From ba6872a50ff8f9826656755ed7ef12e10efbec36 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Tue, 4 Oct 2022 12:01:47 +0100
Subject: [PATCH] Bug 25936: (follow-up) Unit test for store

This unit test confirms that we are not triggering the Password Change
notification notice upon patron creations.
---
 t/db_dependent/Koha/Patrons.t | 36 ++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t
index ad8e7e58f7..627f0f9f4d 100755
--- a/t/db_dependent/Koha/Patrons.t
+++ b/t/db_dependent/Koha/Patrons.t
@@ -1865,7 +1865,7 @@ subtest 'Test Koha::Patrons::merge' => sub {
 };
 
 subtest '->store' => sub {
-    plan tests => 7;
+    plan tests => 8;
     my $schema = Koha::Database->new->schema;
     $schema->storage->txn_begin;
 
@@ -1921,6 +1921,40 @@ subtest '->store' => sub {
         is($logs->count, 0, '->store should not have generated a log for updated_on') or diag 'Log generated:'.Dumper($logs->unblessed);
         $schema->storage->txn_rollback;
     };
+
+    subtest 'create user usage' => sub {
+        plan tests => 1;
+        $schema->storage->txn_begin;
+
+        my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+        my $patron_category = $builder->build_object(
+            {
+                class => 'Koha::Patron::Categories',
+                value => { category_type => 'P', enrolmentfee => 0 }
+            }
+        );
+        my %data = (
+            cardnumber   => "123456789",
+            firstname    => "Tômàsító",
+            surname      => "Ñoné",
+            password     => 'Funk3y',
+            categorycode => $patron_category->categorycode,
+            branchcode   => $library->branchcode,
+        );
+
+        # Enable notifying patrons of password changes for these tests
+        t::lib::Mocks::mock_preference( 'NotifyPasswordChange', 1 );
+        my $new_patron     = Koha::Patron->new( \%data )->store();
+        my $queued_notices = Koha::Notice::Messages->search(
+            { borrowernumber => $new_patron->borrowernumber }
+        );
+        is(
+            $queued_notices->count, 0,
+            "No notice queued when NotifyPasswordChange enabled and this is a new patron"
+        );
+
+        $schema->storage->txn_rollback;
+    };
 };
 
 subtest '->set_password' => sub {
-- 
2.20.1