|
Lines 388-418
subtest 'replace_library_limits() tests' => sub {
Link Here
|
| 388 |
|
388 |
|
| 389 |
subtest 'search_with_library_limits() tests' => sub { |
389 |
subtest 'search_with_library_limits() tests' => sub { |
| 390 |
|
390 |
|
| 391 |
plan tests => 4; |
391 |
plan tests => 5; |
| 392 |
|
392 |
|
| 393 |
$schema->storage->txn_begin; |
393 |
$schema->storage->txn_begin; |
| 394 |
|
394 |
|
| 395 |
# Cleanup before running the tests |
395 |
# Cleanup before running the tests |
| 396 |
Koha::Patron::Attribute::Types->search()->delete(); |
396 |
Koha::Patron::Attribute::Types->search()->delete(); |
| 397 |
|
397 |
|
| 398 |
my $object_code_1 |
398 |
my $object_code_1 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_1' } }); |
| 399 |
= Koha::Patron::Attribute::Type->new( { code => 'code_1', description => 'a description for code_1' } ) |
399 |
my $object_code_2 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_2' } }); |
| 400 |
->store(); |
400 |
my $object_code_3 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_3' } }); |
| 401 |
|
401 |
my $object_code_4 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types', value => { code => 'code_4' } }); |
| 402 |
my $object_code_2 |
|
|
| 403 |
= Koha::Patron::Attribute::Type->new( { code => 'code_2', description => 'a description for code_2' } ) |
| 404 |
->store(); |
| 405 |
|
402 |
|
| 406 |
my $object_code_3 |
403 |
is( Koha::Patron::Attribute::Types->search()->count, 4, 'Three objects created' ); |
| 407 |
= Koha::Patron::Attribute::Type->new( { code => 'code_3', description => 'a description for code_3' } ) |
|
|
| 408 |
->store(); |
| 409 |
|
| 410 |
my $object_code_4 |
| 411 |
= Koha::Patron::Attribute::Type->new( { code => 'code_4', description => 'a description for code_4' } ) |
| 412 |
->store(); |
| 413 |
|
| 414 |
is( Koha::Patron::Attribute::Types->search()->count, |
| 415 |
4, 'Three objects created' ); |
| 416 |
|
404 |
|
| 417 |
my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
405 |
my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 418 |
my $branch_2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
406 |
my $branch_2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
|
Lines 421-435
subtest 'search_with_library_limits() tests' => sub {
Link Here
|
| 421 |
$object_code_2->library_limits( [$branch_2] ); |
409 |
$object_code_2->library_limits( [$branch_2] ); |
| 422 |
$object_code_3->library_limits( [ $branch_1, $branch_2 ] ); |
410 |
$object_code_3->library_limits( [ $branch_1, $branch_2 ] ); |
| 423 |
|
411 |
|
| 424 |
is( Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $branch_1 )->count, |
412 |
my $results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, $branch_1 ); |
| 425 |
3, '3 attribute types are available for the specified branch' ); |
413 |
|
| 426 |
is( Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $branch_2 )->count, |
414 |
is( $results->count, 3, '3 attribute types are available for the specified branch' ); |
| 427 |
3, '3 attribute types are available for the specified branch' ); |
415 |
|
| 428 |
is( Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, undef )->count, |
416 |
$results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, $branch_2 ); |
| 429 |
4, '4 attribute types are available with no library passed' |
417 |
|
| 430 |
); |
418 |
is( $results->count, 3, '3 attribute types are available for the specified branch' ); |
|
|
419 |
|
| 420 |
$results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, undef ); |
| 421 |
|
| 422 |
is( $results->count, 4, 'All attribute types are available with no library pssed' ); |
| 423 |
|
| 424 |
t::lib::Mocks::mock_userenv({ branchcode => $branch_2 }); |
| 425 |
|
| 426 |
$results = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => 'code' }, undef ); |
| 431 |
|
427 |
|
| 432 |
# TODO test if filter_by_branch_limitations restriced on logged-in-user's branch |
428 |
is( $results->count, 3, '3 attribute types are available with no library passed' ); |
| 433 |
|
429 |
|
| 434 |
$schema->storage->txn_rollback; |
430 |
$schema->storage->txn_rollback; |
| 435 |
}; |
431 |
}; |
| 436 |
- |
|
|