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 <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2019-07-05 16:24:17 -03:00 committed by Martin Renvoize
parent 95ab03b73a
commit 9a8bc7fcc5
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 18 additions and 17 deletions

View File

@ -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);
}

View File

@ -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' );