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

(-)a/t/db_dependent/Koha/Patron.t (+37 lines)
Lines 1359-1364 subtest 'password expiration tests' => sub { Link Here
1359
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
1359
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
1360
            password_expiry_days => 10,
1360
            password_expiry_days => 10,
1361
            require_strong_password => 0,
1361
            require_strong_password => 0,
1362
            force_password_reset_when_set_by_staff => 0,
1362
        }
1363
        }
1363
    });
1364
    });
1364
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
1365
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
Lines 1445-1450 subtest 'password expiration tests' => sub { Link Here
1445
1446
1446
};
1447
};
1447
1448
1449
subtest 'force_password_reset_when_set_by_staff tests' => sub {
1450
    plan tests => 3;
1451
1452
    $schema->storage->txn_begin;
1453
1454
    my $category = $builder->build_object({
1455
        class => 'Koha::Patron::Categories',
1456
        value => {
1457
            force_password_reset_when_set_by_staff => 1,
1458
            require_strong_password => 0,
1459
        }
1460
    });
1461
1462
    my $patron = $builder->build_object({
1463
        class => 'Koha::Patrons',
1464
        value => {
1465
            categorycode => $category->categorycode,
1466
            password => 'hats'
1467
        }
1468
    });
1469
1470
    $patron->delete()->store()->discard_changes();
1471
    is($patron->password_expired, 1, "Patron forced into changing password, password expired.");
1472
1473
    $patron->category->force_password_reset_when_set_by_staff(0)->store();
1474
    $patron->delete()->store()->discard_changes();
1475
    is($patron->password_expired, 0, "Patron not forced into changing password, password not expired.");
1476
1477
    $patron->category->force_password_reset_when_set_by_staff(1)->store();
1478
    t::lib::Mocks::mock_preference('PatronSelfRegistrationDefaultCategory', $patron->categorycode);
1479
    $patron->delete()->store()->discard_changes();
1480
    is($patron->password_expired, 0, "Patron forced into changing password but patron is self registered, password not expired.");
1481
1482
    $schema->storage->txn_rollback;
1483
};
1484
1448
subtest 'safe_to_delete() tests' => sub {
1485
subtest 'safe_to_delete() tests' => sub {
1449
1486
1450
    plan tests => 17;
1487
    plan tests => 17;
(-)a/t/db_dependent/Koha/Patron/Category.t (-2 / +57 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 204-209 subtest 'effective_require_strong_password' => sub { Link Here
204
  $schema->storage->txn_rollback;
204
  $schema->storage->txn_rollback;
205
};
205
};
206
206
207
subtest 'effective_force_password_reset_when_set_by_staff() tests' => sub {
208
    plan tests => 2;
209
210
    subtest 'specific overrides global' => sub {
211
        plan tests => 4;
212
213
        $schema->storage->txn_begin;
214
215
        my $category = $builder->build_object({
216
            class => 'Koha::Patron::Categories',
217
            value => {
218
                force_password_reset_when_set_by_staff => 1
219
            }
220
        });
221
222
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0);
223
        ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 1');
224
225
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1);
226
        ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 1');
227
228
        # disable
229
        $category->force_password_reset_when_set_by_staff(0)->store->discard_changes;
230
231
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0);
232
        ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 0');
233
234
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1);
235
        ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 0');
236
237
        $schema->storage->txn_rollback;
238
    };
239
240
    subtest 'no specific rule, global applies' => sub {
241
        plan tests => 2;
242
243
        $schema->storage->txn_begin;
244
245
        my $category = $builder->build_object({
246
            class => 'Koha::Patron::Categories',
247
            value => {
248
                force_password_reset_when_set_by_staff => undef
249
            }
250
        });
251
252
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0);
253
        ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 0 used');
254
255
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1);
256
        ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 1 used');
257
258
        $schema->storage->txn_rollback;
259
    };
260
};
261
262
207
subtest 'get_password_expiry_date() tests' => sub {
263
subtest 'get_password_expiry_date() tests' => sub {
208
264
209
    plan tests => 3;
265
    plan tests => 3;
210
- 

Return to bug 33462