Bug 18228: Adjust Virtualshelves.t

Test plan:
Run t/db_dependent/Virtualshelves.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Eric Gosselin <eric.gosselin@inlibro.com>

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Marcel de Rooy 2017-03-08 16:28:59 +01:00 committed by Jonathan Druart
parent a58aca056b
commit ad2528a102
1 changed files with 48 additions and 62 deletions

View File

@ -19,7 +19,7 @@ $dbh->{AutoCommit} = 0;
teardown();
subtest 'CRUD' => sub {
plan tests => 13;
plan tests => 12;
my $patron = $builder->build({
source => 'Borrower',
});
@ -39,9 +39,8 @@ subtest 'CRUD' => sub {
$number_of_shelves = Koha::Virtualshelves->search->count;
is( $number_of_shelves, 1, '1 shelf should have been inserted' );
is( $shelf->allow_add, 0, 'The default value for allow_add should be 1' );
is( $shelf->allow_delete_own, 1, 'The default value for allow_delete_own should be 0' );
is( $shelf->allow_delete_other, 0, 'The default value for allow_delete_other should be 0' );
is( $shelf->allow_change_from_owner, 1, 'The default value for allow_change_from_owner should be 1' );
is( $shelf->allow_change_from_others, 0, 'The default value for allow_change_from_others should be 0' );
is( output_pref($shelf->created_on), output_pref(dt_from_string), 'The creation time should have been set to today' );
my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
@ -194,50 +193,42 @@ subtest 'Shelf content' => sub {
my $contents = $shelf->get_contents;
is( $contents->count, 2, 'There are 2 biblios on this shelf' );
# Patron 2 will try to remove a content
# allow_add = 0, allow_delete_own = 1, allow_delete_other = 0 => Default values
# Patron 2 will try to remove biblios
# allow_change_from_owner = 1, allow_change_from_others = 0 (defaults)
my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
# Now try with patron 1
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 1, 'To be sure the content has been deleted' );
# allow_delete_own = 0
$shelf->allow_delete_own(0);
# allow_change_from_owner == 0 (readonly)
$shelf->allow_change_from_owner( 0 );
$shelf->store;
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
is( $number_of_deleted_biblios, 1, 'Patron 1 removed another biblio' );
is( $number_of_deleted_biblios, 0, 'Owner could not delete' );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 0, 'The biblio should have been deleted to the shelf by the patron, it is his own content (allow_delete_own=0)' );
is( $number_of_contents, 1, 'Number of entries still equal to 1' );
$shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 1, 'Biblio not added to the list' );
# Add back biblio1
$shelf->allow_change_from_owner( 1 );
$shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 2, 'Biblio added to the list' );
# allow_add = 1, allow_delete_own = 1
$shelf->allow_add(1);
$shelf->allow_delete_own(1);
$shelf->store;
# allow_change_from_others == 1
$shelf->allow_change_from_others( 1 );
my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 3, 'The biblio should have been added to the shelf by the patron 2' );
is( $number_of_contents, 4, 'The biblio should have been added to the shelf by the patron 2' );
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 2, 'The biblio should have been deleted to the shelf by the patron, it is his own content (allow_delete_own=1) ' );
# allow_add = 1, allow_delete_own = 1, allow_delete_other = 1
$shelf->allow_delete_other(1);
$shelf->store;
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
is( $number_of_deleted_biblios, 1, 'Biblio 2 deleted by patron 2' );
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 1, 'The biblio should have been deleted to the shelf by the patron 2, even if it is not his own content (allow_delete_other=1)' );
is( $number_of_contents, 3, 'Back to three entries' );
teardown();
};
@ -257,9 +248,8 @@ subtest 'Shelf permissions' => sub {
{ shelfname => "my first shelf",
owner => $patron1->{borrowernumber},
category => 2,
allow_add => 0,
allow_delete_own => 0,
allow_delete_other => 0,
allow_change_from_owner => 0,
allow_change_from_others => 0,
}
)->store;
@ -272,6 +262,25 @@ subtest 'Shelf permissions' => sub {
is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to his list' );
is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to his list' );
is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
$public_shelf->allow_change_from_owner(1);
$public_shelf->store;
is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
@ -279,34 +288,12 @@ subtest 'Shelf permissions' => sub {
is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
$public_shelf->allow_add(1);
$public_shelf->allow_delete_own(1);
$public_shelf->allow_delete_other(1);
$public_shelf->store;
is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 1, 'Public list should not be modified (add) by someone else' );
is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 1, 'Public list should not be modified (remove) by someone else' );
my $private_shelf = Koha::Virtualshelf->new(
{ shelfname => "my first shelf",
owner => $patron1->{borrowernumber},
category => 1,
allow_add => 0,
allow_delete_own => 0,
allow_delete_other => 0,
allow_change_from_owner => 0,
allow_change_from_others => 0,
}
)->store;
@ -319,16 +306,15 @@ subtest 'Shelf permissions' => sub {
is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to his list' );
is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (add) by someone else' );
is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to his list' );
is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (remove) by someone else' );
$private_shelf->allow_add(1);
$private_shelf->allow_delete_own(1);
$private_shelf->allow_delete_other(1);
$private_shelf->allow_change_from_owner(1);
$private_shelf->allow_change_from_others(1);
$private_shelf->store;
is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
@ -438,7 +424,7 @@ subtest 'Get shelves containing biblios' => sub {
my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron1->{borrowernumber} );
my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
{