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

(-)a/t/db_dependent/Koha/Patrons.t (-2 / +74 lines)
Lines 2138-2143 subtest 'extended_attributes' => sub { Link Here
2138
    ## Do we need a filtered?
2138
    ## Do we need a filtered?
2139
    #$limited_value = $patron_1->get_extended_attribute( $attribute_type_limited->code );
2139
    #$limited_value = $patron_1->get_extended_attribute( $attribute_type_limited->code );
2140
    #is( $limited_value, undef, );
2140
    #is( $limited_value, undef, );
2141
};
2141
2142
2142
    $schema->storage->txn_rollback;
2143
subtest 'libraries_where_can_edit_items + can_edit_item' => sub {
2144
    plan tests => 2;
2145
2146
    $schema->storage->txn_begin;
2147
    my $dbh = $schema->storage->dbh;
2148
2149
    $dbh->do("DELETE FROM library_groups");
2150
2151
    # group1
2152
    #   library_1A
2153
    #   library_1B
2154
    # group2
2155
    #   library_2A
2156
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_limit_item_editing => 1 } )->store;
2157
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_limit_item_editing => 1 } )->store;
2158
    my $library_1A = $builder->build( { source => 'Branch' } );
2159
    my $library_1B = $builder->build( { source => 'Branch' } );
2160
    my $library_2A = $builder->build( { source => 'Branch' } );
2161
    $library_1A = Koha::Libraries->find( $library_1A->{branchcode} );
2162
    $library_1B = Koha::Libraries->find( $library_1B->{branchcode} );
2163
    $library_2A = Koha::Libraries->find( $library_2A->{branchcode} );
2164
    Koha::Library::Group->new( { branchcode => $library_1A->branchcode, parent_id => $group_1->id } )->store;
2165
    Koha::Library::Group->new( { branchcode => $library_1B->branchcode, parent_id => $group_1->id } )->store;
2166
    Koha::Library::Group->new( { branchcode => $library_2A->branchcode, parent_id => $group_2->id } )->store;
2167
2168
    my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 9, ?)|); # 9 for editcatalogue
2169
    # 2 patrons from library_1A (group1)
2170
    # patron_1A_1 see patron's infos from outside its group
2171
    # Setting flags => undef to not be considered as superlibrarian
2172
    my $patron_1A_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }});
2173
    $patron_1A_1 = Koha::Patrons->find( $patron_1A_1->{borrowernumber} );
2174
    $sth->execute( $patron_1A_1->borrowernumber, 'edit_items' );
2175
    $sth->execute( $patron_1A_1->borrowernumber, 'edit_any_item' );
2176
    # patron_1A_2 can only see patron's info from its group
2177
    my $patron_1A_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }});
2178
    $patron_1A_2 = Koha::Patrons->find( $patron_1A_2->{borrowernumber} );
2179
    $sth->execute( $patron_1A_2->borrowernumber, 'edit_items' );
2180
    # 1 patron from library_1B (group1)
2181
    my $patron_1B = $builder->build({ source => 'Borrower', value => { branchcode => $library_1B->branchcode, flags => undef, }});
2182
    $patron_1B = Koha::Patrons->find( $patron_1B->{borrowernumber} );
2183
    # 1 patron from library_2A (group2) can only see patron's info from its group
2184
    my $patron_2A = $builder->build({ source => 'Borrower', value => { branchcode => $library_2A->branchcode, flags => undef, }});
2185
    $patron_2A = Koha::Patrons->find( $patron_2A->{borrowernumber} );
2186
    $sth->execute( $patron_2A->borrowernumber, 'edit_items' );
2187
2188
    subtest 'libraries_where_can_edit_items' => sub {
2189
        plan tests => 3;
2190
2191
        my @branchcodes;
2192
2193
        @branchcodes = $patron_1A_1->libraries_where_can_edit_items;
2194
        is_deeply( \@branchcodes, [], "patron_1A_1 has edit_any_item => No restrictions" );
2195
2196
        @branchcodes = $patron_1A_2->libraries_where_can_edit_items;
2197
        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" );
2198
2199
        @branchcodes = $patron_2A->libraries_where_can_edit_items;
2200
        is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" );
2201
    };
2202
2203
    subtest 'can_edit_item' => sub {
2204
        plan tests => 6;
2205
2206
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 });
2207
        is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
2208
        is( $patron_1A_1->can_edit_item( $library_1B->id ),   1, "patron_1A_1 can see patron_1B, from its group" );
2209
        is( $patron_1A_1->can_edit_item( $library_2A->id ),   1, "patron_1A_1 can see patron_1A_2, from another group" );
2210
2211
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 });
2212
        is( $patron_1A_2->can_edit_item( $library_1A->id ),   1, "patron_1A_2 can see patron_1A_1, from its library" );
2213
        is( $patron_1A_2->can_edit_item( $library_1B->id ),   1, "patron_1A_2 can see patron_1B, from its group" );
2214
        is( $patron_1A_2->can_edit_item( $library_2A->id ),   0, "patron_1A_2 can NOT see patron_2A, from another group" );
2215
    };
2143
};
2216
};
2144
- 

Return to bug 20256