Bug 31333: (QA follow-up) Move and improve tests

This patch moves tests to the right file (singular class name). It also
refactors them a bit, in order to cover more cases, including the
syspref split one.

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Patron/Category.t \
           t/db_dependent/Koha/Patron/Categories.t
=> SUCCESS: All good.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2022-10-05 11:53:46 -03:00
parent 555c55e8ca
commit d08cd5965d
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 52 additions and 27 deletions

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 11;
use Test::More tests => 10;
use C4::Context;
use Koha::Database;
@ -115,30 +115,5 @@ 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;

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 6;
use Test::More tests => 7;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -219,3 +219,53 @@ subtest 'get_password_expiry_date() tests' => sub {
is( $category->get_password_expiry_date(), dt_from_string()->add( days => 32 )->ymd, "Date correctly calculated from password_expiry_days when set");
};
subtest 'can_make_suggestions' => sub {
plan tests => 6;
$schema->storage->txn_begin;
t::lib::Mocks::mock_preference( 'suggestion', 0 );
t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', undef );
my $category_1 = $builder->build_object({ class => 'Koha::Patron::Categories' });
my $category_2 = $builder->build_object({ class => 'Koha::Patron::Categories' });
ok(
!$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
'suggestions globally disabled, categories not in exceptions'
);
t::lib::Mocks::mock_preference( 'suggestion', 1 );
ok(
$category_1->can_make_suggestions && $category_2->can_make_suggestions,
'suggestions globally enabled'
);
t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', $category_2->categorycode );
ok(
$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
'suggestions enabled, suggestionPatronCategoryExceptions set, so present categories not allowed'
);
t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', $category_1->categorycode );
ok(
!$category_1->can_make_suggestions && $category_2->can_make_suggestions,
'suggestions enabled, suggestionPatronCategoryExceptions set, so present categories not allowed'
);
t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', join( ',', $category_1->categorycode, $category_2->categorycode) );
ok(
!$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
'suggestions enabled, suggestionPatronCategoryExceptions set to both categories, both denied'
);
t::lib::Mocks::mock_preference( 'suggestion', 0 );
ok(
!$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
'suggestions disabled, no matter what the value of suggestionPatronCategoryExceptions is'
);
$schema->storage->txn_rollback;
};