Bug 23538 - Email library when new patrons self register
Summary: Email library when new patrons self register
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement with 10 votes (vote)
Assignee: Alex Buckley
QA Contact: Katrin Fischer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-04 16:53 UTC by Kelly McElligott
Modified: 2023-12-28 20:44 UTC (History)
9 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Medium patch
Documentation contact: Aude Charillon
Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/635
Text to go in the release notes:
This enhancement allows libraries to receive notifications when patrons self-register. This is enabled using the new system preference EmailPatronRegistrations (options are: none, email address of library, EmailAddressForPatronRegistrations, and KohaAdminEmailAddress) and a new notice (OPAC_REG). To use a specific email address for notifications, use the new system preference EmailAddressForPatronRegistrations. If verification is required for self-registrations (when PatronSelfRegistrationVerifyByEmail is enabled), then notifications are only sent to the library once the registration is confirmed.
Version(s) released in:
22.11.00


Attachments
Bug 23538: Database changes (8.26 KB, patch)
2022-04-06 21:09 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (9.43 KB, patch)
2022-04-06 21:12 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Unit tests (3.76 KB, patch)
2022-04-06 21:12 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (5.68 KB, patch)
2022-04-06 22:44 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (6.66 KB, patch)
2022-04-08 01:31 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (9.67 KB, patch)
2022-04-08 01:37 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Unit tests (3.75 KB, patch)
2022-04-08 01:37 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (6.66 KB, patch)
2022-04-08 01:37 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (9.43 KB, patch)
2022-04-08 01:42 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Unit tests (3.75 KB, patch)
2022-04-08 01:42 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (6.66 KB, patch)
2022-04-08 01:42 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Database changes (8.37 KB, patch)
2022-07-22 01:59 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (9.37 KB, patch)
2022-07-22 02:00 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (9.37 KB, patch)
2022-07-22 02:11 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Unit tests (3.77 KB, patch)
2022-07-22 02:11 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (46.63 KB, patch)
2022-07-22 02:12 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 23538: Database changes (8.41 KB, patch)
2022-07-28 22:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (8.58 KB, patch)
2022-07-28 22:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 23538: Unit tests (3.82 KB, patch)
2022-07-28 22:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (46.68 KB, patch)
2022-07-28 22:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 23538: Database changes (8.47 KB, patch)
2022-07-30 14:51 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 23538: Email library when new patron self-registers (8.63 KB, patch)
2022-07-30 14:51 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 23538: Unit tests (3.88 KB, patch)
2022-07-30 14:51 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 23538: (follow-up) Fix up notices (5.09 KB, patch)
2022-07-30 14:51 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 23538: (QA follow-up) Group system preferences into one entry (3.19 KB, patch)
2022-07-30 14:51 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 23538: (follow-up) Workaround to fix Patron.t (1.27 KB, patch)
2022-10-03 08:09 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kelly McElligott 2019-09-04 16:53:28 UTC
Self Registration is a great feature in the OPAC.  However, some libraries find it hard to manage these new registrations and would like to be alerted via email when a new patron self-registers.  In the newest version of Koha, 19.05, this feature has been added for Purchase Suggestions, email library when new purchase suggestion is created.  It would be great to have this same thing for Self Registration.
Comment 1 David Cook 2020-04-09 04:37:05 UTC
This is something that we've implemented locally for clients.

I have other priorities at the moment, but I could look at upstreaming that code when I have a chance.
Comment 2 Alex Buckley 2020-04-24 03:41:14 UTC
Hi all,

I've implemented functionality very similar to what is requested on this bug report in Bug 25090

Our client wanted to be able to moderate which patron self registrations got OPAC logins (i.e. a record in the borrowers table) due to wanting to restrict paid for access to online resources (for which users need a Koha OPAC login) to only those self registrations from within their organisation. 

With PatronSelfRegistrationVerifybyEmail syspref patrons do not get a patron record (OPAC login) until they've clicked the verification link in the email. 

However it gave the library no control over which self registrations got OPAC logins. The functionality in bug 25090 allows librarians to control who receives the verification email, (much the same way as: EmailPurchaseSuggestions and EmailAddressForSuggestions) if set to anything other than 'email address of registering patron' then a notice is sent to librarians listing some patron details. 

If the library decides that registration is valid (because the user is in the same organisation for example) they can click the verification link and a password reset link is sent to the registering patron to reset their credentials and login to the OPAC. 

I'd really appreciate any thoughts/feedback on bug 25090 :)

Many thanks,
Alex
Comment 3 Alex Buckley 2022-04-06 21:09:15 UTC
Created attachment 133050 [details] [review]
Bug 23538: Database changes

Sponsored-by: Catalyst IT
Comment 4 Alex Buckley 2022-04-06 21:12:23 UTC
Created attachment 133051 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply patchset
2. Update database:
- cd installer/data/mysql
- sudo koha-shell <instance>
- ./updatedatabase.pl
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:
6.a. EmailPatronRegistrations syspref = 'none'. Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

6.b. EmailPatronRegistrations syspref = 'email address of branch'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address of
branch address

6.c. EmailPatronRegistrations syspref =
'EmailAddressForPatronRegistrations'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling EmailAddressForPatronRegistrations syspref

6.d. EmailPatronRegistrations syspref = 'KohaAdminEmailAddress'. Submit
OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling KohaAdminEmaiLAddress syspref

7. Enable PatronSelfRegistrationVerifyByEmail syspref
8. Repeat steps 6.a, 6.b, 6.c, 6.d but this time confirm the expected
outcomes only happen AFTER you have clicked the verification link in the
OPAC_REG_VERIFY notice

Sponsored-by: Catalyst IT
Comment 5 Alex Buckley 2022-04-06 21:12:55 UTC
Created attachment 133052 [details] [review]
Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT
Comment 6 Alex Buckley 2022-04-06 22:44:11 UTC
Created attachment 133053 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template syntax to notices
- Add translated notice

Sponsored-by: Catalyst IT
Comment 7 Alex Buckley 2022-04-08 01:31:17 UTC
Created attachment 133097 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template (TT) syntax to notices
- Add TT conditionals to notices
- Add translated notice

Sponsored-by: Catalyst IT
Comment 8 Alex Buckley 2022-04-08 01:37:09 UTC
Created attachment 133098 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply patchset
2. Update database:
- cd installer/data/mysql
- sudo koha-shell <instance>
- ./updatedatabase.pl
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:
6.a. EmailPatronRegistrations syspref = 'none'. Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

6.b. EmailPatronRegistrations syspref = 'email address of branch'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address of
branch address

6.c. EmailPatronRegistrations syspref =
'EmailAddressForPatronRegistrations'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling EmailAddressForPatronRegistrations syspref

6.d. EmailPatronRegistrations syspref = 'KohaAdminEmailAddress'. Submit
OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling KohaAdminEmaiLAddress syspref

7. Enable PatronSelfRegistrationVerifyByEmail syspref
8. Repeat steps 6.a, 6.b, 6.c, 6.d but this time confirm the expected
outcomes only happen AFTER you have clicked the verification link in the
OPAC_REG_VERIFY notice

Sponsored-by: Catalyst IT
Comment 9 Alex Buckley 2022-04-08 01:37:28 UTC
Created attachment 133099 [details] [review]
Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT
Comment 10 Alex Buckley 2022-04-08 01:37:55 UTC
Created attachment 133100 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template (TT) syntax to notices
- Add TT conditionals to notices
- Add translated notice

Sponsored-by: Catalyst IT
Comment 11 Alex Buckley 2022-04-08 01:42:14 UTC
Created attachment 133101 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply patchset
2. Update database:
- cd installer/data/mysql
- sudo koha-shell <instance>
- ./updatedatabase.pl
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:
6.a. EmailPatronRegistrations syspref = 'none'. Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

6.b. EmailPatronRegistrations syspref = 'email address of branch'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address of
branch address

6.c. EmailPatronRegistrations syspref =
'EmailAddressForPatronRegistrations'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling EmailAddressForPatronRegistrations syspref

6.d. EmailPatronRegistrations syspref = 'KohaAdminEmailAddress'. Submit
OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling KohaAdminEmaiLAddress syspref

7. Enable PatronSelfRegistrationVerifyByEmail syspref
8. Repeat steps 6.a, 6.b, 6.c, 6.d but this time confirm the expected
outcomes only happen AFTER you have clicked the verification link in the
OPAC_REG_VERIFY notice

Sponsored-by: Catalyst IT
Comment 12 Alex Buckley 2022-04-08 01:42:38 UTC
Created attachment 133102 [details] [review]
Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT
Comment 13 Alex Buckley 2022-04-08 01:42:57 UTC
Created attachment 133103 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template (TT) syntax to notices
- Add TT conditionals to notices
- Add translated notice

Sponsored-by: Catalyst IT
Comment 14 Alex Buckley 2022-04-08 02:15:50 UTC
I linked bug 25090 in comment #2 but I think that will need me to do some re-work to get it working better. 

So what I've done now is write this patchset, so librarians can at least choose if they are notified when a new patron self-registers. This is similar functionality to emails sent to the library when an OPAC purchase suggestion is made.

Ready to test!
Comment 15 Lucas Gass 2022-05-18 22:00:02 UTC
Hi Alex, it looks like there is a small conflict in sample_notices.yml in current master. Can this be rebased?
Comment 16 Alex Buckley 2022-07-22 01:59:31 UTC
Created attachment 137997 [details] [review]
Bug 23538: Database changes

Sponsored-by: Catalyst IT
Comment 17 Alex Buckley 2022-07-22 02:00:13 UTC
Created attachment 137998 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply all patches
2. Update database
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:

- EmailPatronRegistrations syspref = 'none'.
Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

---

-  EmailPatronRegistrations syspref = 'email address of branch'.
Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling the branch address

---

- EmailPatronRegistrations syspref = 'EmailAddressForPatronRegistrations'.
Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling EmailAddressForPatronRegistrations syspref

---

- EmailPatronRegistrations syspref = 'KohaAdminEmailAddress'.
Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling KohaAdminEmailAddress syspref

7. Enable PatronSelfRegistrationVerifyByEmail syspref
8. Repeat testing all use cases. Confirm this time the expected outcomes only happen AFTER you have clicked the verification link in the OPAC_REG_VERIFY notice

Sponsored-by: Catalyst IT
Comment 18 Alex Buckley 2022-07-22 02:11:16 UTC
Created attachment 137999 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply all patches
2. Update database
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:

- EmailPatronRegistrations syspref = 'none'.
Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

---

-  EmailPatronRegistrations syspref = 'email address of branch'.
Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling the branch address

---

- EmailPatronRegistrations syspref = 'EmailAddressForPatronRegistrations'.
Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling EmailAddressForPatronRegistrations syspref

---

- EmailPatronRegistrations syspref = 'KohaAdminEmailAddress'.
Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling KohaAdminEmailAddress syspref

7. Enable PatronSelfRegistrationVerifyByEmail syspref
8. Repeat testing all use cases. Confirm this time the expected outcomes only happen AFTER you have clicked the verification link in the OPAC_REG_VERIFY notice

Sponsored-by: Catalyst IT
Comment 19 Alex Buckley 2022-07-22 02:11:46 UTC
Created attachment 138000 [details] [review]
Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT
Comment 20 Alex Buckley 2022-07-22 02:12:19 UTC
Created attachment 138001 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template (TT) syntax to notices
- Add TT conditionals to notices
- Add translated notice

Sponsored-by: Catalyst IT
Comment 21 Alex Buckley 2022-07-22 03:19:34 UTC
Hi Lucas, 

Apologies for the delay rebasing. This is now rebased and is ready for testing again.

Thanks,
Alex
Comment 22 David Nind 2022-07-28 22:47:34 UTC
Created attachment 138237 [details] [review]
Bug 23538: Database changes

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>
Comment 23 David Nind 2022-07-28 22:47:39 UTC
Created attachment 138238 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply all patches
2. Update database
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:

- EmailPatronRegistrations syspref = 'none'.
Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

Signed-off-by: David Nind <david@davidnind.com>
Comment 24 David Nind 2022-07-28 22:47:44 UTC
Created attachment 138239 [details] [review]
Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>
Comment 25 David Nind 2022-07-28 22:47:49 UTC
Created attachment 138240 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template (TT) syntax to notices
- Add TT conditionals to notices
- Add translated notice

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>
Comment 26 David Nind 2022-07-28 23:20:39 UTC
Not sure what happened to the test plan for the 'Email library when new patron self-registers' patch after I signed it off - step 6 and onwards are cut off.
Comment 27 David Nind 2022-07-28 23:34:41 UTC
Minor suggested changes to the new EmailPatronRegistrations system preference wording:

- Revised wording for the first sentence: Choose the email address that new patron self-registration notifications are sent to: [options].

- Option - 'email address of branch': I think the terminology guidelines are to use library instead of branch. 

- Remove the : at the end of the last sentence and replace with a full stop. I've also suggested some revised wording.

==> Choose the email address that new patron self-registration notifications are sent to: [options]. A valid email address is required for EmailAddressForPatronRegistrations if that option is selected.
Comment 28 Katrin Fischer 2022-07-30 14:51:25 UTC
Created attachment 138383 [details] [review]
Bug 23538: Database changes

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 29 Katrin Fischer 2022-07-30 14:51:30 UTC
Created attachment 138384 [details] [review]
Bug 23538: Email library when new patron self-registers

Test plan:
1. Apply all patches
2. Update database
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:

- EmailPatronRegistrations syspref = 'none'.
Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 30 Katrin Fischer 2022-07-30 14:51:35 UTC
Created attachment 138385 [details] [review]
Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 31 Katrin Fischer 2022-07-30 14:51:41 UTC
Created attachment 138386 [details] [review]
Bug 23538: (follow-up) Fix up notices

- Add toolkit template (TT) syntax to notices
- Add TT conditionals to notices

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 32 Katrin Fischer 2022-07-30 14:51:46 UTC
Created attachment 138387 [details] [review]
Bug 23538: (QA follow-up) Group system preferences into one entry

This makes the new perferences EmailPatronRegistrations and EmailAddressForPatronRegistrations
follow a little more closely the pattern set by the very similar
EmailPurchaseSuggestions and EmailAddressforSuggestions.

* Group both preferences into one entry
* Add line break between preferences
* Switch branch for library in pull down

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 33 Katrin Fischer 2022-07-30 14:52:15 UTC
Very happy to see inbound_email_address and ReplyToDefault used here!

installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql is no longer necessary. I have amended David's patch removing the file and adjusting the commit message.
Comment 34 Alex Buckley 2022-07-31 21:29:08 UTC
Thanks very much for testing and feedback David and Katrin!

Great to see this Passed QA
Comment 35 Tomás Cohen Arazi 2022-09-23 12:58:57 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 36 Marcel de Rooy 2022-10-03 07:12:10 UTC
+    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'root@localhost' );
+    t::lib::Mocks::mock_preference( 'EmailAddressForPatronRegistrations', 'library@localhost' );
+
+    # Test when EmailPatronRegistrations equals BranchEmailAddress
+    t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'BranchEmailAddress' );
+    is( $patron->notify_library_of_registration(C4::Context->preference('EmailPatronRegistrations')), 1, 'OPAC_REG email is queued if EmailPatronRegistration syspref equals BranchEmailAddress');
+    my $sth = $dbh->prepare("SELECT to_address FROM message_queue where borrowernumber = ?");
+    $sth->execute( $patron->borrowernumber );
+    my $to_address = $sth->fetchrow_array;
+    is( $to_address, 'to@mybranch.com', 'OPAC_REG email queued to go to branchreplyto address when EmailPatronRegistration equals BranchEmailAddress' );
+    $dbh->do(q|DELETE FROM message_queue|);
+
+    # Test when EmailPatronRegistrations equals EmailAddressForPatronRegistrations
+    t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'EmailAddressForPatronRegistrations' );
+    is( $patron->notify_library_of_registration(C4::Context->preference('EmailPatronRegistrations')), 1, 'OPAC_REG email is queued if EmailPatronRegistration syspref equals EmailAddressForPatronRegistrations');
+    $sth->execute( $patron->borrowernumber );
+    $to_address = $sth->fetchrow_array;
+    is( $to_address, 'library@localhost', 'OPAC_REG email queued to go to EmailAddressForPatronRegistrations syspref when EmailPatronRegistration equals EmailAddressForPatronRegistrations' );
+    $dbh->do(q|DELETE FROM message_queue|);
+
+    # Test when EmailPatronRegistrations equals KohaAdminEmailAddress
+    t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'KohaAdminEmailAddress' );
+    is( $patron->notify_library_of_registration(C4::Context->preference('EmailPatronRegistrations')), 1, 'OPAC_REG email is queued if EmailPatronRegistration syspref equals KohaAdminEmailAddress');
+    $sth->execute( $patron->borrowernumber );
+    $to_address = $sth->fetchrow_array;
+    is( $to_address, 'root@localhost', 'OPAC_REG email queued to go to KohaAdminEmailAddress syspref when EmailPatronRegistration equals KohaAdminEmailAddress' );
+    $dbh->do(q|DELETE FROM message_queue|);

This part of the test fails with me:
    not ok 6 - OPAC_REG email queued to go to KohaAdminEmailAddress syspref when EmailPatronRegistration equals KohaAdminEmailAddress
    #   Failed test 'OPAC_REG email queued to go to KohaAdminEmailAddress syspref when EmailPatronRegistration equals KohaAdminEmailAddress'
    #   at t/db_dependent/Koha/Patron.t line 1347.
    #          got: 'bibliotheek@master.rijkskoha.nl'
    #     expected: 'root@localhost'
    # Looks like you failed 1 test of 6.

Also note that you'd better not use localhost as an email address in your tests. 
And that you include several SQL statements that should be Koha objects.
Comment 37 Marcel de Rooy 2022-10-03 07:25:43 UTC
Koha::Patron

        elsif ( $email_patron_registrations eq "KohaAdminEmailAddress" ) {
            $to_address = C4::Context->preference('ReplytoDefault')
            || C4::Context->preference('KohaAdminEmailAddress');
        }

This is the cause of the failing test. Why do you use ReplytoDefault here. The value of the pref says KohaAdmin. This is quite confusing.
Comment 38 Marcel de Rooy 2022-10-03 08:09:06 UTC
Created attachment 141223 [details] [review]
Bug 23538: (follow-up) Workaround to fix Patron.t

See comment36 and comment37. This needs more attention but
serves as a quick fix only.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 39 Marcel de Rooy 2022-10-03 08:10:26 UTC
Tomas: Last patch only please.
Comment 40 Tomás Cohen Arazi 2022-10-03 15:41:49 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 41 Tomás Cohen Arazi 2022-10-03 16:35:46 UTC
(In reply to Marcel de Rooy from comment #39)
> Tomas: Last patch only please.

Thank you, Marcel. Good job!
Comment 42 Lucas Gass 2022-11-01 22:10:55 UTC
Enhancement will not be backported to 22.05.x series
Comment 43 Aude Charillon 2023-03-06 09:05:29 UTC
Added to manual.