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