|
Lines 24-30
use Koha::Borrowers;
Link Here
|
| 24 |
|
24 |
|
| 25 |
use Test::More tests => 16; |
25 |
use Test::More tests => 16; |
| 26 |
|
26 |
|
| 27 |
use_ok('C4::Passwordrecovery'); |
27 |
use_ok('Koha::Patron::Password::Recovery'); |
| 28 |
|
28 |
|
| 29 |
my $schema = Koha::Database->new()->schema(); |
29 |
my $schema = Koha::Database->new()->schema(); |
| 30 |
$schema->storage->txn_begin(); |
30 |
$schema->storage->txn_begin(); |
|
Lines 90-123
$schema->resultset('BorrowerPasswordRecovery')->create(
Link Here
|
| 90 |
} |
90 |
} |
| 91 |
); |
91 |
); |
| 92 |
|
92 |
|
| 93 |
can_ok( "C4::Passwordrecovery", qw(ValidateBorrowernumber GetValidLinkInfo SendPasswordRecoveryEmail CompletePasswordRecovery) ); |
93 |
can_ok( "Koha::Patron::Password::Recovery", qw(ValidateBorrowernumber GetValidLinkInfo SendPasswordRecoveryEmail CompletePasswordRecovery) ); |
| 94 |
|
94 |
|
| 95 |
################################################ |
95 |
############################################################ |
| 96 |
# C4::Passwordrecovery::ValidateBorrowernumber # |
96 |
# Koha::Patron::Password::Recovery::ValidateBorrowernumber # |
| 97 |
################################################ |
97 |
############################################################ |
| 98 |
|
98 |
|
| 99 |
ok( C4::Passwordrecovery::ValidateBorrowernumber($borrowernumber1), "[ValidateBorrowernumber] Borrower has a password recovery entry" ); |
99 |
ok( Koha::Patron::Password::Recovery::ValidateBorrowernumber($borrowernumber1), "[ValidateBorrowernumber] Borrower has a password recovery entry" ); |
| 100 |
ok( ! C4::Passwordrecovery::ValidateBorrowernumber($borrowernumber2), "[ValidateBorrowernumber] Borrower's number is not found; password recovery entry is expired" ); |
100 |
ok( ! Koha::Patron::Password::Recovery::ValidateBorrowernumber($borrowernumber2), "[ValidateBorrowernumber] Borrower's number is not found; password recovery entry is expired" ); |
| 101 |
ok( ! C4::Passwordrecovery::ValidateBorrowernumber(9999), "[ValidateBorrowernumber] Borrower has no password recovery entry" ); |
101 |
ok( ! Koha::Patron::Password::Recovery::ValidateBorrowernumber(9999), "[ValidateBorrowernumber] Borrower has no password recovery entry" ); |
| 102 |
|
102 |
|
| 103 |
########################################## |
103 |
###################################################### |
| 104 |
# C4::Passwordrecovery::GetValidLinkInfo # |
104 |
# Koha::Patron::Password::Recovery::GetValidLinkInfo # |
| 105 |
########################################## |
105 |
###################################################### |
| 106 |
|
106 |
|
| 107 |
my ($bnum1, $uname1) = C4::Passwordrecovery::GetValidLinkInfo($uuid1); |
107 |
my ($bnum1, $uname1) = Koha::Patron::Password::Recovery::GetValidLinkInfo($uuid1); |
| 108 |
my ($bnum2, $uname2) = C4::Passwordrecovery::GetValidLinkInfo($uuid2); |
108 |
my ($bnum2, $uname2) = Koha::Patron::Password::Recovery::GetValidLinkInfo($uuid2); |
| 109 |
my ($bnum3, $uname3) = C4::Passwordrecovery::GetValidLinkInfo("THISISANINVALIDUUID"); |
109 |
my ($bnum3, $uname3) = Koha::Patron::Password::Recovery::GetValidLinkInfo("THISISANINVALIDUUID"); |
| 110 |
|
110 |
|
| 111 |
is( $bnum1, $borrowernumber1, "[GetValidLinkInfo] Borrower has a valid link" ); |
111 |
is( $bnum1, $borrowernumber1, "[GetValidLinkInfo] Borrower has a valid link" ); |
| 112 |
is( $uname1, $userid1, "[GetValidLinkInfo] Borrower's username is fetched when a valid link is found" ); |
112 |
is( $uname1, $userid1, "[GetValidLinkInfo] Borrower's username is fetched when a valid link is found" ); |
| 113 |
ok( ! defined($bnum2), "[GetValidLinkInfo] Borrower's link is no longer valid; entry is expired" ); |
113 |
ok( ! defined($bnum2), "[GetValidLinkInfo] Borrower's link is no longer valid; entry is expired" ); |
| 114 |
ok( ! defined($bnum3), "[GetValidLinkInfo] Invalid UUID returns no borrowernumber" ); |
114 |
ok( ! defined($bnum3), "[GetValidLinkInfo] Invalid UUID returns no borrowernumber" ); |
| 115 |
|
115 |
|
| 116 |
################################################## |
116 |
############################################################## |
| 117 |
# C4::Passwordrecovery::CompletePasswordRecovery # |
117 |
# Koha::Patron::Password::Recovery::CompletePasswordRecovery # |
| 118 |
################################################## |
118 |
############################################################## |
| 119 |
|
119 |
|
| 120 |
ok( C4::Passwordrecovery::CompletePasswordRecovery($uuid1) == 2, "[CompletePasswordRecovery] Completing a password recovery deletes the entry and expired entries" ); |
120 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid1) == 2, "[CompletePasswordRecovery] Completing a password recovery deletes the entry and expired entries" ); |
| 121 |
|
121 |
|
| 122 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
122 |
$schema->resultset('BorrowerPasswordRecovery')->create( |
| 123 |
{ |
123 |
{ |
|
Lines 127-148
$schema->resultset('BorrowerPasswordRecovery')->create(
Link Here
|
| 127 |
} |
127 |
} |
| 128 |
); |
128 |
); |
| 129 |
|
129 |
|
| 130 |
ok( C4::Passwordrecovery::CompletePasswordRecovery($uuid2) == 1, "[CompletePasswordRecovery] An expired or invalid UUID purges expired entries" ); |
130 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 1, "[CompletePasswordRecovery] An expired or invalid UUID purges expired entries" ); |
| 131 |
ok( C4::Passwordrecovery::CompletePasswordRecovery($uuid2) == 0, "[CompletePasswordRecovery] Returns 0 on a clean table" ); |
131 |
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 0, "[CompletePasswordRecovery] Returns 0 on a clean table" ); |
| 132 |
|
132 |
|
| 133 |
################################################### |
133 |
############################################################### |
| 134 |
# C4::Passwordrecovery::SendPasswordRecoveryEmail # |
134 |
# Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail # |
| 135 |
################################################### |
135 |
############################################################### |
| 136 |
|
136 |
|
| 137 |
my $borrower = shift [ Koha::Borrowers->search( { userid => $userid1 } ) ]; |
137 |
my $borrower = shift [ Koha::Borrowers->search( { userid => $userid1 } ) ]; |
| 138 |
ok( C4::Passwordrecovery::SendPasswordRecoveryEmail($borrower, $email1, 0) == 1, "[SendPasswordRecoveryEmail] Returns 1 on success" ); |
138 |
ok( Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 0) == 1, "[SendPasswordRecoveryEmail] Returns 1 on success" ); |
| 139 |
my $letters = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber1, limit => 99 } ); |
139 |
my $letters = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber1, limit => 99 } ); |
| 140 |
ok( scalar @$letters == 1, "[SendPasswordRecoveryEmail] There is a letter in the queue for our borrower"); |
140 |
ok( scalar @$letters == 1, "[SendPasswordRecoveryEmail] There is a letter in the queue for our borrower"); |
| 141 |
|
141 |
|
| 142 |
my $bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumber => $borrowernumber1 } ); |
142 |
my $bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumber => $borrowernumber1 } ); |
| 143 |
my $tempuuid1 = $bpr->next->uuid; |
143 |
my $tempuuid1 = $bpr->next->uuid; |
| 144 |
|
144 |
|
| 145 |
C4::Passwordrecovery::SendPasswordRecoveryEmail($borrower, $email1, 1); |
145 |
Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 1); |
| 146 |
|
146 |
|
| 147 |
$bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumber => $borrowernumber1 } ); |
147 |
$bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumber => $borrowernumber1 } ); |
| 148 |
my $tempuuid2 = $bpr->next->uuid; |
148 |
my $tempuuid2 = $bpr->next->uuid; |
| 149 |
- |
|
|