Lines 22-28
use C4::Letters;
Link Here
|
22 |
use Koha::Database; |
22 |
use Koha::Database; |
23 |
use Koha::Patrons; |
23 |
use Koha::Patrons; |
24 |
|
24 |
|
25 |
use Test::More tests => 16; |
25 |
use Test::More tests => 18; |
26 |
|
26 |
|
27 |
use_ok('Koha::Patron::Password::Recovery'); |
27 |
use_ok('Koha::Patron::Password::Recovery'); |
28 |
|
28 |
|
Lines 38-49
$dbh->{RaiseError} = 1;
Link Here
|
38 |
|
38 |
|
39 |
my $borrowernumber1 = '2000000000'; |
39 |
my $borrowernumber1 = '2000000000'; |
40 |
my $borrowernumber2 = '2000000001'; |
40 |
my $borrowernumber2 = '2000000001'; |
|
|
41 |
my $borrowernumber3 = '2000000002'; |
41 |
my $userid1 = "I83MFItzRpGPxD3vW0"; |
42 |
my $userid1 = "I83MFItzRpGPxD3vW0"; |
42 |
my $userid2 = "Gh5t43980hfSAOcvne"; |
43 |
my $userid2 = "Gh5t43980hfSAOcvne"; |
|
|
44 |
my $userid3 = "adsfada80hfSAOcvne"; |
43 |
my $email1 = $userid1 . '@koha-community.org'; |
45 |
my $email1 = $userid1 . '@koha-community.org'; |
44 |
my $email2 = $userid2 . '@koha-community.org'; |
46 |
my $email2 = $userid2 . '@koha-community.org'; |
|
|
47 |
my $email3 = $userid3 . '@koha-community.org'; |
45 |
my $uuid1 = "ABCD1234"; |
48 |
my $uuid1 = "ABCD1234"; |
46 |
my $uuid2 = "WXYZ0987"; |
49 |
my $uuid2 = "WXYZ0987"; |
|
|
50 |
my $uuid3 = "LMNO4561"; |
47 |
|
51 |
|
48 |
my $categorycode = 'S'; # staff |
52 |
my $categorycode = 'S'; # staff |
49 |
my $branch = $schema->resultset('Branch')->first(); # legit branch from your db |
53 |
my $branch = $schema->resultset('Branch')->first(); # legit branch from your db |
Lines 74-79
$schema->resultset('Borrower')->create(
Link Here
|
74 |
branchcode => $branch, |
78 |
branchcode => $branch, |
75 |
} |
79 |
} |
76 |
); |
80 |
); |
|
|
81 |
$schema->resultset('Borrower')->create( |
82 |
{ |
83 |
borrowernumber => $borrowernumber3, |
84 |
surname => '', |
85 |
address => '', |
86 |
city => '', |
87 |
userid => $userid3, |
88 |
email => $email3, |
89 |
categorycode => $categorycode, |
90 |
branchcode => $branch, |
91 |
} |
92 |
); |
77 |
|
93 |
|
78 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
94 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
79 |
{ |
95 |
{ |
Lines 89-94
$schema->resultset('BorrowerPasswordRecovery')->create(
Link Here
|
89 |
valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 2 )->datetime() |
105 |
valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 2 )->datetime() |
90 |
} |
106 |
} |
91 |
); |
107 |
); |
|
|
108 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
109 |
{ |
110 |
borrowernumber => $borrowernumber3, |
111 |
uuid => $uuid3, |
112 |
valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 3 )->datetime() |
113 |
} |
114 |
); |
115 |
|
92 |
|
116 |
|
93 |
can_ok( "Koha::Patron::Password::Recovery", qw(ValidateBorrowernumber GetValidLinkInfo SendPasswordRecoveryEmail CompletePasswordRecovery) ); |
117 |
can_ok( "Koha::Patron::Password::Recovery", qw(ValidateBorrowernumber GetValidLinkInfo SendPasswordRecoveryEmail CompletePasswordRecovery) ); |
94 |
|
118 |
|
Lines 117-123
ok( ! defined($bnum3), "[GetValidLinkInfo] Invalid UUID returns no borrowernumbe
Link Here
|
117 |
# Koha::Patron::Password::Recovery::CompletePasswordRecovery # |
141 |
# Koha::Patron::Password::Recovery::CompletePasswordRecovery # |
118 |
############################################################## |
142 |
############################################################## |
119 |
|
143 |
|
120 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid1) == 2, "[CompletePasswordRecovery] Completing a password recovery deletes the entry and expired entries" ); |
144 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid1) == 2, "[CompletePasswordRecovery] Completing a password recovery deletes the used entry" ); |
121 |
|
145 |
|
122 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
146 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
123 |
{ |
147 |
{ |
Lines 130-135
$schema->resultset('BorrowerPasswordRecovery')->create(
Link Here
|
130 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 1, "[CompletePasswordRecovery] An expired or invalid UUID purges expired entries" ); |
154 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 1, "[CompletePasswordRecovery] An expired or invalid UUID purges expired entries" ); |
131 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 0, "[CompletePasswordRecovery] Returns 0 on a clean table" ); |
155 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 0, "[CompletePasswordRecovery] Returns 0 on a clean table" ); |
132 |
|
156 |
|
|
|
157 |
################################################################### |
158 |
# Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery # |
159 |
################################################################### |
160 |
|
161 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
162 |
{ |
163 |
borrowernumber => $borrowernumber3, |
164 |
uuid => $uuid3, |
165 |
valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 3 )->datetime() |
166 |
} |
167 |
); |
168 |
|
169 |
ok( Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery($borrowernumber3) == 1, "[DeleteExpiredPasswordRecovery] we can delete the unused entry" ); |
170 |
ok( Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery($borrowernumber3) == 0, "[DeleteExpiredPasswordRecovery] Returns 0 on a clean table" ); |
171 |
|
133 |
############################################################### |
172 |
############################################################### |
134 |
# Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail # |
173 |
# Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail # |
135 |
############################################################### |
174 |
############################################################### |
136 |
- |
|
|