From 2ea901c6411063f9b3d245674241c7f012d709cb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 10 Feb 2016 10:32:52 +0000 Subject: [PATCH] Bug 15783: AddAuthorisedValue - Remove the subroutine MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test plan: prove t/db_dependent/Koha.t should return green git grep AddAuthorisedValue should not return any results Signed-off-by: Marc Véron Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/Koha.pm | 21 ---------------- t/db_dependent/Koha.t | 58 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index d5d1501bf5..dce3c63a6f 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -65,7 +65,6 @@ BEGIN { &GetKohaAuthorisedValueLib &GetAuthorisedValueByCode &GetAuthValCode - &AddAuthorisedValue &GetNormalizedUPC &GetNormalizedISBN &GetNormalizedEAN @@ -1395,26 +1394,6 @@ sub GetKohaAuthorisedValueLib { return $value; } -=head2 AddAuthorisedValue - - AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac, $imageurl); - -Create a new authorised value. - -=cut - -sub AddAuthorisedValue { - my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_; - - my $dbh = C4::Context->dbh; - my $query = qq{ - INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) - VALUES (?,?,?,?,?) - }; - my $sth = $dbh->prepare($query); - $sth->execute($category, $authorised_value, $lib, $lib_opac, $imageurl); -} - =head2 display_marc_indicators my $display_form = C4::Koha::display_marc_indicators($field); diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t index 048185a4d0..fe6d642cbd 100644 --- a/t/db_dependent/Koha.t +++ b/t/db_dependent/Koha.t @@ -3,10 +3,10 @@ # This is to test C4/Koha # It requires a working Koha database with the sample data -use strict; -use warnings; +use Modern::Perl; use C4::Context; use Koha::DateUtils qw(dt_from_string); +use Koha::AuthorisedValue; use Test::More tests => 10; use DateTime::Format::MySQL; @@ -33,8 +33,15 @@ subtest 'Authorized Values Tests' => sub { # Insert an entry into authorised_value table - my $insert_success = AddAuthorisedValue($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); - ok($insert_success, "Insert data in database"); + my $insert_success = Koha::AuthorisedValue->new( + { category => $data->{category}, + authorised_value => $data->{authorised_value}, + lib => $data->{lib}, + lib_opac => $data->{lib_opac}, + imageurl => $data->{imageurl} + } + )->store; + ok( $insert_success, "Insert data in database" ); # Tests @@ -63,11 +70,34 @@ subtest 'Authorized Values Tests' => sub { SKIP: { eval { require Test::Deep; import Test::Deep; }; skip "Test::Deep required to run the GetAuthorisedValues() tests.", 2 if $@; - AddAuthorisedValue('BUG10656', 'ZZZ', 'Z_STAFF', 'A_PUBLIC', ''); - AddAuthorisedValue('BUG10656', 'AAA', 'A_STAFF', 'Z_PUBLIC', ''); + Koha::AuthorisedValue->new( + { category => 'BUG10656', + authorised_value => 'ZZZ', + lib => 'Z_STAFF', + lib_opac => 'A_PUBLIC', + imageurl => '' + } + )->store; + Koha::AuthorisedValue->new( + { category => 'BUG10656', + authorised_value => 'AAA', + lib => 'A_STAFF', + lib_opac => 'Z_PUBLIC', + imageurl => '' + } + )->store; + # the next one sets lib_opac to NULL; in that case, the staff # display value is meant to be used. - AddAuthorisedValue('BUG10656', 'DDD', 'D_STAFF', undef, ''); + Koha::AuthorisedValue->new( + { category => 'BUG10656', + authorised_value => 'DDD', + lib => 'D_STAFF', + lib_opac => undef, + imageurl => '' + } + )->store; + my $authvals = GetAuthorisedValues('BUG10656'); cmp_deeply( $authvals, @@ -300,7 +330,12 @@ subtest 'GetFrameworksLoop() tests' => sub { subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ plan tests => 7; - my $insertGroup = AddAuthorisedValue('ITEMTYPECAT', 'Qwertyware'); + my $insertGroup = Koha::AuthorisedValue->new( + { category => 'ITEMTYPECAT', + authorised_value => 'Quertyware', + } + )->store; + ok($insertGroup, "Create group Qwertyware"); my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)"; @@ -318,7 +353,12 @@ subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes'); # add more data since GetItemTypesCategorized's search is more subtle - $insertGroup = AddAuthorisedValue('ITEMTYPECAT', 'Veryheavybook'); + $insertGroup = Koha::AuthorisedValue->new( + { category => 'ITEMTYPECAT', + authorised_value => 'Varyheavybook', + } + )->store; + $insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryheavybook', 1); my $hrCat = GetItemTypesCategorized(); -- 2.39.5