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

(-)a/t/db_dependent/Koha/Patron.t (-2 / +39 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 24;
22
use Test::More tests => 25;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 30-36 use Koha::ArticleRequests; Link Here
30
use Koha::Patrons;
30
use Koha::Patrons;
31
use Koha::Patron::Relationships;
31
use Koha::Patron::Relationships;
32
use C4::Circulation qw( AddIssue AddReturn );
32
use C4::Circulation qw( AddIssue AddReturn );
33
34
use t::lib::TestBuilder;
33
use t::lib::TestBuilder;
35
use t::lib::Mocks;
34
use t::lib::Mocks;
36
35
Lines 975-980 subtest 'password expiration tests' => sub { Link Here
975
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
974
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
976
            password_expiry_days => 10,
975
            password_expiry_days => 10,
977
            require_strong_password => 0,
976
            require_strong_password => 0,
977
            force_password_reset_when_set_by_staff => 0,
978
        }
978
        }
979
    });
979
    });
980
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
980
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
Lines 1061-1066 subtest 'password expiration tests' => sub { Link Here
1061
1061
1062
};
1062
};
1063
1063
1064
subtest 'force_password_reset_when_set_by_staff tests' => sub {
1065
1066
    plan tests => 3;
1067
1068
    $schema->storage->txn_begin;
1069
1070
    my $category = $builder->build_object({
1071
        class => 'Koha::Patron::Categories',
1072
        value => {
1073
            force_password_reset_when_set_by_staff => 1,
1074
            require_strong_password => 0,
1075
        }
1076
    });
1077
1078
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
1079
        categorycode => $category->categorycode,
1080
        password => 'hats'
1081
    }
1082
    });
1083
1084
    $patron->delete()->store()->discard_changes();
1085
    is( $patron->password_expired, 1, "Patron forced into changing password, password expired.");
1086
1087
    $patron->category->force_password_reset_when_set_by_staff(0)->store();
1088
    $patron->delete()->store()->discard_changes();
1089
    is( $patron->password_expired, 0, "Patron not forced into changing password, password not expired.");
1090
1091
    $patron->category->force_password_reset_when_set_by_staff(1)->store();
1092
    t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $patron->categorycode );
1093
    $patron->delete()->store()->discard_changes();
1094
    is( $patron->password_expired, 0, "Patron forced into changing password but patron is self registered, password not expired.");
1095
1096
1097
    $schema->storage->txn_rollback;
1098
1099
};
1100
1064
subtest 'safe_to_delete() tests' => sub {
1101
subtest 'safe_to_delete() tests' => sub {
1065
1102
1066
    plan tests => 14;
1103
    plan tests => 14;
(-)a/t/db_dependent/Koha/Patron/Category.t (-2 / +59 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
209
    plan tests => 2;
210
211
    subtest 'specific overrides global' => sub {
212
213
        plan tests => 4;
214
215
        $schema->storage->txn_begin;
216
217
        my $category = $builder->build_object({
218
            class => 'Koha::Patron::Categories',
219
            value => {
220
                force_password_reset_when_set_by_staff => 1
221
            }
222
        });
223
224
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 );
225
        ok( $category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 1' );
226
227
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 );
228
        ok( $category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 1' );
229
230
        # disable
231
        $category->force_password_reset_when_set_by_staff( 0 )->store->discard_changes;
232
233
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 );
234
        ok( !$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 0' );
235
236
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 );
237
        ok( !$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 0' );
238
239
        $schema->storage->txn_rollback;
240
    };
241
242
    subtest 'no specific rule, global applies' => sub {
243
244
        plan tests => 2;
245
246
        $schema->storage->txn_begin;
247
248
        my $category = $builder->build_object({
249
            class => 'Koha::Patron::Categories',
250
            value => {
251
                force_password_reset_when_set_by_staff => undef
252
            }
253
        });
254
255
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 );
256
        ok( !$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 0 used' );
257
258
        t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 );
259
        ok( $category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 1 used' );
260
261
        $schema->storage->txn_rollback;
262
    };
263
};
264
207
subtest 'get_password_expiry_date() tests' => sub {
265
subtest 'get_password_expiry_date() tests' => sub {
208
266
209
    plan tests => 2;
267
    plan tests => 2;
210
- 

Return to bug 33462