View | Details | Raw Unified | Return to bug 23271
Collapse All | Expand All

(-)a/Koha/Objects/Limit/Library.pm (+4 lines)
Lines 17-22 package Koha::Objects::Limit::Library; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use C4::Context;
20
use Koha::Database;
21
use Koha::Database;
21
22
22
=head1 NAME
23
=head1 NAME
Lines 53-58 limits Link Here
53
sub search_with_library_limits {
54
sub search_with_library_limits {
54
    my ( $self, $params, $attributes, $library_id ) = @_;
55
    my ( $self, $params, $attributes, $library_id ) = @_;
55
56
57
    $library_id //= C4::Context->userenv->{branch}
58
        if defined C4::Context->userenv;
59
56
    return $self->search( $params, $attributes ) unless $library_id;
60
    return $self->search( $params, $attributes ) unless $library_id;
57
61
58
    my $library_limits = $self->object_class()->_library_limits;
62
    my $library_limits = $self->object_class()->_library_limits;
(-)a/Koha/Patron/Categories.pm (-5 / +1 lines)
Lines 17-26 package Koha::Patron::Categories; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Carp;
21
22
use C4::Context; # Sigh...
23
24
use Koha::Database;
20
use Koha::Database;
25
21
26
use Koha::Patron::Category;
22
use Koha::Patron::Category;
Lines 33-39 Koha::Patron::Categories - Koha Patron Category Object set class Link Here
33
29
34
=head1 API
30
=head1 API
35
31
36
=head2 Class Methods
32
=head2 Class methods
37
33
38
=cut
34
=cut
39
35
(-)a/t/db_dependent/Koha/Patron/Attribute/Types.t (-27 / +22 lines)
Lines 388-418 subtest 'replace_library_limits() tests' => sub { Link Here
388
388
389
subtest 'search_with_library_limits() tests' => sub {
389
subtest 'search_with_library_limits() tests' => sub {
390
390
391
    plan tests => 4;
391
    plan tests => 5;
392
392
393
    $schema->storage->txn_begin;
393
    $schema->storage->txn_begin;
394
394
395
    # Cleanup before running the tests
395
    # Cleanup before running the tests
396
    Koha::Patron::Attribute::Types->search()->delete();
396
    Koha::Patron::Attribute::Types->search()->delete();
397
397
398
    my $object_code_1
398
    my $object_code_1 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_1' } });
399
        = Koha::Patron::Attribute::Type->new( { code => 'code_1', description => 'a description for code_1' } )
399
    my $object_code_2 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_2' } });
400
        ->store();
400
    my $object_code_3 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_3' } });
401
401
    my $object_code_4 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_4' } });
402
    my $object_code_2
403
        = Koha::Patron::Attribute::Type->new( { code => 'code_2', description => 'a description for code_2' } )
404
        ->store();
405
402
406
    my $object_code_3
403
    is( Koha::Patron::Attribute::Types->search()->count, 4, 'Three objects created' );
407
        = Koha::Patron::Attribute::Type->new( { code => 'code_3', description => 'a description for code_3' } )
408
        ->store();
409
410
    my $object_code_4
411
        = Koha::Patron::Attribute::Type->new( { code => 'code_4', description => 'a description for code_4' } )
412
        ->store();
413
414
    is( Koha::Patron::Attribute::Types->search()->count,
415
        4, 'Three objects created' );
416
404
417
    my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode};
405
    my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode};
418
    my $branch_2 = $builder->build( { source => 'Branch' } )->{branchcode};
406
    my $branch_2 = $builder->build( { source => 'Branch' } )->{branchcode};
Lines 421-435 subtest 'search_with_library_limits() tests' => sub { Link Here
421
    $object_code_2->library_limits( [$branch_2] );
409
    $object_code_2->library_limits( [$branch_2] );
422
    $object_code_3->library_limits( [ $branch_1, $branch_2 ] );
410
    $object_code_3->library_limits( [ $branch_1, $branch_2 ] );
423
411
424
    is( Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $branch_1 )->count,
412
    my $results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, $branch_1 );
425
        3, '3 attribute types are available for the specified branch' );
413
426
    is( Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $branch_2 )->count,
414
    is( $results->count, 3, '3 attribute types are available for the specified branch' );
427
        3, '3 attribute types are available for the specified branch' );
415
428
    is( Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, undef )->count,
416
    $results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, $branch_2 );
429
        4, '4 attribute types are available with no library passed'
417
430
    );
418
    is( $results->count, 3, '3 attribute types are available for the specified branch' );
419
420
    $results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, undef );
421
422
    is( $results->count, 4, 'All attribute types are available with no library pssed' );
423
424
    t::lib::Mocks::mock_userenv({ branchcode => $branch_2 });
425
426
    $results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, undef );
431
427
432
    # TODO test if filter_by_branch_limitations restriced on logged-in-user's branch
428
    is( $results->count, 3, '3 attribute types are available with no library passed' );
433
429
434
    $schema->storage->txn_rollback;
430
    $schema->storage->txn_rollback;
435
};
431
};
436
- 

Return to bug 23271