|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 16; |
22 |
use Test::More tests => 17; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 882-887
subtest 'can_patron_change_staff_only_lists() tests' => sub {
Link Here
|
| 882 |
$schema->storage->txn_rollback; |
882 |
$schema->storage->txn_rollback; |
| 883 |
}; |
883 |
}; |
| 884 |
|
884 |
|
|
|
885 |
subtest 'password expiration tests' => sub { |
| 886 |
|
| 887 |
plan tests => 5; |
| 888 |
|
| 889 |
$schema->storage->txn_begin; |
| 890 |
my $date = dt_from_string(); |
| 891 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { |
| 892 |
password_expiry_days => 10, |
| 893 |
require_strong_password => 0, |
| 894 |
} |
| 895 |
}); |
| 896 |
my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => { |
| 897 |
categorycode => $category->categorycode, |
| 898 |
password => 'hats' |
| 899 |
} |
| 900 |
}); |
| 901 |
|
| 902 |
$patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron |
| 903 |
|
| 904 |
is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation"); |
| 905 |
|
| 906 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 907 |
categorycode => $category->categorycode, |
| 908 |
password => undef |
| 909 |
} |
| 910 |
}); |
| 911 |
$patron->delete()->store()->discard_changes(); |
| 912 |
|
| 913 |
is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password"); |
| 914 |
|
| 915 |
$category->password_expiry_days(undef)->store(); |
| 916 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 917 |
categorycode => $category->categorycode |
| 918 |
} |
| 919 |
}); |
| 920 |
$patron->delete()->store()->discard_changes(); |
| 921 |
is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set"); |
| 922 |
|
| 923 |
$schema->storage->txn_rollback; |
| 924 |
|
| 925 |
subtest 'password_expired' => sub { |
| 926 |
|
| 927 |
plan tests => 3; |
| 928 |
|
| 929 |
$schema->storage->txn_begin; |
| 930 |
my $date = dt_from_string(); |
| 931 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 932 |
password_expiration_date => undef |
| 933 |
} |
| 934 |
}); |
| 935 |
is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired"); |
| 936 |
$patron->password_expiration_date( $date )->store; |
| 937 |
$patron->discard_changes(); |
| 938 |
is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired"); |
| 939 |
$date->subtract( days => 1 ); |
| 940 |
$patron->password_expiration_date( $date )->store; |
| 941 |
$patron->discard_changes(); |
| 942 |
is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired"); |
| 943 |
|
| 944 |
$schema->storage->txn_rollback; |
| 945 |
}; |
| 946 |
|
| 947 |
subtest 'set_password' => sub { |
| 948 |
|
| 949 |
plan tests => 4; |
| 950 |
|
| 951 |
$schema->storage->txn_begin; |
| 952 |
|
| 953 |
my $date = dt_from_string(); |
| 954 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { |
| 955 |
password_expiry_days => 10 |
| 956 |
} |
| 957 |
}); |
| 958 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 959 |
categorycode => $category->categorycode, |
| 960 |
password_expiration_date => $date->subtract( days => 1 ) |
| 961 |
} |
| 962 |
}); |
| 963 |
is( $patron->password_expired, 1, "Patron password is expired"); |
| 964 |
|
| 965 |
$date = dt_from_string(); |
| 966 |
$patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes(); |
| 967 |
is( $patron->password_expired, 0, "Patron password no longer expired when new password set"); |
| 968 |
is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation"); |
| 969 |
|
| 970 |
|
| 971 |
$category->password_expiry_days( undef )->store(); |
| 972 |
$patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes(); |
| 973 |
is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days"); |
| 974 |
|
| 975 |
$schema->storage->txn_rollback; |
| 976 |
}; |
| 977 |
|
| 978 |
}; |
| 979 |
|
| 885 |
subtest 'safe_to_delete() tests' => sub { |
980 |
subtest 'safe_to_delete() tests' => sub { |
| 886 |
|
981 |
|
| 887 |
plan tests => 14; |
982 |
plan tests => 14; |