Bug 10021: Remove notify headers from pay*.tt
[koha.git] / t / db_dependent / Virtualshelves.t
blobf77e36b32cf46b83e0941ff4bcd09af5ab183ca5
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Test::More tests => 6;
5 use DateTime::Duration;
7 use C4::Context;
8 use Koha::DateUtils;
9 use Koha::Virtualshelves;
10 use Koha::Virtualshelfshares;
11 use Koha::Virtualshelfcontents;
13 use t::lib::Dates;
14 use t::lib::TestBuilder;
16 my $builder = t::lib::TestBuilder->new;
18 my $dbh = C4::Context->dbh;
19 $dbh->{AutoCommit} = 0;
20 teardown();
22 subtest 'CRUD' => sub {
23 plan tests => 13;
24 my $patron = $builder->build({
25 source => 'Borrower',
26 });
28 my $number_of_shelves = Koha::Virtualshelves->search->count;
30 is( $number_of_shelves, 0, 'No shelves should exist' );
32 my $shelf = Koha::Virtualshelf->new({
33 shelfname => "my first shelf",
34 owner => $patron->{borrowernumber},
35 category => 1,
37 )->store;
39 is( ref( $shelf ), 'Koha::Virtualshelf', 'The constructor should return a valid object' );
41 $number_of_shelves = Koha::Virtualshelves->search->count;
42 is( $number_of_shelves, 1, '1 shelf should have been inserted' );
43 is( $shelf->allow_change_from_owner, 1, 'The default value for allow_change_from_owner should be 1' );
44 is( $shelf->allow_change_from_others, 0, 'The default value for allow_change_from_others should be 0' );
45 is( t::lib::Dates::compare( $shelf->created_on, dt_from_string), 0, 'The creation time should have been set to today' );
47 # Test if creation date will not be overwritten by store
48 my $created = dt_from_string->subtract( hours => 1 );
49 $shelf->created_on( $created );
50 $shelf->store;
52 my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
54 is( $retrieved_shelf->shelfname, $shelf->shelfname, 'Find should correctly return the shelfname' );
55 is( t::lib::Dates::compare( $retrieved_shelf->created_on, $created), 0, 'Creation date is the same after update (Bug 18672)' );
57 # Insert with the same name
58 eval {
59 $shelf = Koha::Virtualshelf->new({
60 shelfname => "my first shelf",
61 owner => $patron->{borrowernumber},
62 category => 1,
64 )->store;
66 is( ref($@), 'Koha::Exceptions::Virtualshelves::DuplicateObject',
67 'Exception on duplicate name' );
68 $number_of_shelves = Koha::Virtualshelves->search->count;
69 is( $number_of_shelves, 1, 'To be sure the number of shelves is still 1' );
71 my $another_patron = $builder->build({
72 source => 'Borrower',
73 });
75 $shelf = Koha::Virtualshelf->new({
76 shelfname => "my first shelf",
77 owner => $another_patron->{borrowernumber},
78 category => 1,
80 )->store;
81 $number_of_shelves = Koha::Virtualshelves->search->count;
82 is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
84 my $is_deleted = Koha::Virtualshelves->find( $shelf->shelfnumber )->delete;
85 is( $is_deleted, 1, 'The shelf has been deleted correctly' );
86 $number_of_shelves = Koha::Virtualshelves->search->count;
87 is( $number_of_shelves, 1, 'To be sure the shelf has been deleted' );
89 teardown();
92 subtest 'Sharing' => sub {
93 plan tests => 18;
94 my $patron_wants_to_share = $builder->build({
95 source => 'Borrower',
96 });
97 my $share_with_me = $builder->build({
98 source => 'Borrower',
99 });
100 my $just_another_patron = $builder->build({
101 source => 'Borrower',
104 my $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
105 is( $number_of_shelves_shared, 0, 'No shelves should exist' );
107 my $shelf_to_share = Koha::Virtualshelf->new({
108 shelfname => "my first shelf",
109 owner => $patron_wants_to_share->{borrowernumber},
110 category => 1,
112 )->store;
114 my $shelf_not_to_share = Koha::Virtualshelf->new({
115 shelfname => "my second shelf",
116 owner => $patron_wants_to_share->{borrowernumber},
117 category => 1,
119 )->store;
121 my $shared_shelf = eval { $shelf_to_share->share };
122 is ( ref( $@ ), 'Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing', 'Do not share if no key given' );
123 $shared_shelf = eval { $shelf_to_share->share('this is a valid key') };
124 is( ref( $shared_shelf ), 'Koha::Virtualshelfshare', 'On sharing, the method should return a valid Koha::Virtualshelfshare object' );
126 my $another_shared_shelf = eval { $shelf_to_share->share('this is another valid key') }; # Just to have 2 shares in DB
128 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
129 is( $number_of_shelves_shared, 2, '2 shares should have been inserted' );
131 my $is_accepted = eval {
132 $shared_shelf->accept( 'this is an invalid key', $share_with_me->{borrowernumber} );
134 is( $is_accepted, undef, 'The share should have not been accepted if the key is invalid' );
135 is( ref( $@ ), 'Koha::Exceptions::Virtualshelves::InvalidInviteKey', 'accept with an invalid key should raise an exception' );
137 $is_accepted = $shared_shelf->accept( 'this is a valid key', $share_with_me->{borrowernumber} );
138 ok( defined($is_accepted), 'The share should have been accepted if the key valid' );
140 is( $shelf_to_share->is_shared, 1, 'first shelf is shared' );
141 is( $shelf_not_to_share->is_shared, 0, 'second shelf is not shared' );
143 is( $shelf_to_share->is_shared_with( $patron_wants_to_share->{borrowernumber} ), 0 , "The shelf should not be shared with the owner" );
144 is( $shelf_to_share->is_shared_with( $share_with_me->{borrowernumber} ), 1 , "The shelf should be shared with share_with_me" );
145 is( $shelf_to_share->is_shared_with( $just_another_patron->{borrowernumber} ), 0, "The shelf should not be shared with just_another_patron" );
147 is( $shelf_to_share->remove_share( $just_another_patron->{borrowernumber} ), 0, 'No share should be removed if the share has not been done with this patron' );
148 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
149 is( $number_of_shelves_shared, 2, 'To be sure no shares have been removed' );
151 is( $shelf_not_to_share->remove_share( $share_with_me->{borrowernumber} ), 0, '0 share should have been removed if the shelf is not share' );
152 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
153 is( $number_of_shelves_shared, 2, 'To be sure no shares have been removed' );
155 is( $shelf_to_share->remove_share( $share_with_me->{borrowernumber} ), 1, '1 share should have been removed if the shelf was shared with this patron' );
156 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
157 is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' );
159 teardown();
162 subtest 'Shelf content' => sub {
164 plan tests => 18;
165 my $patron1 = $builder->build( { source => 'Borrower', } );
166 my $patron2 = $builder->build( { source => 'Borrower', } );
167 my $biblio1 = $builder->build( { source => 'Biblio', } );
168 my $biblio2 = $builder->build( { source => 'Biblio', } );
169 my $biblio3 = $builder->build( { source => 'Biblio', } );
170 my $biblio4 = $builder->build( { source => 'Biblio', } );
171 my $number_of_contents = Koha::Virtualshelfcontents->search->count;
173 is( $number_of_contents, 0, 'No content should exist' );
175 my $dt_yesterday = dt_from_string->subtract_duration( DateTime::Duration->new( days => 1 ) );
176 my $shelf = Koha::Virtualshelf->new(
177 { shelfname => "my first shelf",
178 owner => $patron1->{borrowernumber},
179 category => 1,
180 lastmodified => $dt_yesterday,
182 )->store;
184 $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
185 is( t::lib::Dates::compare( $shelf->lastmodified, $dt_yesterday), 0, 'The lastmodified has been set to yesterday, will be useful for another test later' );
186 my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
187 is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
188 $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
189 is( t::lib::Dates::compare( $shelf->lastmodified, dt_from_string), 0, 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
190 my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
191 $number_of_contents = Koha::Virtualshelfcontents->search->count;
192 is( $number_of_contents, 2, '2 biblio should have been inserted' );
194 my $content1_bis = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
195 is( $content1_bis, undef, 'add_biblio should return undef on duplicate' ); # Or an exception ?
196 $number_of_contents = Koha::Virtualshelfcontents->search->count;
197 is( $number_of_contents, 2, 'The biblio should not have been duplicated' );
199 $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
200 my $contents = $shelf->get_contents;
201 is( $contents->count, 2, 'There are 2 biblios on this shelf' );
203 # Patron 2 will try to remove biblios
204 # allow_change_from_owner = 1, allow_change_from_others = 0 (defaults)
205 my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
206 is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
207 # Now try with patron 1
208 $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
209 is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
210 $number_of_contents = Koha::Virtualshelfcontents->search->count;
211 is( $number_of_contents, 1, 'To be sure the content has been deleted' );
213 # allow_change_from_owner == 0 (readonly)
214 $shelf->allow_change_from_owner( 0 );
215 $shelf->store;
216 $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
217 is( $number_of_deleted_biblios, 0, 'Owner could not delete' );
218 $number_of_contents = Koha::Virtualshelfcontents->search->count;
219 is( $number_of_contents, 1, 'Number of entries still equal to 1' );
220 $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
221 $number_of_contents = Koha::Virtualshelfcontents->search->count;
222 is( $number_of_contents, 1, 'Biblio not added to the list' );
223 # Add back biblio1
224 $shelf->allow_change_from_owner( 1 );
225 $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
226 $number_of_contents = Koha::Virtualshelfcontents->search->count;
227 is( $number_of_contents, 2, 'Biblio added to the list' );
229 # allow_change_from_others == 1
230 $shelf->allow_change_from_others( 1 );
231 my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
232 my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
233 $number_of_contents = Koha::Virtualshelfcontents->search->count;
234 is( $number_of_contents, 4, 'The biblio should have been added to the shelf by the patron 2' );
235 $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
236 is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
237 $number_of_contents = Koha::Virtualshelfcontents->search->count;
238 is( $number_of_contents, 3, 'Back to three entries' );
240 teardown();
243 subtest 'Shelf permissions' => sub {
245 plan tests => 40;
246 my $patron1 = $builder->build( { source => 'Borrower', value => { flags => '2096766' } } ); # 2096766 is everything checked but not superlibrarian
247 my $patron2 = $builder->build( { source => 'Borrower', value => { flags => '1048190' } } ); # 1048190 is everything checked but not superlibrarian and delete_public_lists
248 my $biblio1 = $builder->build( { source => 'Biblio', } );
249 my $biblio2 = $builder->build( { source => 'Biblio', } );
250 my $biblio3 = $builder->build( { source => 'Biblio', } );
251 my $biblio4 = $builder->build( { source => 'Biblio', } );
254 my $public_shelf = Koha::Virtualshelf->new(
255 { shelfname => "my first shelf",
256 owner => $patron1->{borrowernumber},
257 category => 2,
258 allow_change_from_owner => 0,
259 allow_change_from_others => 0,
261 )->store;
263 is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
264 is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
266 is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
267 is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
269 is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
270 is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
272 is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to their list' );
273 is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
275 is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to their list' );
276 is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
279 $public_shelf->allow_change_from_owner(1);
280 $public_shelf->store;
282 is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
283 is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
285 is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
286 is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
288 is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
289 is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
291 is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
292 is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
294 is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
295 is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
298 my $private_shelf = Koha::Virtualshelf->new(
299 { shelfname => "my first shelf",
300 owner => $patron1->{borrowernumber},
301 category => 1,
302 allow_change_from_owner => 0,
303 allow_change_from_others => 0,
305 )->store;
307 is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
308 is( $private_shelf->can_be_viewed( $patron2->{borrowernumber} ), 0, 'Private list should not be viewed by someone else' );
310 is( $private_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
311 is( $private_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Private list should not be deleted by someone else' );
313 is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
314 is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
316 is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to their list' );
317 is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (add) by someone else' );
319 is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to their list' );
320 is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (remove) by someone else' );
323 $private_shelf->allow_change_from_owner(1);
324 $private_shelf->allow_change_from_others(1);
325 $private_shelf->store;
327 is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
328 is( $private_shelf->can_be_viewed( $patron2->{borrowernumber} ), 0, 'Private list should not be viewed by someone else' );
330 is( $private_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
331 is( $private_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Private list should not be deleted by someone else' );
333 is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
334 is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
336 is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
337 is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 1, 'Private list could be modified (add) by someone else # individual check done later' );
339 is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
340 is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 1, 'Private list could be modified (remove) by someone else # individual check done later' );
342 teardown();
345 subtest 'Get shelves' => sub {
346 plan tests => 4;
347 my $patron1 = $builder->build({
348 source => 'Borrower',
350 my $patron2 = $builder->build({
351 source => 'Borrower',
354 my $private_shelf1_1 = Koha::Virtualshelf->new({
355 shelfname => "private shelf 1 for patron 1",
356 owner => $patron1->{borrowernumber},
357 category => 1,
359 )->store;
360 my $private_shelf1_2 = Koha::Virtualshelf->new({
361 shelfname => "private shelf 2 for patron 1",
362 owner => $patron1->{borrowernumber},
363 category => 1,
365 )->store;
366 my $private_shelf2_1 = Koha::Virtualshelf->new({
367 shelfname => "private shelf 1 for patron 2",
368 owner => $patron2->{borrowernumber},
369 category => 1,
371 )->store;
372 my $public_shelf1_1 = Koha::Virtualshelf->new({
373 shelfname => "public shelf 1 for patron 1",
374 owner => $patron1->{borrowernumber},
375 category => 2,
377 )->store;
378 my $public_shelf1_2 = Koha::Virtualshelf->new({
379 shelfname => "public shelf 2 for patron 1",
380 owner => $patron1->{borrowernumber},
381 category => 2,
383 )->store;
385 my $private_shelves = Koha::Virtualshelves->get_private_shelves;
386 is( $private_shelves->count, 0, 'Without borrowernumber given, get_private_shelves should not return any shelf' );
387 $private_shelves = Koha::Virtualshelves->get_private_shelves({ borrowernumber => $patron1->{borrowernumber} });
388 is( $private_shelves->count, 2, 'get_private_shelves should return all shelves for a given patron' );
390 $private_shelf2_1->share('a key')->accept('a key', $patron1->{borrowernumber});
391 $private_shelves = Koha::Virtualshelves->get_private_shelves({ borrowernumber => $patron1->{borrowernumber} });
392 is( $private_shelves->count, 3, 'get_private_shelves should return all shelves for a given patron, even the shared ones' );
394 my $public_shelves = Koha::Virtualshelves->get_public_shelves;
395 is( $public_shelves->count, 2, 'get_public_shelves should return all public shelves, no matter who is the owner' );
397 teardown();
400 subtest 'Get shelves containing biblios' => sub {
402 plan tests => 9;
403 my $patron1 = $builder->build( { source => 'Borrower', } );
404 my $patron2 = $builder->build( { source => 'Borrower', } );
405 my $biblio1 = $builder->build( { source => 'Biblio', } );
406 my $biblio2 = $builder->build( { source => 'Biblio', } );
407 my $biblio3 = $builder->build( { source => 'Biblio', } );
408 my $biblio4 = $builder->build( { source => 'Biblio', } );
410 my $shelf1 = Koha::Virtualshelf->new(
411 { shelfname => "my first shelf",
412 owner => $patron1->{borrowernumber},
413 category => 1,
415 )->store;
416 my $shelf2 = Koha::Virtualshelf->new(
417 { shelfname => "my x second shelf", # 'x' to make it sorted after 'third'
418 owner => $patron2->{borrowernumber},
419 category => 1,
421 )->store;
422 my $shelf3 = Koha::Virtualshelf->new(
423 { shelfname => "my third shelf",
424 owner => $patron1->{borrowernumber},
425 category => 2,
427 )->store;
429 my $content1 = $shelf1->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
430 my $content2 = $shelf1->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
431 my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
432 my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
433 my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
434 my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron1->{borrowernumber} );
436 my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
438 biblionumber => $biblio1->{biblionumber},
441 is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' );
443 my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
445 biblionumber => $biblio4->{biblionumber},
448 is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' );
449 is ( $shelves_with_biblio4_for_any_patrons->next->shelfname, $shelf3->shelfname, 'The correct shelf (3) should be displayed' );
451 my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record(
453 biblionumber => $biblio1->{biblionumber},
454 borrowernumber => $patron2->{borrowernumber},
457 is ( $shelves_with_biblio1_for_other_patrons->count, 0, 'shelf1 is private and should not be displayed for other patrons' );
459 my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record(
461 biblionumber => $biblio1->{biblionumber},
462 borrowernumber => $patron1->{borrowernumber},
465 is ( $shelves_with_biblio1_for_owner->count, 1, 'shelf1 is private and should be displayed for the owner' );
467 my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record(
469 biblionumber => $biblio2->{biblionumber},
470 borrowernumber => $patron1->{borrowernumber},
473 is ( $shelves_with_biblio2_for_patron1->count, 1, 'Only shelf1 should be displayed for patron 1 and biblio 1' );
474 is ( $shelves_with_biblio2_for_patron1->next->shelfname, $shelf1->shelfname, 'The correct shelf (1) should be displayed for patron 1' );
476 my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record(
478 biblionumber => $biblio4->{biblionumber},
479 borrowernumber => $patron2->{borrowernumber},
482 is ( $shelves_with_biblio4_for_patron2->count, 2, 'Patron should shown private and public lists for a given biblio' );
483 is ( $shelves_with_biblio4_for_patron2->next->shelfname, $shelf3->shelfname, 'The shelves should be sorted by shelfname' );
485 teardown();
488 sub teardown {
489 $dbh->do(q|DELETE FROM virtualshelfshares|);
490 $dbh->do(q|DELETE FROM virtualshelfcontents|);
491 $dbh->do(q|DELETE FROM virtualshelves|);