From 79908aef27ccbb3bb8a37e87d336aba34e12754d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 1 Nov 2023 16:52:08 -0300 Subject: [PATCH] Bug 32730: Add tests for Koha::Patron->get_lists_with_patron Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Patron.t | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 12879efe7c..7313a5d585 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 30; +use Test::More tests => 31; use Test::Exception; use Test::Warn; use Time::Fake; @@ -29,6 +29,7 @@ use Koha::Database; use Koha::DateUtils qw(dt_from_string); use Koha::ArticleRequests; use Koha::Patrons; +use Koha::List::Patron qw(AddPatronList AddPatronsToList); use Koha::Patron::Relationships; use C4::Circulation qw( AddIssue AddReturn ); @@ -2114,3 +2115,33 @@ subtest 'update_lastseen tests' => sub { Time::Fake->reset; $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; +}; -- 2.39.2