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

(-)a/t/db_dependent/Koha/Patron.t (-1 / +94 lines)
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;
(-)a/t/db_dependent/Koha/Patron/Category.t (-2 / +18 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
29
29
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
Lines 202-204 subtest 'effective_require_strong_password' => sub { Link Here
202
203
203
  $schema->storage->txn_rollback;
204
  $schema->storage->txn_rollback;
204
};
205
};
205
- 
206
207
subtest 'get_password_expiry_date() tests' => sub {
208
209
    plan tests => 2;
210
211
    $schema->storage->txn_begin;
212
213
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
214
    $category->password_expiry_days( undef )->store;
215
216
    is( $category->get_password_expiry_date(), undef, "No date returned if expiry days undef" );
217
218
    $category->password_expiry_days( 32 )->store;
219
    is( $category->get_password_expiry_date(), dt_from_string()->add( days => 32 )->ymd, "Date correctly calculated from password_expiry_days when set");
220
221
};

Return to bug 29924