From 9a8bc7fcc5d88dc5ed5d279fae3029c4a9ecbca5 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 5 Jul 2019 16:24:17 -0300 Subject: [PATCH] Bug 23272: Adapt controller and tests This patch adapts the controller script for handling authorised values, and the tests to reflect the method names changes. To test: - Verify you can add/delete/edit authorised values with/without branch limitations, as usual => SUCCESS: All works as usual! - Run: $ kshell k$ prove t/db_dependent/AuthorisedValues.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- admin/authorised_values.pl | 23 ++++++++++++----------- t/db_dependent/AuthorisedValues.t | 12 ++++++------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 4f951291e4..6080dbb640 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -20,6 +20,8 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use List::MoreUtils qw(any); + use C4::Auth; use C4::Context; use C4::Koha; @@ -49,22 +51,21 @@ our ($template, $borrowernumber, $cookie)= get_template_and_user({ ################## ADD_FORM ################################## # called by default. Used to create form to add or modify a record if ($op eq 'add_form') { - my ( $selected_branches, $category, $av ); + my ( @selected_branches, $category, $av ); if ($id) { $av = Koha::AuthorisedValues->new->find( $id ); - $selected_branches = $av->branch_limitations; + @selected_branches = $av->library_limits->as_list; } else { $category = $input->param('category'); } - my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; + my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } ); my @branches_loop; - foreach my $branch ( @$branches ) { - my $selected = ( grep {$_ eq $branch->{branchcode}} @$selected_branches ) ? 1 : 0; + while ( my $branch = $branches->next ) { push @branches_loop, { - branchcode => $branch->{branchcode}, - branchname => $branch->{branchname}, - selected => $selected, + branchcode => $branch->branchcode, + branchname => $branch->branchname, + selected => any {$_->branchcode eq $branch->branchcode} @selected_branches, }; } @@ -126,7 +127,7 @@ if ($op eq 'add_form') { $av->imageurl( $imageurl ); eval{ $av->store; - $av->replace_branch_limitations( \@branches ); + $av->replace_library_limits( \@branches ); }; if ( $@ ) { push @messages, {type => 'error', code => 'error_on_update' }; @@ -145,7 +146,7 @@ if ($op eq 'add_form') { eval { $av->store; - $av->replace_branch_limitations( \@branches ); + $av->replace_library_limits( \@branches ); }; if ( $@ ) { @@ -230,7 +231,7 @@ if ( $op eq 'list' ) { $row_data{lib} = $av->lib; $row_data{lib_opac} = $av->lib_opac; $row_data{imageurl} = getitemtypeimagelocation( 'intranet', $av->imageurl ); - $row_data{branches} = $av->branch_limitations; + $row_data{branches} = $av->library_limits->as_list; $row_data{id} = $av->id; push(@loop_data, \%row_data); } diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t index f7da7a5f77..d16d282731 100644 --- a/t/db_dependent/AuthorisedValues.t +++ b/t/db_dependent/AuthorisedValues.t @@ -95,7 +95,7 @@ is( @authorised_values, 3, "Get correct number of values" ); my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode}; my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; -$av1->add_branch_limitation( $branchcode1 ); +$av1->add_library_limit( $branchcode1 ); @authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } ); is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" ); @@ -103,15 +103,15 @@ is( @authorised_values, 3, "Search including value with a branch limit ( branch @authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } ); is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" ); -$av1->del_branch_limitation( $branchcode1 ); +$av1->del_library_limit( $branchcode1 ); @authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } ); is( @authorised_values, 3, "Branch limitation deleted successfully" ); -$av1->add_branch_limitation( $branchcode1 ); -$av1->branch_limitations( [ $branchcode1, $branchcode2 ] ); +$av1->add_library_limit( $branchcode1 ); +$av1->library_limits( [ $branchcode1, $branchcode2 ] ); -my $limits = $av1->branch_limitations; -is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' ); +my $limits = $av1->library_limits->as_list; +is( @$limits, 2, 'library_limits functions correctly both as setter and getter' ); my @categories = Koha::AuthorisedValues->new->categories; is( @categories, 3, 'There should have 2 categories inserted' ); -- 2.39.5