Bug 22884: Show separator between 440 and 490 fields
[koha.git] / t / db_dependent / Virtualshelves.t
blob9f830fb45ba933976a309e8b5e52749b752b4c72
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::Database;
9 use Koha::DateUtils;
10 use Koha::Virtualshelves;
11 use Koha::Virtualshelfshares;
12 use Koha::Virtualshelfcontents;
14 use t::lib::Dates;
15 use t::lib::TestBuilder;
17 my $builder = t::lib::TestBuilder->new;
19 my $schema = Koha::Database->new->schema;
20 $schema->storage->txn_begin;
21 my $dbh = C4::Context->dbh;
22 teardown();
24 subtest 'CRUD' => sub {
25 plan tests => 13;
26 my $patron = $builder->build({
27 source => 'Borrower',
28 });
30 my $number_of_shelves = Koha::Virtualshelves->search->count;
32 is( $number_of_shelves, 0, 'No shelves should exist' );
34 my $shelf = Koha::Virtualshelf->new({
35 shelfname => "my first shelf",
36 owner => $patron->{borrowernumber},
37 category => 1,
39 )->store;
41 is( ref( $shelf ), 'Koha::Virtualshelf', 'The constructor should return a valid object' );
43 $number_of_shelves = Koha::Virtualshelves->search->count;
44 is( $number_of_shelves, 1, '1 shelf should have been inserted' );
45 is( $shelf->allow_change_from_owner, 1, 'The default value for allow_change_from_owner should be 1' );
46 is( $shelf->allow_change_from_others, 0, 'The default value for allow_change_from_others should be 0' );
47 is( t::lib::Dates::compare( $shelf->created_on, dt_from_string), 0, 'The creation time should have been set to today' );
49 # Test if creation date will not be overwritten by store
50 my $created = dt_from_string->subtract( hours => 1 );
51 $shelf->created_on( $created );
52 $shelf->store;
54 my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
56 is( $retrieved_shelf->shelfname, $shelf->shelfname, 'Find should correctly return the shelfname' );
57 is( t::lib::Dates::compare( $retrieved_shelf->created_on, $created), 0, 'Creation date is the same after update (Bug 18672)' );
59 # Insert with the same name
60 eval {
61 $shelf = Koha::Virtualshelf->new({
62 shelfname => "my first shelf",
63 owner => $patron->{borrowernumber},
64 category => 1,
66 )->store;
68 is( ref($@), 'Koha::Exceptions::Virtualshelves::DuplicateObject',
69 'Exception on duplicate name' );
70 $number_of_shelves = Koha::Virtualshelves->search->count;
71 is( $number_of_shelves, 1, 'To be sure the number of shelves is still 1' );
73 my $another_patron = $builder->build({
74 source => 'Borrower',
75 });
77 $shelf = Koha::Virtualshelf->new({
78 shelfname => "my first shelf",
79 owner => $another_patron->{borrowernumber},
80 category => 1,
82 )->store;
83 $number_of_shelves = Koha::Virtualshelves->search->count;
84 is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
86 my $is_deleted = Koha::Virtualshelves->find( $shelf->shelfnumber )->delete;
87 is( $is_deleted, 1, 'The shelf has been deleted correctly' );
88 $number_of_shelves = Koha::Virtualshelves->search->count;
89 is( $number_of_shelves, 1, 'To be sure the shelf has been deleted' );
91 teardown();
94 subtest 'Sharing' => sub {
95 plan tests => 21;
96 my $patron_wants_to_share = $builder->build({
97 source => 'Borrower',
98 });
99 my $share_with_me = $builder->build({
100 source => 'Borrower',
102 my $just_another_patron = $builder->build({
103 source => 'Borrower',
106 my $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
107 is( $number_of_shelves_shared, 0, 'No shelves should exist' );
109 my $shelf_to_share = Koha::Virtualshelf->new({
110 shelfname => "my first shelf",
111 owner => $patron_wants_to_share->{borrowernumber},
112 category => 1,
114 )->store;
116 my $shelf_not_to_share = Koha::Virtualshelf->new({
117 shelfname => "my second shelf",
118 owner => $patron_wants_to_share->{borrowernumber},
119 category => 1,
121 )->store;
123 my $shared_shelf = eval { $shelf_to_share->share };
124 is ( ref( $@ ), 'Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing', 'Do not share if no key given' );
125 $shared_shelf = eval { $shelf_to_share->share('valid key') };
126 is( ref( $shared_shelf ), 'Koha::Virtualshelfshare', 'On sharing, the method should return a valid Koha::Virtualshelfshare object' );
128 my $another_shared_shelf = eval { $shelf_to_share->share('valid key2') }; # Just to have 2 shares in DB
130 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
131 is( $number_of_shelves_shared, 2, '2 shares should have been inserted' );
133 my $is_accepted = eval {
134 $shared_shelf->accept( 'invalid k', $share_with_me->{borrowernumber} );
136 is( $is_accepted, undef, 'The share should have not been accepted if the key is invalid' );
137 is( ref( $@ ), 'Koha::Exceptions::Virtualshelves::InvalidInviteKey', 'accept with an invalid key should raise an exception' );
139 $is_accepted = $shared_shelf->accept( 'valid key', $share_with_me->{borrowernumber} );
140 ok( defined($is_accepted), 'The share should have been accepted if the key valid' );
142 is( $shelf_to_share->is_shared, 1, 'first shelf is shared' );
143 is( $shelf_not_to_share->is_shared, 0, 'second shelf is not shared' );
145 is( $shelf_to_share->is_shared_with( $patron_wants_to_share->{borrowernumber} ), 0 , "The shelf should not be shared with the owner" );
146 is( $shelf_to_share->is_shared_with( $share_with_me->{borrowernumber} ), 1 , "The shelf should be shared with share_with_me" );
147 is( $shelf_to_share->is_shared_with( $just_another_patron->{borrowernumber} ), 0, "The shelf should not be shared with just_another_patron" );
149 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' );
150 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
151 is( $number_of_shelves_shared, 2, 'To be sure no shares have been removed' );
153 is( $shelf_not_to_share->remove_share( $share_with_me->{borrowernumber} ), 0, '0 share should have been removed if the shelf is not share' );
154 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
155 is( $number_of_shelves_shared, 2, 'To be sure no shares have been removed' );
157 # Test double accept (BZ 11943) before removing the accepted share
158 my $third_share = $shelf_to_share->share('valid key3');
159 is( Koha::Virtualshelfshares->search->count, 3, 'Three shares' );
160 $is_accepted = $third_share->accept( 'valid key3', $share_with_me->{borrowernumber} );
161 is( $is_accepted->shelfnumber, $shelf_to_share->shelfnumber, 'Accept returned the existing share' );
162 is( Koha::Virtualshelfshares->search->count, 2, 'Check that number of shares went down again' );
164 # Remove the first accept
165 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' );
166 $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
167 is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' );
169 teardown();
172 subtest 'Shelf content' => sub {
174 plan tests => 18;
175 my $patron1 = $builder->build( { source => 'Borrower', } );
176 my $patron2 = $builder->build( { source => 'Borrower', } );
177 my $biblio1 = $builder->build( { source => 'Biblio', } );
178 my $biblio2 = $builder->build( { source => 'Biblio', } );
179 my $biblio3 = $builder->build( { source => 'Biblio', } );
180 my $biblio4 = $builder->build( { source => 'Biblio', } );
181 my $number_of_contents = Koha::Virtualshelfcontents->search->count;
183 is( $number_of_contents, 0, 'No content should exist' );
185 my $dt_yesterday = dt_from_string->subtract_duration( DateTime::Duration->new( days => 1 ) );
186 my $shelf = Koha::Virtualshelf->new(
187 { shelfname => "my first shelf",
188 owner => $patron1->{borrowernumber},
189 category => 1,
190 lastmodified => $dt_yesterday,
192 )->store;
194 $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
195 is( t::lib::Dates::compare( $shelf->lastmodified, $dt_yesterday), 0, 'The lastmodified has been set to yesterday, will be useful for another test later' );
196 my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
197 is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
198 $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
199 is( t::lib::Dates::compare( $shelf->lastmodified, dt_from_string), 0, 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
200 my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
201 $number_of_contents = Koha::Virtualshelfcontents->search->count;
202 is( $number_of_contents, 2, '2 biblio should have been inserted' );
204 my $content1_bis = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
205 is( $content1_bis, undef, 'add_biblio should return undef on duplicate' ); # Or an exception ?
206 $number_of_contents = Koha::Virtualshelfcontents->search->count;
207 is( $number_of_contents, 2, 'The biblio should not have been duplicated' );
209 $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
210 my $contents = $shelf->get_contents;
211 is( $contents->count, 2, 'There are 2 biblios on this shelf' );
213 # Patron 2 will try to remove biblios
214 # allow_change_from_owner = 1, allow_change_from_others = 0 (defaults)
215 my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
216 is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
217 # Now try with patron 1
218 $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
219 is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
220 $number_of_contents = Koha::Virtualshelfcontents->search->count;
221 is( $number_of_contents, 1, 'To be sure the content has been deleted' );
223 # allow_change_from_owner == 0 (readonly)
224 $shelf->allow_change_from_owner( 0 );
225 $shelf->store;
226 $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
227 is( $number_of_deleted_biblios, 0, 'Owner could not delete' );
228 $number_of_contents = Koha::Virtualshelfcontents->search->count;
229 is( $number_of_contents, 1, 'Number of entries still equal to 1' );
230 $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
231 $number_of_contents = Koha::Virtualshelfcontents->search->count;
232 is( $number_of_contents, 1, 'Biblio not added to the list' );
233 # Add back biblio1
234 $shelf->allow_change_from_owner( 1 );
235 $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
236 $number_of_contents = Koha::Virtualshelfcontents->search->count;
237 is( $number_of_contents, 2, 'Biblio added to the list' );
239 # allow_change_from_others == 1
240 $shelf->allow_change_from_others( 1 );
241 my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
242 my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
243 $number_of_contents = Koha::Virtualshelfcontents->search->count;
244 is( $number_of_contents, 4, 'The biblio should have been added to the shelf by the patron 2' );
245 $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
246 is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
247 $number_of_contents = Koha::Virtualshelfcontents->search->count;
248 is( $number_of_contents, 3, 'Back to three entries' );
250 teardown();
253 subtest 'Shelf permissions' => sub {
255 plan tests => 40;
256 my $patron1 = $builder->build( { source => 'Borrower', value => { flags => '2096766' } } ); # 2096766 is everything checked but not superlibrarian
257 my $patron2 = $builder->build( { source => 'Borrower', value => { flags => '1048190' } } ); # 1048190 is everything checked but not superlibrarian and delete_public_lists
258 my $biblio1 = $builder->build( { source => 'Biblio', } );
259 my $biblio2 = $builder->build( { source => 'Biblio', } );
260 my $biblio3 = $builder->build( { source => 'Biblio', } );
261 my $biblio4 = $builder->build( { source => 'Biblio', } );
264 my $public_shelf = Koha::Virtualshelf->new(
265 { shelfname => "my first shelf",
266 owner => $patron1->{borrowernumber},
267 category => 2,
268 allow_change_from_owner => 0,
269 allow_change_from_others => 0,
271 )->store;
273 is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
274 is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
276 is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
277 is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
279 is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
280 is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
282 is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to their list' );
283 is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
285 is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to their list' );
286 is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
289 $public_shelf->allow_change_from_owner(1);
290 $public_shelf->store;
292 is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
293 is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
295 is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
296 is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
298 is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
299 is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
301 is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
302 is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
304 is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
305 is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
308 my $private_shelf = Koha::Virtualshelf->new(
309 { shelfname => "my first shelf",
310 owner => $patron1->{borrowernumber},
311 category => 1,
312 allow_change_from_owner => 0,
313 allow_change_from_others => 0,
315 )->store;
317 is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
318 is( $private_shelf->can_be_viewed( $patron2->{borrowernumber} ), 0, 'Private list should not be viewed by someone else' );
320 is( $private_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
321 is( $private_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Private list should not be deleted by someone else' );
323 is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
324 is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
326 is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to their list' );
327 is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (add) by someone else' );
329 is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to their list' );
330 is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (remove) by someone else' );
333 $private_shelf->allow_change_from_owner(1);
334 $private_shelf->allow_change_from_others(1);
335 $private_shelf->store;
337 is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
338 is( $private_shelf->can_be_viewed( $patron2->{borrowernumber} ), 0, 'Private list should not be viewed by someone else' );
340 is( $private_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
341 is( $private_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Private list should not be deleted by someone else' );
343 is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
344 is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
346 is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
347 is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 1, 'Private list could be modified (add) by someone else # individual check done later' );
349 is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
350 is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 1, 'Private list could be modified (remove) by someone else # individual check done later' );
352 teardown();
355 subtest 'Get shelves' => sub {
356 plan tests => 4;
357 my $patron1 = $builder->build({
358 source => 'Borrower',
360 my $patron2 = $builder->build({
361 source => 'Borrower',
364 my $private_shelf1_1 = Koha::Virtualshelf->new({
365 shelfname => "private shelf 1 for patron 1",
366 owner => $patron1->{borrowernumber},
367 category => 1,
369 )->store;
370 my $private_shelf1_2 = Koha::Virtualshelf->new({
371 shelfname => "private shelf 2 for patron 1",
372 owner => $patron1->{borrowernumber},
373 category => 1,
375 )->store;
376 my $private_shelf2_1 = Koha::Virtualshelf->new({
377 shelfname => "private shelf 1 for patron 2",
378 owner => $patron2->{borrowernumber},
379 category => 1,
381 )->store;
382 my $public_shelf1_1 = Koha::Virtualshelf->new({
383 shelfname => "public shelf 1 for patron 1",
384 owner => $patron1->{borrowernumber},
385 category => 2,
387 )->store;
388 my $public_shelf1_2 = Koha::Virtualshelf->new({
389 shelfname => "public shelf 2 for patron 1",
390 owner => $patron1->{borrowernumber},
391 category => 2,
393 )->store;
395 my $private_shelves = Koha::Virtualshelves->get_private_shelves;
396 is( $private_shelves->count, 0, 'Without borrowernumber given, get_private_shelves should not return any shelf' );
397 $private_shelves = Koha::Virtualshelves->get_private_shelves({ borrowernumber => $patron1->{borrowernumber} });
398 is( $private_shelves->count, 2, 'get_private_shelves should return all shelves for a given patron' );
400 $private_shelf2_1->share('a key')->accept('a key', $patron1->{borrowernumber});
401 $private_shelves = Koha::Virtualshelves->get_private_shelves({ borrowernumber => $patron1->{borrowernumber} });
402 is( $private_shelves->count, 3, 'get_private_shelves should return all shelves for a given patron, even the shared ones' );
404 my $public_shelves = Koha::Virtualshelves->get_public_shelves;
405 is( $public_shelves->count, 2, 'get_public_shelves should return all public shelves, no matter who is the owner' );
407 teardown();
410 subtest 'Get shelves containing biblios' => sub {
412 plan tests => 9;
413 my $patron1 = $builder->build( { source => 'Borrower', } );
414 my $patron2 = $builder->build( { source => 'Borrower', } );
415 my $biblio1 = $builder->build( { source => 'Biblio', } );
416 my $biblio2 = $builder->build( { source => 'Biblio', } );
417 my $biblio3 = $builder->build( { source => 'Biblio', } );
418 my $biblio4 = $builder->build( { source => 'Biblio', } );
420 my $shelf1 = Koha::Virtualshelf->new(
421 { shelfname => "my first shelf",
422 owner => $patron1->{borrowernumber},
423 category => 1,
425 )->store;
426 my $shelf2 = Koha::Virtualshelf->new(
427 { shelfname => "my x second shelf", # 'x' to make it sorted after 'third'
428 owner => $patron2->{borrowernumber},
429 category => 1,
431 )->store;
432 my $shelf3 = Koha::Virtualshelf->new(
433 { shelfname => "my third shelf",
434 owner => $patron1->{borrowernumber},
435 category => 2,
437 )->store;
439 my $content1 = $shelf1->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
440 my $content2 = $shelf1->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
441 my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
442 my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
443 my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
444 my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron1->{borrowernumber} );
446 my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
448 biblionumber => $biblio1->{biblionumber},
451 is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' );
453 my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
455 biblionumber => $biblio4->{biblionumber},
458 is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' );
459 is ( $shelves_with_biblio4_for_any_patrons->next->shelfname, $shelf3->shelfname, 'The correct shelf (3) should be displayed' );
461 my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record(
463 biblionumber => $biblio1->{biblionumber},
464 borrowernumber => $patron2->{borrowernumber},
467 is ( $shelves_with_biblio1_for_other_patrons->count, 0, 'shelf1 is private and should not be displayed for other patrons' );
469 my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record(
471 biblionumber => $biblio1->{biblionumber},
472 borrowernumber => $patron1->{borrowernumber},
475 is ( $shelves_with_biblio1_for_owner->count, 1, 'shelf1 is private and should be displayed for the owner' );
477 my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record(
479 biblionumber => $biblio2->{biblionumber},
480 borrowernumber => $patron1->{borrowernumber},
483 is ( $shelves_with_biblio2_for_patron1->count, 1, 'Only shelf1 should be displayed for patron 1 and biblio 1' );
484 is ( $shelves_with_biblio2_for_patron1->next->shelfname, $shelf1->shelfname, 'The correct shelf (1) should be displayed for patron 1' );
486 my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record(
488 biblionumber => $biblio4->{biblionumber},
489 borrowernumber => $patron2->{borrowernumber},
492 is ( $shelves_with_biblio4_for_patron2->count, 2, 'Patron should shown private and public lists for a given biblio' );
493 is ( $shelves_with_biblio4_for_patron2->next->shelfname, $shelf3->shelfname, 'The shelves should be sorted by shelfname' );
495 teardown();
498 sub teardown {
499 $dbh->do(q|DELETE FROM virtualshelfshares|);
500 $dbh->do(q|DELETE FROM virtualshelfcontents|);
501 $dbh->do(q|DELETE FROM virtualshelves|);