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