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 => 5; |
4 |
use Test::More tests => 6; |
5 |
use DateTime::Duration; |
5 |
use DateTime::Duration; |
6 |
|
6 |
|
7 |
use C4::Context; |
7 |
use C4::Context; |
Lines 404-409
subtest 'Get shelves' => sub {
Link Here
|
404 |
teardown(); |
404 |
teardown(); |
405 |
}; |
405 |
}; |
406 |
|
406 |
|
|
|
407 |
subtest 'Get shelves containing biblios' => sub { |
408 |
|
409 |
plan tests => 9; |
410 |
my $patron1 = $builder->build( { source => 'Borrower', } ); |
411 |
my $patron2 = $builder->build( { source => 'Borrower', } ); |
412 |
my $biblio1 = $builder->build( { source => 'Biblio', } ); |
413 |
my $biblio2 = $builder->build( { source => 'Biblio', } ); |
414 |
my $biblio3 = $builder->build( { source => 'Biblio', } ); |
415 |
my $biblio4 = $builder->build( { source => 'Biblio', } ); |
416 |
|
417 |
my $shelf1 = Koha::Virtualshelf->new( |
418 |
{ shelfname => "my first shelf", |
419 |
owner => $patron1->{borrowernumber}, |
420 |
category => 1, |
421 |
} |
422 |
)->store; |
423 |
my $shelf2 = Koha::Virtualshelf->new( |
424 |
{ shelfname => "my x second shelf", # 'x' to make it sorted after 'third' |
425 |
owner => $patron2->{borrowernumber}, |
426 |
category => 1, |
427 |
} |
428 |
)->store; |
429 |
my $shelf3 = Koha::Virtualshelf->new( |
430 |
{ shelfname => "my third shelf", |
431 |
owner => $patron1->{borrowernumber}, |
432 |
category => 2, |
433 |
} |
434 |
)->store; |
435 |
|
436 |
my $content1 = $shelf1->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} ); |
437 |
my $content2 = $shelf1->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} ); |
438 |
my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} ); |
439 |
my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} ); |
440 |
my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} ); |
441 |
my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} ); |
442 |
|
443 |
my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record( |
444 |
{ |
445 |
biblionumber => $biblio1->{biblionumber}, |
446 |
} |
447 |
); |
448 |
is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' ); |
449 |
|
450 |
my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record( |
451 |
{ |
452 |
biblionumber => $biblio4->{biblionumber}, |
453 |
} |
454 |
); |
455 |
is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' ); |
456 |
is ( $shelves_with_biblio4_for_any_patrons->next->shelfname, $shelf3->shelfname, 'The correct shelf (3) should be displayed' ); |
457 |
|
458 |
my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record( |
459 |
{ |
460 |
biblionumber => $biblio1->{biblionumber}, |
461 |
borrowernumber => $patron2->{borrowernumber}, |
462 |
} |
463 |
); |
464 |
is ( $shelves_with_biblio1_for_other_patrons->count, 0, 'shelf1 is private and should not be displayed for other patrons' ); |
465 |
|
466 |
my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record( |
467 |
{ |
468 |
biblionumber => $biblio1->{biblionumber}, |
469 |
borrowernumber => $patron1->{borrowernumber}, |
470 |
} |
471 |
); |
472 |
is ( $shelves_with_biblio1_for_owner->count, 1, 'shelf1 is private and should be displayed for the owner' ); |
473 |
|
474 |
my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record( |
475 |
{ |
476 |
biblionumber => $biblio2->{biblionumber}, |
477 |
borrowernumber => $patron1->{borrowernumber}, |
478 |
} |
479 |
); |
480 |
is ( $shelves_with_biblio2_for_patron1->count, 1, 'Only shelf1 should be displayed for patron 1 and biblio 1' ); |
481 |
is ( $shelves_with_biblio2_for_patron1->next->shelfname, $shelf1->shelfname, 'The correct shelf (1) should be displayed for patron 1' ); |
482 |
|
483 |
my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record( |
484 |
{ |
485 |
biblionumber => $biblio4->{biblionumber}, |
486 |
borrowernumber => $patron2->{borrowernumber}, |
487 |
} |
488 |
); |
489 |
is ( $shelves_with_biblio4_for_patron2->count, 2, 'Patron should shown private and public lists for a given biblio' ); |
490 |
is ( $shelves_with_biblio4_for_patron2->next->shelfname, $shelf3->shelfname, 'The shelves should be sorted by shelfname' ); |
491 |
|
492 |
teardown(); |
493 |
}; |
494 |
|
407 |
sub teardown { |
495 |
sub teardown { |
408 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
496 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
409 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
497 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
410 |
- |
|
|