|
Lines 852-857
subtest 'article_requests() tests' => sub {
Link Here
|
| 852 |
$schema->storage->txn_rollback; |
852 |
$schema->storage->txn_rollback; |
| 853 |
}; |
853 |
}; |
| 854 |
|
854 |
|
|
|
855 |
subtest 'password expiration tests' => sub { |
| 856 |
|
| 857 |
plan tests => 5; |
| 858 |
|
| 859 |
$schema->storage->txn_begin; |
| 860 |
my $date = dt_from_string(); |
| 861 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { |
| 862 |
password_expiry_days => 10, |
| 863 |
require_strong_password => 0, |
| 864 |
} |
| 865 |
}); |
| 866 |
my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => { |
| 867 |
categorycode => $category->categorycode, |
| 868 |
password => 'hats' |
| 869 |
} |
| 870 |
}); |
| 871 |
|
| 872 |
$patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron |
| 873 |
|
| 874 |
is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation"); |
| 875 |
|
| 876 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 877 |
categorycode => $category->categorycode, |
| 878 |
password => undef |
| 879 |
} |
| 880 |
}); |
| 881 |
$patron->delete()->store()->discard_changes(); |
| 882 |
|
| 883 |
is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password"); |
| 884 |
|
| 885 |
$category->password_expiry_days(undef)->store(); |
| 886 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 887 |
categorycode => $category->categorycode |
| 888 |
} |
| 889 |
}); |
| 890 |
$patron->delete()->store()->discard_changes(); |
| 891 |
is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set"); |
| 892 |
|
| 893 |
$schema->storage->txn_rollback; |
| 894 |
|
| 895 |
subtest 'password_expired' => sub { |
| 896 |
|
| 897 |
plan tests => 3; |
| 898 |
|
| 899 |
$schema->storage->txn_begin; |
| 900 |
my $date = dt_from_string(); |
| 901 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 902 |
password_expiration_date => undef |
| 903 |
} |
| 904 |
}); |
| 905 |
is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired"); |
| 906 |
$patron->password_expiration_date( $date )->store; |
| 907 |
$patron->discard_changes(); |
| 908 |
is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired"); |
| 909 |
$date->subtract( days => 1 ); |
| 910 |
$patron->password_expiration_date( $date )->store; |
| 911 |
$patron->discard_changes(); |
| 912 |
is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired"); |
| 913 |
|
| 914 |
$schema->storage->txn_rollback; |
| 915 |
}; |
| 916 |
|
| 917 |
subtest 'set_password' => sub { |
| 918 |
|
| 919 |
plan tests => 4; |
| 920 |
|
| 921 |
$schema->storage->txn_begin; |
| 922 |
|
| 923 |
my $date = dt_from_string(); |
| 924 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { |
| 925 |
password_expiry_days => 10 |
| 926 |
} |
| 927 |
}); |
| 928 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
| 929 |
categorycode => $category->categorycode, |
| 930 |
password_expiration_date => $date->subtract( days => 1 ) |
| 931 |
} |
| 932 |
}); |
| 933 |
is( $patron->password_expired, 1, "Patron password is expired"); |
| 934 |
|
| 935 |
$date = dt_from_string(); |
| 936 |
$patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes(); |
| 937 |
is( $patron->password_expired, 0, "Patron password no longer expired when new password set"); |
| 938 |
is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation"); |
| 939 |
|
| 940 |
|
| 941 |
$category->password_expiry_days( undef )->store(); |
| 942 |
$patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes(); |
| 943 |
is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days"); |
| 944 |
|
| 945 |
$schema->storage->txn_rollback; |
| 946 |
}; |
| 947 |
|
| 948 |
}; |
| 949 |
|
| 855 |
subtest 'safe_to_delete() tests' => sub { |
950 |
subtest 'safe_to_delete() tests' => sub { |
| 856 |
|
951 |
|
| 857 |
plan tests => 14; |
952 |
plan tests => 14; |