Bug 32730: Add tests for Koha::Patron->get_lists_with_patron

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2023-11-01 16:52:08 -03:00
parent 21504e2ab4
commit 79908aef27
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -19,7 +19,7 @@
use Modern::Perl; use Modern::Perl;
use Test::More tests => 30; use Test::More tests => 31;
use Test::Exception; use Test::Exception;
use Test::Warn; use Test::Warn;
use Time::Fake; use Time::Fake;
@ -29,6 +29,7 @@ use Koha::Database;
use Koha::DateUtils qw(dt_from_string); use Koha::DateUtils qw(dt_from_string);
use Koha::ArticleRequests; use Koha::ArticleRequests;
use Koha::Patrons; use Koha::Patrons;
use Koha::List::Patron qw(AddPatronList AddPatronsToList);
use Koha::Patron::Relationships; use Koha::Patron::Relationships;
use C4::Circulation qw( AddIssue AddReturn ); use C4::Circulation qw( AddIssue AddReturn );
@ -2114,3 +2115,33 @@ subtest 'update_lastseen tests' => sub {
Time::Fake->reset; Time::Fake->reset;
$schema->storage->txn_rollback; $schema->storage->txn_rollback;
}; };
subtest 'get_lists_with_patron() tests' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $owner = $builder->build_object( { class => 'Koha::Patrons' } );
my $list_1 = AddPatronList( { name => ' Ya', owner => $owner->id } );
my $list_2 = AddPatronList( { name => 'Hey!', owner => $owner->id } );
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my @lists = $patron->get_lists_with_patron();
is( scalar @lists, 0, 'Patron not included in any list' );
AddPatronsToList( { list => $list_1, cardnumbers => [ $patron->cardnumber ] } );
AddPatronsToList( { list => $list_2, cardnumbers => [ $patron->cardnumber ] } );
@lists = $patron->get_lists_with_patron();
foreach my $list (@lists) {
is( ref($list), 'Koha::Schema::Result::PatronList', 'Type is correct' );
}
is( join( ' ', map { $_->name } @lists ), ' Ya Hey!', 'Lists are the correct ones, and sorted alphabetically' );
$schema->storage->txn_rollback;
};