Lines 19-31
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 |
use Test::Warn; |
23 |
|
24 |
|
24 |
use Koha::Patron; |
25 |
use Koha::Patron; |
25 |
use Koha::Patrons; |
26 |
use Koha::Patrons; |
26 |
use Koha::Database; |
27 |
use Koha::Database; |
27 |
|
28 |
|
28 |
use t::lib::TestBuilder; |
29 |
use t::lib::TestBuilder; |
|
|
30 |
use t::lib::Mocks; |
29 |
|
31 |
|
30 |
my $schema = Koha::Database->new->schema; |
32 |
my $schema = Koha::Database->new->schema; |
31 |
$schema->storage->txn_begin; |
33 |
$schema->storage->txn_begin; |
Lines 40-45
my $new_patron_1 = Koha::Patron->new(
Link Here
|
40 |
categorycode => $category->{categorycode}, |
42 |
categorycode => $category->{categorycode}, |
41 |
surname => 'surname for patron1', |
43 |
surname => 'surname for patron1', |
42 |
firstname => 'firstname for patron1', |
44 |
firstname => 'firstname for patron1', |
|
|
45 |
userid => 'a_nonexistent_userid_1', |
43 |
} |
46 |
} |
44 |
)->store; |
47 |
)->store; |
45 |
my $new_patron_2 = Koha::Patron->new( |
48 |
my $new_patron_2 = Koha::Patron->new( |
Lines 48-53
my $new_patron_2 = Koha::Patron->new(
Link Here
|
48 |
categorycode => $category->{categorycode}, |
51 |
categorycode => $category->{categorycode}, |
49 |
surname => 'surname for patron2', |
52 |
surname => 'surname for patron2', |
50 |
firstname => 'firstname for patron2', |
53 |
firstname => 'firstname for patron2', |
|
|
54 |
userid => 'a_nonexistent_userid_2', |
51 |
} |
55 |
} |
52 |
)->store; |
56 |
)->store; |
53 |
|
57 |
|
Lines 98-103
subtest 'siblings' => sub {
Link Here
|
98 |
$retrieved_guarantee_1->delete; |
102 |
$retrieved_guarantee_1->delete; |
99 |
}; |
103 |
}; |
100 |
|
104 |
|
|
|
105 |
subtest 'update_password' => sub { |
106 |
plan tests => 7; |
107 |
|
108 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
109 |
my $original_userid = $new_patron_1->userid; |
110 |
my $original_password = $new_patron_1->password; |
111 |
warning_like { $retrieved_patron_1->update_password( $new_patron_2->userid, 'another_password' ) } |
112 |
qr{Duplicate entry}, |
113 |
'Koha::Patron->update_password should warn if the userid is already used by another patron'; |
114 |
is( Koha::Patrons->find( $new_patron_1->borrowernumber )->userid, $original_userid, 'Koha::Patron->update_password should not have updated the userid' ); |
115 |
is( Koha::Patrons->find( $new_patron_1->borrowernumber )->password, $original_password, 'Koha::Patron->update_password should not have updated the userid' ); |
116 |
|
117 |
$retrieved_patron_1->update_password( 'another_nonexistent_userid_1', 'another_password' ); |
118 |
is( Koha::Patrons->find( $new_patron_1->borrowernumber )->userid, 'another_nonexistent_userid_1', 'Koha::Patron->update_password should have updated the userid' ); |
119 |
is( Koha::Patrons->find( $new_patron_1->borrowernumber )->password, 'another_password', 'Koha::Patron->update_password should have updated the password' ); |
120 |
|
121 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $new_patron_1->borrowernumber } )->count; |
122 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should have logged' ); |
123 |
|
124 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
125 |
$retrieved_patron_1->update_password( 'yet_another_nonexistent_userid_1', 'another_password' ); |
126 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $new_patron_1->borrowernumber } )->count; |
127 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' ); |
128 |
}; |
129 |
|
101 |
$retrieved_patron_1->delete; |
130 |
$retrieved_patron_1->delete; |
102 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
131 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
103 |
|
132 |
|
104 |
- |
|
|