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