View | Details | Raw Unified | Return to bug 31333
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patron/Categories.t (-26 / +1 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 11;
22
use Test::More tests => 10;
23
23
24
use C4::Context;
24
use C4::Context;
25
use Koha::Database;
25
use Koha::Database;
Lines 115-144 my $new_category_4 = Koha::Patron::Category->new( Link Here
115
)->store;
115
)->store;
116
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'upperagelimit and dateofbirthrequired should have a default value if empty string is passed' );
116
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'upperagelimit and dateofbirthrequired should have a default value if empty string is passed' );
117
117
118
subtest 'can_make_suggestions' => sub {
119
    plan tests => 5;
120
    t::lib::Mocks::mock_preference('suggestion', 0);
121
    my $category = Koha::Patron::Category->new({
122
        categorycode => 'the_cat',
123
        category_type => 'A',
124
        description => 'thecatdesc',
125
        enrolementperiod => undef
126
    })->store;
127
    is ( $category->can_make_suggestions, undef, 'With suggestion syspref disabled and suggestionPatronCategoryExceptions syspref empty then Koha::Patron::Category->can_make_suggestions() returns undef' );
128
129
    t::lib::Mocks::mock_preference('suggestion', 1);
130
    is( $category->can_make_suggestions, 1, 'With suggestion syspref enabled and suggestionPatronsCategoryExceptions syspref empty then Koha::Patron::Category->can_make_suggestions() returns 1' );
131
132
    t::lib::Mocks::mock_preference('suggestionPatronCategoryExceptions', 'the_cat');
133
    is( $category->can_make_suggestions, undef, 'With suggestion syspref enabled and suggestionPatronCategoryExceptions syspref = "the_cat" then Koha::Patron::Category->can_make_suggestions() returns undef' );
134
135
    t::lib::Mocks::mock_preference('suggestionPatronCategoryExceptions', 'mycatcodeW');
136
    is( $category->can_make_suggestions, 1, 'With suggestion syspref enabled and suggestionPatronCategoryExceptions syspref = "mycatcodeW" then Koha::Patron::Category->can_make_suggestions returns 1' );
137
138
    t::lib::Mocks::mock_preference('suggestion', 0);
139
    is( $category->can_make_suggestions, undef, 'With suggestion syspref disabled and suggestionPatronCategoryExceptions syspref = "mycatcodeW" then Koha::Patron::Category->can_make_suggestions returns undef' );
140
    $category->delete;
141
};
142
143
$schema->storage->txn_rollback;
118
$schema->storage->txn_rollback;
144
119
(-)a/t/db_dependent/Koha/Patron/Category.t (-2 / +51 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 219-221 subtest 'get_password_expiry_date() tests' => sub { Link Here
219
    is( $category->get_password_expiry_date(), dt_from_string()->add( days => 32 )->ymd, "Date correctly calculated from password_expiry_days when set");
219
    is( $category->get_password_expiry_date(), dt_from_string()->add( days => 32 )->ymd, "Date correctly calculated from password_expiry_days when set");
220
220
221
};
221
};
222
- 
222
223
subtest 'can_make_suggestions' => sub {
224
225
    plan tests => 6;
226
227
    $schema->storage->txn_begin;
228
229
    t::lib::Mocks::mock_preference( 'suggestion', 0 );
230
    t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', undef );
231
232
    my $category_1 = $builder->build_object({ class => 'Koha::Patron::Categories' });
233
    my $category_2 = $builder->build_object({ class => 'Koha::Patron::Categories' });
234
235
    ok(
236
        !$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
237
        'suggestions globally disabled, categories not in exceptions'
238
    );
239
240
    t::lib::Mocks::mock_preference( 'suggestion', 1 );
241
    ok(
242
        $category_1->can_make_suggestions && $category_2->can_make_suggestions,
243
        'suggestions globally enabled'
244
    );
245
246
    t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', $category_2->categorycode );
247
    ok(
248
        $category_1->can_make_suggestions && !$category_2->can_make_suggestions,
249
        'suggestions enabled, suggestionPatronCategoryExceptions set, so present categories not allowed'
250
    );
251
252
    t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', $category_1->categorycode );
253
    ok(
254
        !$category_1->can_make_suggestions && $category_2->can_make_suggestions,
255
        'suggestions enabled, suggestionPatronCategoryExceptions set, so present categories not allowed'
256
    );
257
258
    t::lib::Mocks::mock_preference( 'suggestionPatronCategoryExceptions', join( ',', $category_1->categorycode, $category_2->categorycode) );
259
    ok(
260
        !$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
261
        'suggestions enabled, suggestionPatronCategoryExceptions set to both categories, both denied'
262
    );
263
264
    t::lib::Mocks::mock_preference( 'suggestion', 0 );
265
    ok(
266
        !$category_1->can_make_suggestions && !$category_2->can_make_suggestions,
267
        'suggestions disabled, no matter what the value of suggestionPatronCategoryExceptions is'
268
    );
269
270
    $schema->storage->txn_rollback;
271
};

Return to bug 31333