From a2ae96c05b8c8a50b8b6903d975d978dd96b209e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 11 Sep 2024 14:04:17 +0000 Subject: [PATCH] Bug 37892: Unit tests These patches will alter the checks for a patron that prevent a category with 'can_be_guarantee' from being a guarantor. Two patrons in the same category should be allowed to have a guarantee/guarantor relationship The tests below assume you are using the KTD sample data. Update borrowernumbers if not. To test: 0 - Apply tests patch 1 - Set the 'Patron' category as 'Can be a guarantee' 2 - Add a relationship between two patrons of the same category This is restricted from the staff interface perl -e 'use Koha::Patrons; my $p = Koha::Patrons->find(5)->add_guarantor({ guarantor_id => 23, relationship => 'father'});' 3 - Note there is no warning or exception. This should be allowed. 4 - Checkout an item to Edna (borrowernumber 5) 5 - Set 'TrackLastPatronActivityTriggers' to 'Checking in an item' 6 - Try to check the item in, KABOOM 7 - Set 'TrackLastPatronActivityTriggers' to 'Checking out an item' 8 - Try to issue an item to Enda, KABOOM 9 - prove -v t/db_dependent/Koha/Patron.t, fail 10 - Apply second patch 11 - prove -v t/db_dependent/Koha/Patron.t, one more test passes, but then fail 12 - Apply third patch 13 - prove -v t/db_dependent/Koha/Patron.t, pass! 14 - restart_all 15 - Checkout to Enda, OK! 16 - Checkin from Edna, OK! 17 - Find two more patrons in the category and attempt to link them 18 - 'Guarantor cannot be a guarantee' 19 - Apply fourth patch 20 - You can add a guarantor from the same category in interface 21 - Try to add a guarantor to the guarantor assigned in 20 22 - Confirm you cannot add a guarantor - "Guarantor cannot be a guarantee" Signed-off-by: Olivier V Signed-off-by: Brendan Lawlor Signed-off-by: Baptiste Wojtkowski --- t/db_dependent/Koha/Patron.t | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 970235e..8a0cd81 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 => 35; +use Test::More tests => 36; use Test::Exception; use Test::Warn; use Time::Fake; @@ -410,6 +410,51 @@ subtest 'add_guarantor() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'guarantor checks on patron creation / update tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'borrowerRelationship', 'guarantor' ); + my $category = $builder->build_object( + { class => 'Koha::Patron::Categories', value => { can_be_guarantee => 1, category_type => 'A' } } ); + + my $guarantor = + $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); + my $guarantee = + $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); + + subtest 'patron update tests' => sub { + plan tests => 4; + ok( + $guarantee->add_guarantor( { guarantor_id => $guarantor->borrowernumber, relationship => 'guarantor' } ), + "Relationship is added, no problem" + ); + is( $guarantor->guarantee_relationships->count, 1, 'Relationship added' ); + ok( $guarantor->surname("Duck")->store(), "Updating guarantor is okay" ); + ok( $guarantee->surname("Duck")->store(), "Updating guarantee is okay" ); + }; + + subtest 'patron update tests' => sub { + plan tests => 1; + + my $new_guarantee = $builder->build_object( + { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); + my $new_guarantee_hash = $new_guarantee->unblessed; + $new_guarantee->delete(); + + delete $new_guarantee_hash->{borrowernumber}; + + ok( + Koha::Patron->new($new_guarantee_hash)->store( { guarantors => [$guarantor] } ), + "We can add the new patron and indicate guarantor" + ); + }; + + $schema->storage->txn_rollback; +}; + subtest 'relationships_debt() tests' => sub { plan tests => 168; -- 2.43.0