From 5793d9107fe20e11d635009807072bafd42a0b09 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 28 Mar 2024 11:28:04 +0000 Subject: [PATCH] Bug 34597: Add tests prove t/db_dependent/Koha/Illrequest.t prove t/db_dependent/Koha/Patron/Categories.t Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/ILL/Request.t | 22 ++++++++++++++++++++-- t/db_dependent/Koha/Patron/Categories.t | 5 +++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Koha/ILL/Request.t b/t/db_dependent/Koha/ILL/Request.t index 5f4de8a993..2ec832949e 100755 --- a/t/db_dependent/Koha/ILL/Request.t +++ b/t/db_dependent/Koha/ILL/Request.t @@ -20,6 +20,7 @@ use Modern::Perl; use Test::More tests => 3; +use Test::MockModule; use Koha::ILL::Requests; @@ -30,11 +31,20 @@ my $schema = Koha::Database->new->schema; subtest 'patron() tests' => sub { - plan tests => 3; + plan tests => 5; $schema->storage->txn_begin; - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron_module = Test::MockModule->new('Koha::Patron'); + + my $patroncategory = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { can_place_ill_in_opac => 1, BlockExpiredPatronOpacActions => 'ill_request' } + } + ); + my $patron = + $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patroncategory->id } } ); my $request = $builder->build_object( { class => 'Koha::ILL::Requests', value => { borrowernumber => $patron->id } } ); @@ -46,6 +56,14 @@ subtest 'patron() tests' => sub { is( $request->patron, undef ); + # patron is not expired, is allowed + $patron_module->mock( 'is_expired', sub { return 0; } ); + is( $request->can_patron_place_ill_in_opac($patron), 1 ); + + # patron is expired, is not allowed + $patron_module->mock( 'is_expired', sub { return 1; } ); + is( $request->can_patron_place_ill_in_opac($patron), 0 ); + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t index b0c13d38a6..4bee746332 100755 --- a/t/db_dependent/Koha/Patron/Categories.t +++ b/t/db_dependent/Koha/Patron/Categories.t @@ -103,8 +103,8 @@ subtest 'get_expiry_date' => sub { }; subtest 'BlockExpiredPatronOpacActions' => sub { - plan tests => 3; - t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 'hold'); + plan tests => 4; + t::lib::Mocks::mock_preference( 'BlockExpiredPatronOpacActions', 'hold,ill_request' ); my $category = Koha::Patron::Category->new({ categorycode => 'ya_cat', category_type => 'A', @@ -113,6 +113,7 @@ subtest 'BlockExpiredPatronOpacActions' => sub { BlockExpiredPatronOpacActions => 'follow_syspref_BlockExpiredPatronOpacActions', })->store; is( $category->effective_BlockExpiredPatronOpacActions_contains('hold'), 1 ); + is( $category->effective_BlockExpiredPatronOpacActions_contains('ill_request'), 1 ); is( $category->effective_BlockExpiredPatronOpacActions_contains('renew'), undef ); $category->BlockExpiredPatronOpacActions('renew')->store; is( $category->effective_BlockExpiredPatronOpacActions_contains('renew'), 1 );