Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 9; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
|
24 |
|
25 |
use Koha::Suggestion; |
25 |
use Koha::Suggestion; |
Lines 27-32
use Koha::Suggestions;
Link Here
|
27 |
use Koha::Database; |
27 |
use Koha::Database; |
28 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
28 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
29 |
|
29 |
|
|
|
30 |
use t::lib::Mocks; |
30 |
use t::lib::TestBuilder; |
31 |
use t::lib::TestBuilder; |
31 |
|
32 |
|
32 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
Lines 257-259
subtest 'fund' => sub {
Link Here
|
257 |
|
258 |
|
258 |
$schema->storage->txn_rollback; |
259 |
$schema->storage->txn_rollback; |
259 |
}; |
260 |
}; |
260 |
- |
261 |
|
|
|
262 |
subtest 'search_limited() tests' => sub { |
263 |
|
264 |
plan tests => 4; |
265 |
|
266 |
$schema->storage->txn_begin; |
267 |
|
268 |
# Two libraries |
269 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
270 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
271 |
|
272 |
# A patron from $library_1, that is not superlibrarian at all |
273 |
my $patron = $builder->build_object( |
274 |
{ |
275 |
class => 'Koha::Patrons', |
276 |
value => { branchcode => $library_1->id, flags => 0 } |
277 |
} |
278 |
); |
279 |
|
280 |
# Add 3 suggestions, to be sorted by author |
281 |
my $suggestion_1 = $builder->build_object( |
282 |
{ |
283 |
class => 'Koha::Suggestions', |
284 |
value => { branchcode => $library_1->id, author => 'A' } |
285 |
} |
286 |
); |
287 |
my $suggestion_2 = $builder->build_object( |
288 |
{ |
289 |
class => 'Koha::Suggestions', |
290 |
value => { branchcode => $library_2->id, author => 'B' } |
291 |
} |
292 |
); |
293 |
my $suggestion_3 = $builder->build_object( |
294 |
{ |
295 |
class => 'Koha::Suggestions', |
296 |
value => { branchcode => $library_2->id, author => 'C' } |
297 |
} |
298 |
); |
299 |
|
300 |
my $resultset = Koha::Suggestions->search( |
301 |
{ branchcode => [ $library_1->id, $library_2->id ] }, |
302 |
{ order_by => { -desc => ['author'] } } ); |
303 |
|
304 |
is( $resultset->count, 3, 'Only this three suggestions are returned' ); |
305 |
|
306 |
# Now the tests |
307 |
t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library_1->id }); |
308 |
|
309 |
# Disable IndependentBranches |
310 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); |
311 |
|
312 |
my $filtered_rs = $resultset->search_limited; |
313 |
is( $filtered_rs->count, 3, 'No IndependentBranches, all suggestions returned' ); |
314 |
|
315 |
# Enable IndependentBranches |
316 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); |
317 |
|
318 |
$filtered_rs = $resultset->search_limited; |
319 |
|
320 |
is( $filtered_rs->count, 1, 'IndependentBranches, only suggestions from own branch returned' ); |
321 |
|
322 |
# Make the patron superlibrarian to override IndependentBranches |
323 |
$patron->flags(1)->store; |
324 |
# So it reloads C4::Context->userenv->{flags} |
325 |
t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library_1->id }); |
326 |
|
327 |
$filtered_rs = $resultset->search_limited; |
328 |
is( $filtered_rs->count, 3, 'IndependentBranches but patron is superlibrarian, all suggestions returned' ); |
329 |
|
330 |
$schema->storage->txn_rollback; |
331 |
}; |