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

(-)a/t/db_dependent/Koha/Patrons.t (-2 / +74 lines)
Lines 2201-2206 subtest 'extended_attributes' => sub { Link Here
2201
    ## Do we need a filtered?
2201
    ## Do we need a filtered?
2202
    #$limited_value = $patron_1->get_extended_attribute( $attribute_type_limited->code );
2202
    #$limited_value = $patron_1->get_extended_attribute( $attribute_type_limited->code );
2203
    #is( $limited_value, undef, );
2203
    #is( $limited_value, undef, );
2204
};
2204
2205
2205
    $schema->storage->txn_rollback;
2206
subtest 'libraries_where_can_edit_items + can_edit_item' => sub {
2207
    plan tests => 2;
2208
2209
    $schema->storage->txn_begin;
2210
    my $dbh = $schema->storage->dbh;
2211
2212
    $dbh->do("DELETE FROM library_groups");
2213
2214
    # group1
2215
    #   library_1A
2216
    #   library_1B
2217
    # group2
2218
    #   library_2A
2219
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_limit_item_editing => 1 } )->store;
2220
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_limit_item_editing => 1 } )->store;
2221
    my $library_1A = $builder->build( { source => 'Branch' } );
2222
    my $library_1B = $builder->build( { source => 'Branch' } );
2223
    my $library_2A = $builder->build( { source => 'Branch' } );
2224
    $library_1A = Koha::Libraries->find( $library_1A->{branchcode} );
2225
    $library_1B = Koha::Libraries->find( $library_1B->{branchcode} );
2226
    $library_2A = Koha::Libraries->find( $library_2A->{branchcode} );
2227
    Koha::Library::Group->new( { branchcode => $library_1A->branchcode, parent_id => $group_1->id } )->store;
2228
    Koha::Library::Group->new( { branchcode => $library_1B->branchcode, parent_id => $group_1->id } )->store;
2229
    Koha::Library::Group->new( { branchcode => $library_2A->branchcode, parent_id => $group_2->id } )->store;
2230
2231
    my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 9, ?)|); # 9 for editcatalogue
2232
    # 2 patrons from library_1A (group1)
2233
    # patron_1A_1 see patron's infos from outside its group
2234
    # Setting flags => undef to not be considered as superlibrarian
2235
    my $patron_1A_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }});
2236
    $patron_1A_1 = Koha::Patrons->find( $patron_1A_1->{borrowernumber} );
2237
    $sth->execute( $patron_1A_1->borrowernumber, 'edit_items' );
2238
    $sth->execute( $patron_1A_1->borrowernumber, 'edit_any_item' );
2239
    # patron_1A_2 can only see patron's info from its group
2240
    my $patron_1A_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }});
2241
    $patron_1A_2 = Koha::Patrons->find( $patron_1A_2->{borrowernumber} );
2242
    $sth->execute( $patron_1A_2->borrowernumber, 'edit_items' );
2243
    # 1 patron from library_1B (group1)
2244
    my $patron_1B = $builder->build({ source => 'Borrower', value => { branchcode => $library_1B->branchcode, flags => undef, }});
2245
    $patron_1B = Koha::Patrons->find( $patron_1B->{borrowernumber} );
2246
    # 1 patron from library_2A (group2) can only see patron's info from its group
2247
    my $patron_2A = $builder->build({ source => 'Borrower', value => { branchcode => $library_2A->branchcode, flags => undef, }});
2248
    $patron_2A = Koha::Patrons->find( $patron_2A->{borrowernumber} );
2249
    $sth->execute( $patron_2A->borrowernumber, 'edit_items' );
2250
2251
    subtest 'libraries_where_can_edit_items' => sub {
2252
        plan tests => 3;
2253
2254
        my @branchcodes;
2255
2256
        @branchcodes = $patron_1A_1->libraries_where_can_edit_items;
2257
        is_deeply( \@branchcodes, [], "patron_1A_1 has edit_any_item => No restrictions" );
2258
2259
        @branchcodes = $patron_1A_2->libraries_where_can_edit_items;
2260
        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" );
2261
2262
        @branchcodes = $patron_2A->libraries_where_can_edit_items;
2263
        is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" );
2264
    };
2265
2266
    subtest 'can_edit_item' => sub {
2267
        plan tests => 6;
2268
2269
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 });
2270
        is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
2271
        is( $patron_1A_1->can_edit_item( $library_1B->id ),   1, "patron_1A_1 can see patron_1B, from its group" );
2272
        is( $patron_1A_1->can_edit_item( $library_2A->id ),   1, "patron_1A_1 can see patron_1A_2, from another group" );
2273
2274
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 });
2275
        is( $patron_1A_2->can_edit_item( $library_1A->id ),   1, "patron_1A_2 can see patron_1A_1, from its library" );
2276
        is( $patron_1A_2->can_edit_item( $library_1B->id ),   1, "patron_1A_2 can see patron_1B, from its group" );
2277
        is( $patron_1A_2->can_edit_item( $library_2A->id ),   0, "patron_1A_2 can NOT see patron_2A, from another group" );
2278
    };
2206
};
2279
};
2207
- 

Return to bug 20256