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

(-)a/Koha/Schema/Result/Category.pm (-1 / +1 lines)
Lines 403-414 __PACKAGE__->has_many( Link Here
403
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-09-17 17:34:19
403
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-09-17 17:34:19
404
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SZoU95HraPfIzszljOSHyQ
404
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SZoU95HraPfIzszljOSHyQ
405
405
406
407
# You can replace this text with custom code or comments, and it will be preserved on regeneration
406
# You can replace this text with custom code or comments, and it will be preserved on regeneration
408
407
409
sub koha_object_class {
408
sub koha_object_class {
410
    'Koha::Patron::Category';
409
    'Koha::Patron::Category';
411
}
410
}
411
412
sub koha_objects_class {
412
sub koha_objects_class {
413
    'Koha::Patron::Categories';
413
    'Koha::Patron::Categories';
414
}
414
}
(-)a/t/db_dependent/Koha/Patron.t (-63 / +94 lines)
Lines 1355-1393 subtest 'password expiration tests' => sub { Link Here
1355
    plan tests => 5;
1355
    plan tests => 5;
1356
1356
1357
    $schema->storage->txn_begin;
1357
    $schema->storage->txn_begin;
1358
    my $date = dt_from_string();
1358
    my $date     = dt_from_string();
1359
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
1359
    my $category = $builder->build_object(
1360
            password_expiry_days => 10,
1360
        {
1361
            require_strong_password => 0,
1361
            class => 'Koha::Patron::Categories',
1362
            force_password_reset_when_set_by_staff => 0,
1362
            value => {
1363
                password_expiry_days                   => 10,
1364
                require_strong_password                => 0,
1365
                force_password_reset_when_set_by_staff => 0,
1366
            }
1363
        }
1367
        }
1364
    });
1368
    );
1365
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
1369
    my $patron = $builder->build_object(
1366
            categorycode => $category->categorycode,
1370
        {
1367
            password => 'hats'
1371
            class => 'Koha::Patrons',
1372
            value => {
1373
                categorycode => $category->categorycode,
1374
                password     => 'hats'
1375
            }
1368
        }
1376
        }
1369
    });
1377
    );
1370
1378
1371
    $patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron
1379
    $patron->delete()->store()->discard_changes();    # Make sure we are storing a 'new' patron
1372
1380
1373
    is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation");
1381
    is(
1382
        $patron->password_expiration_date(), $date->add( days => 10 )->ymd(),
1383
        "Password expiration date set correctly on patron creation"
1384
    );
1374
1385
1375
    $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
1386
    $patron = $builder->build_object(
1376
            categorycode => $category->categorycode,
1387
        {
1377
            password => undef
1388
            class => 'Koha::Patrons',
1389
            value => {
1390
                categorycode => $category->categorycode,
1391
                password     => undef
1392
            }
1378
        }
1393
        }
1379
    });
1394
    );
1380
    $patron->delete()->store()->discard_changes();
1395
    $patron->delete()->store()->discard_changes();
1381
1396
1382
    is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password");
1397
    is(
1398
        $patron->password_expiration_date(), undef,
1399
        "Password expiration date is not set if patron does not have a password"
1400
    );
1383
1401
1384
    $category->password_expiry_days(undef)->store();
1402
    $category->password_expiry_days(undef)->store();
1385
    $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
1403
    $patron =
1386
            categorycode => $category->categorycode
1404
        $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } );
1387
        }
1388
    });
1389
    $patron->delete()->store()->discard_changes();
1405
    $patron->delete()->store()->discard_changes();
1390
    is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set");
1406
    is(
1407
        $patron->password_expiration_date(), undef,
1408
        "Password expiration date is not set if category does not have expiry days set"
1409
    );
1391
1410
1392
    $schema->storage->txn_rollback;
1411
    $schema->storage->txn_rollback;
1393
1412
Lines 1397-1414 subtest 'password expiration tests' => sub { Link Here
1397
1416
1398
        $schema->storage->txn_begin;
1417
        $schema->storage->txn_begin;
1399
        my $date = dt_from_string();
1418
        my $date = dt_from_string();
1400
        $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
1419
        $patron =
1401
                password_expiration_date => undef
1420
            $builder->build_object( { class => 'Koha::Patrons', value => { password_expiration_date => undef } } );
1402
            }
1421
        is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired" );
1403
        });
1422
        $patron->password_expiration_date($date)->store;
1404
        is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired");
1405
        $patron->password_expiration_date( $date )->store;
1406
        $patron->discard_changes();
1423
        $patron->discard_changes();
1407
        is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired");
1424
        is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired" );
1408
        $date->subtract( days => 1 );
1425
        $date->subtract( days => 1 );
1409
        $patron->password_expiration_date( $date )->store;
1426
        $patron->password_expiration_date($date)->store;
1410
        $patron->discard_changes();
1427
        $patron->discard_changes();
1411
        is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired");
1428
        is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired" );
1412
1429
1413
        $schema->storage->txn_rollback;
1430
        $schema->storage->txn_rollback;
1414
    };
1431
    };
Lines 1420-1445 subtest 'password expiration tests' => sub { Link Here
1420
        $schema->storage->txn_begin;
1437
        $schema->storage->txn_begin;
1421
1438
1422
        my $date = dt_from_string();
1439
        my $date = dt_from_string();
1423
        my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
1440
        my $category =
1424
                password_expiry_days => 10
1441
            $builder->build_object( { class => 'Koha::Patron::Categories', value => { password_expiry_days => 10 } } );
1425
            }
1442
        my $patron = $builder->build_object(
1426
        });
1443
            {
1427
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
1444
                class => 'Koha::Patrons',
1428
                categorycode => $category->categorycode,
1445
                value => {
1429
                password_expiration_date =>  $date->subtract( days => 1 )
1446
                    categorycode             => $category->categorycode,
1447
                    password_expiration_date => $date->subtract( days => 1 )
1448
                }
1430
            }
1449
            }
1431
        });
1450
        );
1432
        is( $patron->password_expired, 1, "Patron password is expired");
1451
        is( $patron->password_expired, 1, "Patron password is expired" );
1433
1452
1434
        $date = dt_from_string();
1453
        $date = dt_from_string();
1435
        $patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes();
1454
        $patron->set_password( { password => "kitten", skip_validation => 1 } )->discard_changes();
1436
        is( $patron->password_expired, 0, "Patron password no longer expired when new password set");
1455
        is( $patron->password_expired, 0, "Patron password no longer expired when new password set" );
1437
        is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation");
1456
        is(
1438
1457
            $patron->password_expiration_date(), $date->add( days => 10 )->ymd(),
1458
            "Password expiration date set correctly on patron creation"
1459
        );
1439
1460
1440
        $category->password_expiry_days( undef )->store();
1461
        $category->password_expiry_days(undef)->store();
1441
        $patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes();
1462
        $patron->set_password( { password => "puppies", skip_validation => 1 } )->discard_changes();
1442
        is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days");
1463
        is(
1464
            $patron->password_expiration_date(), undef,
1465
            "Password expiration date is unset if category does not have expiry days"
1466
        );
1443
1467
1444
        $schema->storage->txn_rollback;
1468
        $schema->storage->txn_rollback;
1445
    };
1469
    };
Lines 1451-1483 subtest 'force_password_reset_when_set_by_staff tests' => sub { Link Here
1451
1475
1452
    $schema->storage->txn_begin;
1476
    $schema->storage->txn_begin;
1453
1477
1454
    my $category = $builder->build_object({
1478
    my $category = $builder->build_object(
1455
        class => 'Koha::Patron::Categories',
1479
        {
1456
        value => {
1480
            class => 'Koha::Patron::Categories',
1457
            force_password_reset_when_set_by_staff => 1,
1481
            value => {
1458
            require_strong_password => 0,
1482
                force_password_reset_when_set_by_staff => 1,
1483
                require_strong_password                => 0,
1484
            }
1459
        }
1485
        }
1460
    });
1486
    );
1461
1487
1462
    my $patron = $builder->build_object({
1488
    my $patron = $builder->build_object(
1463
        class => 'Koha::Patrons',
1489
        {
1464
        value => {
1490
            class => 'Koha::Patrons',
1465
            categorycode => $category->categorycode,
1491
            value => {
1466
            password => 'hats'
1492
                categorycode => $category->categorycode,
1493
                password     => 'hats'
1494
            }
1467
        }
1495
        }
1468
    });
1496
    );
1469
1497
1470
    $patron->delete()->store()->discard_changes();
1498
    $patron->delete()->store()->discard_changes();
1471
    is($patron->password_expired, 1, "Patron forced into changing password, password expired.");
1499
    is( $patron->password_expired, 1, "Patron forced into changing password, password expired." );
1472
1500
1473
    $patron->category->force_password_reset_when_set_by_staff(0)->store();
1501
    $patron->category->force_password_reset_when_set_by_staff(0)->store();
1474
    $patron->delete()->store()->discard_changes();
1502
    $patron->delete()->store()->discard_changes();
1475
    is($patron->password_expired, 0, "Patron not forced into changing password, password not expired.");
1503
    is( $patron->password_expired, 0, "Patron not forced into changing password, password not expired." );
1476
1504
1477
    $patron->category->force_password_reset_when_set_by_staff(1)->store();
1505
    $patron->category->force_password_reset_when_set_by_staff(1)->store();
1478
    t::lib::Mocks::mock_preference('PatronSelfRegistrationDefaultCategory', $patron->categorycode);
1506
    t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $patron->categorycode );
1479
    $patron->delete()->store()->discard_changes();
1507
    $patron->delete()->store()->discard_changes();
1480
    is($patron->password_expired, 0, "Patron forced into changing password but patron is self registered, password not expired.");
1508
    is(
1509
        $patron->password_expired, 0,
1510
        "Patron forced into changing password but patron is self registered, password not expired."
1511
    );
1481
1512
1482
    $schema->storage->txn_rollback;
1513
    $schema->storage->txn_rollback;
1483
};
1514
};
(-)a/t/db_dependent/Koha/Patron/Category.t (-25 / +42 lines)
Lines 212-238 subtest 'effective_force_password_reset_when_set_by_staff() tests' => sub { Link Here
212
212
213
        $schema->storage->txn_begin;
213
        $schema->storage->txn_begin;
214
214
215
        my $category = $builder->build_object({
215
        my $category = $builder->build_object(
216
            class => 'Koha::Patron::Categories',
216
            {
217
            value => {
217
                class => 'Koha::Patron::Categories',
218
                force_password_reset_when_set_by_staff => 1
218
                value => { force_password_reset_when_set_by_staff => 1 }
219
            }
219
            }
220
        });
220
        );
221
221
222
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0);
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');
223
        ok(
224
            $category->effective_force_password_reset_when_set_by_staff,
225
            'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 1'
226
        );
224
227
225
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1);
228
        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');
229
        ok(
230
            $category->effective_force_password_reset_when_set_by_staff,
231
            'ForcePasswordResetWhenSetByStaff set and category has the flag set to 1'
232
        );
227
233
228
        # disable
234
        # disable
229
        $category->force_password_reset_when_set_by_staff(0)->store->discard_changes;
235
        $category->force_password_reset_when_set_by_staff(0)->store->discard_changes;
230
236
231
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0);
237
        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');
238
        ok(
239
            !$category->effective_force_password_reset_when_set_by_staff,
240
            'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 0'
241
        );
233
242
234
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1);
243
        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');
244
        ok(
245
            !$category->effective_force_password_reset_when_set_by_staff,
246
            'ForcePasswordResetWhenSetByStaff set and category has the flag set to 0'
247
        );
236
248
237
        $schema->storage->txn_rollback;
249
        $schema->storage->txn_rollback;
238
    };
250
    };
Lines 242-259 subtest 'effective_force_password_reset_when_set_by_staff() tests' => sub { Link Here
242
254
243
        $schema->storage->txn_begin;
255
        $schema->storage->txn_begin;
244
256
245
        my $category = $builder->build_object({
257
        my $category = $builder->build_object(
246
            class => 'Koha::Patron::Categories',
258
            {
247
            value => {
259
                class => 'Koha::Patron::Categories',
248
                force_password_reset_when_set_by_staff => undef
260
                value => { force_password_reset_when_set_by_staff => undef }
249
            }
261
            }
250
        });
262
        );
251
263
252
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0);
264
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 );
253
        ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 0 used');
265
        ok(
254
266
            !$category->effective_force_password_reset_when_set_by_staff,
255
        t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1);
267
            'ForcePasswordResetWhenSetByStaff set to 0 used'
256
        ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 1 used');
268
        );
269
270
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 );
271
        ok(
272
            $category->effective_force_password_reset_when_set_by_staff,
273
            'ForcePasswordResetWhenSetByStaff set to 1 used'
274
        );
257
275
258
        $schema->storage->txn_rollback;
276
        $schema->storage->txn_rollback;
259
    };
277
    };
260
- 

Return to bug 33462