@@ -, +, @@ Koha::Objects::Limit::Library $ kshell k$ prove t/db_dependent/AuthorisedValues.t --- Koha/AuthorisedValues.pm | 29 +---------------------------- t/db_dependent/AuthorisedValues.t | 6 +++--- 2 files changed, 4 insertions(+), 31 deletions(-) --- a/Koha/AuthorisedValues.pm +++ a/Koha/AuthorisedValues.pm @@ -27,7 +27,7 @@ use Koha::AuthorisedValue; use Koha::MarcSubfieldStructures; use Koha::Cache::Memory::Lite; -use base qw(Koha::Objects); +use base qw(Koha::Objects Koha::Objects::Limit::Library); =head1 NAME @@ -39,33 +39,6 @@ Koha::AuthorisedValues - Koha Authorised value Object set class =cut -=head3 Koha::AuthorisedValues->search(); - -my @objects = Koha::AuthorisedValues->search($params); - -=cut - -sub search { - my ( $self, $params, $attributes ) = @_; - - my $branchcode = $params->{branchcode}; - delete( $params->{branchcode} ); - - my $or = - $branchcode - ? { - '-or' => [ - 'authorised_values_branches.branchcode' => undef, - 'authorised_values_branches.branchcode' => $branchcode, - ] - } - : {}; - my $join = $branchcode ? { join => 'authorised_values_branches' } : {}; - $attributes //= {}; - $attributes = { %$attributes, %$join }; - return $self->SUPER::search( { %$params, %$or, }, $attributes ); -} - sub search_by_marc_field { my ( $self, $params ) = @_; my $frameworkcode = $params->{frameworkcode} || ''; --- a/t/db_dependent/AuthorisedValues.t +++ a/t/db_dependent/AuthorisedValues.t @@ -119,14 +119,14 @@ my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; $av1->add_library_limit( $branchcode1 ); -@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } ); +@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode1 ); is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" ); -@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } ); +@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $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_library_limit( $branchcode1 ); -@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } ); +@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode2 ); is( @authorised_values, 3, "Branch limitation deleted successfully" ); $av1->add_library_limit( $branchcode1 ); --