Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 6; |
4 |
use Test::More tests => 7; |
5 |
use DateTime::Duration; |
5 |
use DateTime::Duration; |
6 |
|
6 |
|
7 |
use C4::Context; |
7 |
use C4::Context; |
Lines 591-596
subtest 'Get shelves containing biblios' => sub {
Link Here
|
591 |
teardown(); |
591 |
teardown(); |
592 |
}; |
592 |
}; |
593 |
|
593 |
|
|
|
594 |
subtest 'cannot_be_transferred' => sub { |
595 |
plan tests => 12; |
596 |
|
597 |
# Three patrons and a deleted one |
598 |
my $staff = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); |
599 |
my $listowner = $builder->build_object({ class => 'Koha::Patrons' }); |
600 |
my $receiver = $builder->build_object({ class => 'Koha::Patrons' }); |
601 |
my $removed_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
602 |
$removed_patron->delete; |
603 |
|
604 |
# Create three lists |
605 |
my $private_list = Koha::Virtualshelf->new({ shelfname => "A", owner => $listowner->id })->store; |
606 |
my $public_list = Koha::Virtualshelf->new({ shelfname => "B", public => 1, owner => $listowner->id })->store; |
607 |
my $shared_list = Koha::Virtualshelf->new({ shelfname => "C", owner => $listowner->id })->store; |
608 |
$shared_list->share("key")->accept( "key", $receiver->id ); |
609 |
|
610 |
# Test on private list |
611 |
is( $private_list->cannot_be_transferred, 'unauthorized_transfer', 'Private list can never be transferred' ); |
612 |
|
613 |
# Test on public list |
614 |
is( $public_list->cannot_be_transferred, 'missing_by_parameter', 'Public list, no parameters' ); |
615 |
is( $public_list->cannot_be_transferred({ by => $staff->id, to => $receiver->id }), 'unauthorized_transfer', 'Lacks permission' ); |
616 |
my $perms = $builder->build({ source => 'UserPermission', value => { |
617 |
borrowernumber => $staff->id, module_bit => 20, code => 'edit_public_lists', |
618 |
}}); |
619 |
is( $public_list->cannot_be_transferred({ by => $staff->id, to => $receiver->id }), 0, 'Minimum permission passes' ); |
620 |
$staff->flags(1)->store; |
621 |
is( $public_list->cannot_be_transferred({ by => $staff->id, to => $receiver->id }), 0, 'Superlibrarian permission passes' ); |
622 |
is( $public_list->cannot_be_transferred({ by => $staff->id, to => $receiver->id, interface => 'opac' }), 'unauthorized_transfer', |
623 |
'Not supported on OPAC' ); |
624 |
is( $public_list->cannot_be_transferred({ by => $staff->id, to => $removed_patron->id }), 'new_owner_not_found', 'Removed patron cannot own' ); |
625 |
|
626 |
# Test on shared list |
627 |
is( $shared_list->cannot_be_transferred({ by => $staff->id }), 'unauthorized_transfer', 'Shared list, transfer limited to owner' ); |
628 |
is( $shared_list->cannot_be_transferred({ by => $receiver->id }), 'unauthorized_transfer', 'Shared list, transfer still limited to owner' ); |
629 |
is( $shared_list->cannot_be_transferred({ by => $listowner->id, to => $receiver->id }), 0, 'sharee could become owner' ); |
630 |
is( $shared_list->cannot_be_transferred({ by => $listowner->id, to => $receiver->id, interface => 'intranet' }), 'unauthorized_transfer', |
631 |
'Intranet not supported' ); |
632 |
is( $shared_list->cannot_be_transferred({ by => $listowner->id, to => $staff->id }), 'new_owner_has_no_share', 'staff has no share' ); |
633 |
}; |
634 |
|
635 |
$schema->storage->txn_rollback; |
636 |
|
594 |
sub teardown { |
637 |
sub teardown { |
595 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
638 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
596 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
639 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
597 |
- |
|
|