From 639453b1493fb86d15fa829917769a3ab80d449e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 29 Sep 2022 12:42:39 +0100 Subject: [PATCH] Bug 25936: Unit tests Content-Type: text/plain; charset=utf-8 This patch adds a unit test to check that the notice is enqueued and sending is attempted immediately. Signed-off-by: Marcel de Rooy --- t/db_dependent/Koha/Patrons.t | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index c8f8ce32af..7a2f4597bf 100755 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1925,15 +1925,18 @@ subtest '->store' => sub { subtest '->set_password' => sub { - plan tests => 14; + plan tests => 16; $schema->storage->txn_begin; my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { login_attempts => 3 } } ); - # Disable logging password changes for this tests + # Disable logging password changes for these tests t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); + # Disable notifying patrons of password changes for these tests + t::lib::Mocks::mock_preference( 'NotifyPasswordChange', 0 ); + # Password-length tests t::lib::Mocks::mock_preference( 'minPasswordLength', undef ); throws_ok { $patron->set_password({ password => 'ab' }); } @@ -1998,6 +2001,14 @@ subtest '->set_password' => sub { $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' ); + # Enable notifying patrons of password changes + t::lib::Mocks::mock_preference( 'NotifyPasswordChange', 1 ); + $patron->set_password({ password => 'abcd c' }); + my $queued_notices = Koha::Notice::Messages->search({ borrowernumber => $patron->borrowernumber }); + is( $queued_notices->count, 1, "One notice queued when NotifyPassowrdChange enabled" ); + my $THE_notice = $queued_notices->next; + is( $THE_notice->status, 'failed', "The notice was sent immediately"); + $schema->storage->txn_rollback; }; -- 2.30.2