From 1b37924220654dc829f58bbfa8aa071c4beadba2 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 15 Aug 2022 06:39:23 +0000 Subject: [PATCH] Bug 31333: Unit tests Test plan: 1. Run tests (Categories.t has been updated by me, and I suggest running Suggestions.t to confirm it still passes): sudo koha-shell kohadev prove t/db_dependent/Koha/Patron/Categories.t prove t/db_dependent/Koha/Suggestions.t Sponsored-by: Catalyst IT, New Zealand Signed-off-by: Rhonda Kuiper --- t/db_dependent/Koha/Patron/Categories.t | 27 ++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t index f6cdba7e24..6be30bb82a 100755 --- a/t/db_dependent/Koha/Patron/Categories.t +++ b/t/db_dependent/Koha/Patron/Categories.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use C4::Context; use Koha::Database; @@ -115,5 +115,30 @@ my $new_category_4 = Koha::Patron::Category->new( )->store; is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'upperagelimit and dateofbirthrequired should have a default value if empty string is passed' ); +subtest 'can_make_suggestions' => sub { + plan tests => 5; + t::lib::Mocks::mock_preference('suggestion', 0); + my $category = Koha::Patron::Category->new({ + categorycode => 'the_cat', + category_type => 'A', + description => 'thecatdesc', + enrolementperiod => undef + })->store; + is ( $category->can_make_suggestions, undef, 'With suggestion syspref disabled and suggestionPatronCategoryExceptions syspref empty then Koha::Patron::Category->can_make_suggestions() returns undef' ); + + t::lib::Mocks::mock_preference('suggestion', 1); + is( $category->can_make_suggestions, 1, 'With suggestion syspref enabled and suggestionPatronsCategoryExceptions syspref empty then Koha::Patron::Category->can_make_suggestions() returns 1' ); + + t::lib::Mocks::mock_preference('suggestionPatronCategoryExceptions', 'the_cat'); + is( $category->can_make_suggestions, undef, 'With suggestion syspref enabled and suggestionPatronCategoryExceptions syspref = "the_cat" then Koha::Patron::Category->can_make_suggestions() returns undef' ); + + t::lib::Mocks::mock_preference('suggestionPatronCategoryExceptions', 'mycatcodeW'); + is( $category->can_make_suggestions, 1, 'With suggestion syspref enabled and suggestionPatronCategoryExceptions syspref = "mycatcodeW" then Koha::Patron::Category->can_make_suggestions returns 1' ); + + t::lib::Mocks::mock_preference('suggestion', 0); + is( $category->can_make_suggestions, undef, 'With suggestion syspref disabled and suggestionPatronCategoryExceptions syspref = "mycatcodeW" then Koha::Patron::Category->can_make_suggestions returns undef' ); + $category->delete; +}; + $schema->storage->txn_rollback; -- 2.30.2