|
Lines 1-7
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 4 |
use Test::More tests => 6; |
19 |
|
|
|
20 |
use Test::More tests => 8; |
| 21 |
use Test::Exception; |
| 22 |
|
| 5 |
use DateTime::Duration; |
23 |
use DateTime::Duration; |
| 6 |
|
24 |
|
| 7 |
use C4::Context; |
25 |
use C4::Context; |
|
Lines 494-499
subtest 'Get shelves containing biblios' => sub {
Link Here
|
| 494 |
teardown(); |
512 |
teardown(); |
| 495 |
}; |
513 |
}; |
| 496 |
|
514 |
|
|
|
515 |
$schema->storage->txn_rollback; |
| 516 |
|
| 517 |
subtest 'filter_by_public() tests' => sub { |
| 518 |
|
| 519 |
plan tests => 4; |
| 520 |
|
| 521 |
$schema->storage->txn_begin; |
| 522 |
|
| 523 |
my $list_1 = $builder->build_object( |
| 524 |
{ |
| 525 |
class => 'Koha::Virtualshelves', |
| 526 |
value => { |
| 527 |
public => 0 |
| 528 |
} |
| 529 |
} |
| 530 |
); |
| 531 |
my $list_2 = $builder->build_object( |
| 532 |
{ |
| 533 |
class => 'Koha::Virtualshelves', |
| 534 |
value => { |
| 535 |
public => 1 |
| 536 |
} |
| 537 |
} |
| 538 |
); |
| 539 |
my $list_3 = $builder->build_object( |
| 540 |
{ |
| 541 |
class => 'Koha::Virtualshelves', |
| 542 |
value => { |
| 543 |
public => 1 |
| 544 |
} |
| 545 |
} |
| 546 |
); |
| 547 |
|
| 548 |
my $lists = Koha::Virtualshelves->search( |
| 549 |
{ |
| 550 |
shelfnumber => [ $list_1->id, $list_2->id, $list_3->id ] |
| 551 |
} |
| 552 |
); |
| 553 |
|
| 554 |
is( $lists->count, 3, 'Our three lists are returned' ); |
| 555 |
$lists = $lists->filter_by_public; |
| 556 |
|
| 557 |
is( $lists->count, 2, 'Our two public lists are returned' ); |
| 558 |
|
| 559 |
while ( my $list = $lists->next ) { |
| 560 |
ok( $list->public, 'Only public lists in the resultset' ); |
| 561 |
} |
| 562 |
|
| 563 |
$schema->storage->txn_rollback; |
| 564 |
}; |
| 565 |
|
| 566 |
subtest 'filter_by_readable() tests' => sub { |
| 567 |
|
| 568 |
plan tests => 7; |
| 569 |
|
| 570 |
$schema->storage->txn_begin; |
| 571 |
|
| 572 |
my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 573 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 574 |
|
| 575 |
my $list_1 = $builder->build_object( |
| 576 |
{ |
| 577 |
class => 'Koha::Virtualshelves', |
| 578 |
value => { |
| 579 |
public => 0, |
| 580 |
owner => $patron_1->id, |
| 581 |
} |
| 582 |
} |
| 583 |
); |
| 584 |
my $list_2 = $builder->build_object( |
| 585 |
{ |
| 586 |
class => 'Koha::Virtualshelves', |
| 587 |
value => { |
| 588 |
public => 1, |
| 589 |
owner => $patron_1->id, |
| 590 |
} |
| 591 |
} |
| 592 |
); |
| 593 |
my $list_3 = $builder->build_object( |
| 594 |
{ |
| 595 |
class => 'Koha::Virtualshelves', |
| 596 |
value => { |
| 597 |
public => 0, |
| 598 |
owner => $patron_2->id, |
| 599 |
} |
| 600 |
} |
| 601 |
); |
| 602 |
my $list_4 = $builder->build_object( |
| 603 |
{ |
| 604 |
class => 'Koha::Virtualshelves', |
| 605 |
value => { |
| 606 |
public => 1, |
| 607 |
owner => $patron_2->id, |
| 608 |
} |
| 609 |
} |
| 610 |
); |
| 611 |
|
| 612 |
my $lists = Koha::Virtualshelves->search( |
| 613 |
{ |
| 614 |
shelfnumber => [ $list_1->id, $list_2->id, $list_3->id, $list_4->id ] |
| 615 |
} |
| 616 |
); |
| 617 |
|
| 618 |
is( $lists->count, 4, 'Our four lists are returned' ); |
| 619 |
|
| 620 |
throws_ok |
| 621 |
{ $lists->filter_by_readable; } |
| 622 |
'Koha::Exceptions::MissingParameter', |
| 623 |
'Exception thrown on missing'; |
| 624 |
|
| 625 |
is( "$@", 'Mandatory patron_id parameter missing', 'Expected message in exception' ); |
| 626 |
|
| 627 |
$lists = $lists->filter_by_readable({ patron_id => $patron_1->id }); |
| 628 |
|
| 629 |
is( $lists->count, 3, 'Three lists are returned' ); |
| 630 |
|
| 631 |
while ( my $list = $lists->next ) { |
| 632 |
ok( $list->owner == $patron_1->id || $list->public, 'Only public or self lists in the resultset' ); |
| 633 |
} |
| 634 |
|
| 635 |
$schema->storage->txn_rollback; |
| 636 |
}; |
| 637 |
|
| 497 |
sub teardown { |
638 |
sub teardown { |
| 498 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
639 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
| 499 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
640 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
| 500 |
- |
|
|