From 4bb0d63440b36970121e3f61ab2ed7eb809377e2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 30 Mar 2021 15:47:12 +0100 Subject: [PATCH] Bug 25946: (QA follow-up) Add Unit tests Add a unit test for the empty relationship availability. Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Patron/Relationship.t | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Patron/Relationship.t b/t/db_dependent/Koha/Patron/Relationship.t index 380aaa2ea6..495afad126 100755 --- a/t/db_dependent/Koha/Patron/Relationship.t +++ b/t/db_dependent/Koha/Patron/Relationship.t @@ -35,7 +35,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'store() tests' => sub { - plan tests => 9; + plan tests => 13; $schema->storage->txn_begin; @@ -76,7 +76,23 @@ subtest 'store() tests' => sub { 'No guarantors added' ); - $relationship_1->relationship('father1')->store; + $relationship = ''; + + throws_ok + { $relationship_1->relationship($relationship)->store; } + 'Koha::Exceptions::Patron::Relationship::InvalidRelationship', + 'Exception is thrown as a wrong relationship was passed'; + + is( "$@", "Invalid relationship passed, '$relationship' is not defined.", 'Exception stringified correctly' ); + + is( Koha::Patron::Relationships->search( { guarantee_id => $patron_1->borrowernumber } )->count, + 0, + 'No guarantors added when empty relationship passed and not defined' + ); + + $relationship = 'father1'; + + $relationship_1->relationship($relationship)->store; is( Koha::Patron::Relationships->search( { guarantee_id => $patron_1->borrowernumber } )->count, 1, @@ -108,5 +124,17 @@ subtest 'store() tests' => sub { ); } + t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); + + my $relationship_3 = Koha::Patron::Relationship->new( + { + guarantor_id => $patron_1->borrowernumber, + guarantee_id => $patron_2->borrowernumber, + relationship => '' + } + )->store(); + + is( $relationship_3->relationship, '', 'Empty relationship allowed' ); + $schema->storage->txn_rollback; }; -- 2.20.1