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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +74 lines)
Lines 2460-2466 subtest 'filter_by_amount_owed' => sub { Link Here
2460
    is( $filtered->_resultset->as_subselect_rs->count, 1,
2460
    is( $filtered->_resultset->as_subselect_rs->count, 1,
2461
"filter_by_amount_owed({ more_than => 6.00, library => $library2->{branchcode} }) found one patron"
2461
"filter_by_amount_owed({ more_than => 6.00, library => $library2->{branchcode} }) found one patron"
2462
    );
2462
    );
2463
};
2464
2465
subtest 'libraries_where_can_edit_items + can_edit_item' => sub {
2466
    plan tests => 2;
2467
2468
    $schema->storage->txn_begin;
2469
    my $dbh = $schema->storage->dbh;
2470
2471
    $dbh->do("DELETE FROM library_groups");
2472
2473
    # group1
2474
    #   library_1A
2475
    #   library_1B
2476
    # group2
2477
    #   library_2A
2478
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_limit_item_editing => 1 } )->store;
2479
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_limit_item_editing => 1 } )->store;
2480
    my $library_1A = $builder->build( { source => 'Branch' } );
2481
    my $library_1B = $builder->build( { source => 'Branch' } );
2482
    my $library_2A = $builder->build( { source => 'Branch' } );
2483
    $library_1A = Koha::Libraries->find( $library_1A->{branchcode} );
2484
    $library_1B = Koha::Libraries->find( $library_1B->{branchcode} );
2485
    $library_2A = Koha::Libraries->find( $library_2A->{branchcode} );
2486
    Koha::Library::Group->new( { branchcode => $library_1A->branchcode, parent_id => $group_1->id } )->store;
2487
    Koha::Library::Group->new( { branchcode => $library_1B->branchcode, parent_id => $group_1->id } )->store;
2488
    Koha::Library::Group->new( { branchcode => $library_2A->branchcode, parent_id => $group_2->id } )->store;
2489
2490
    my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 9, ?)|); # 9 for editcatalogue
2491
    # 2 patrons from library_1A (group1)
2492
    # patron_1A_1 see patron's infos from outside its group
2493
    # Setting flags => undef to not be considered as superlibrarian
2494
    my $patron_1A_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }});
2495
    $patron_1A_1 = Koha::Patrons->find( $patron_1A_1->{borrowernumber} );
2496
    $sth->execute( $patron_1A_1->borrowernumber, 'edit_items' );
2497
    $sth->execute( $patron_1A_1->borrowernumber, 'edit_any_item' );
2498
    # patron_1A_2 can only see patron's info from its group
2499
    my $patron_1A_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }});
2500
    $patron_1A_2 = Koha::Patrons->find( $patron_1A_2->{borrowernumber} );
2501
    $sth->execute( $patron_1A_2->borrowernumber, 'edit_items' );
2502
    # 1 patron from library_1B (group1)
2503
    my $patron_1B = $builder->build({ source => 'Borrower', value => { branchcode => $library_1B->branchcode, flags => undef, }});
2504
    $patron_1B = Koha::Patrons->find( $patron_1B->{borrowernumber} );
2505
    # 1 patron from library_2A (group2) can only see patron's info from its group
2506
    my $patron_2A = $builder->build({ source => 'Borrower', value => { branchcode => $library_2A->branchcode, flags => undef, }});
2507
    $patron_2A = Koha::Patrons->find( $patron_2A->{borrowernumber} );
2508
    $sth->execute( $patron_2A->borrowernumber, 'edit_items' );
2509
2510
    subtest 'libraries_where_can_edit_items' => sub {
2511
        plan tests => 3;
2463
2512
2513
        my @branchcodes;
2514
2515
        @branchcodes = $patron_1A_1->libraries_where_can_edit_items;
2516
        is_deeply( \@branchcodes, [], "patron_1A_1 has edit_any_item => No restrictions" );
2517
2518
        @branchcodes = $patron_1A_2->libraries_where_can_edit_items;
2519
        is_deeply( \@branchcodes, [ sort ( $library_1A->branchcode, $library_1B->branchcode ) ], "patron_1A_2 doesn't have edit_any_item => Can only edit items from its group" );
2520
2521
        @branchcodes = $patron_2A->libraries_where_can_edit_items;
2522
        is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" );
2523
    };
2524
2525
    subtest 'can_edit_item' => sub {
2526
        plan tests => 6;
2527
2528
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 });
2529
        is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
2530
        is( $patron_1A_1->can_edit_item( $library_1B->id ),   1, "patron_1A_1 can see patron_1B, from its group" );
2531
        is( $patron_1A_1->can_edit_item( $library_2A->id ),   1, "patron_1A_1 can see patron_1A_2, from another group" );
2532
2533
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 });
2534
        is( $patron_1A_2->can_edit_item( $library_1A->id ),   1, "patron_1A_2 can see patron_1A_1, from its library" );
2535
        is( $patron_1A_2->can_edit_item( $library_1B->id ),   1, "patron_1A_2 can see patron_1B, from its group" );
2536
        is( $patron_1A_2->can_edit_item( $library_2A->id ),   0, "patron_1A_2 can NOT see patron_2A, from another group" );
2537
    };
2464
};
2538
};
2465
2539
2466
subtest 'filter_by_have_permission' => sub {
2540
subtest 'filter_by_have_permission' => sub {
2467
- 

Return to bug 20256