Bugzilla – Attachment 84812 Details for
Bug 5770
Email librarian when purchase suggestion made
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 5770: Unit test and skeleton perl
Bug-5770-Unit-test-and-skeleton-perl.patch (text/plain), 11.51 KB, created by
Devinim
on 2019-02-06 12:03:58 UTC
(
hide
)
Description:
Bug 5770: Unit test and skeleton perl
Filename:
MIME Type:
Creator:
Devinim
Created:
2019-02-06 12:03:58 UTC
Size:
11.51 KB
patch
obsolete
>From be8632dc2ab90d500c4f3649a63195f78f93802e Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= <nazli@devinim.com.tr> >Date: Wed, 6 Feb 2019 12:01:04 +0000 >Subject: [PATCH] Bug 5770: Unit test and skeleton perl > >--- > C4/Letters.pm | 5 +++ > C4/Suggestions.pm | 2 +- > installer/data/mysql/atomicupdate/bug_5770.perl | 39 +++++++++++++++++ > installer/data/mysql/atomicupdate/bug_5770.sql | 30 ------------- > t/db_dependent/Suggestions.t | 58 ++++++++++++++++++++++++- > 5 files changed, 101 insertions(+), 33 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_5770.perl > delete mode 100644 installer/data/mysql/atomicupdate/bug_5770.sql > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 0f2378d6603..810d06cde30 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -1077,6 +1077,11 @@ ENDSQL > push @query_params, $params->{'borrowernumber'}; > } > >+ if ( exists $params->{'letter_code'} ) { >+ push @whereclauses, ' letter_code = ? '; >+ push @query_params, $params->{'letter_code'}; >+ } >+ > if ( @whereclauses ) { > $statement .= ' WHERE ' . join( 'AND', @whereclauses ); > } >diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm >index ece7c413cd1..08a02f844d8 100644 >--- a/C4/Suggestions.pm >+++ b/C4/Suggestions.pm >@@ -471,7 +471,7 @@ sub NewSuggestion { > my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions"); > > my $toaddress = ( $emailpurchasesuggestions eq "BranchEmailAddress" ) >- ? Koha::Libraries->find($full_suggestion->{branchcode})->branchemail >+ ? ( Koha::Libraries->find($full_suggestion->{branchcode})->branchemail || C4::Context->preference('KohaAdminEmailAddress') ) > : C4::Context->preference( $emailpurchasesuggestions ) ; > > C4::Letters::EnqueueLetter( >diff --git a/installer/data/mysql/atomicupdate/bug_5770.perl b/installer/data/mysql/atomicupdate/bug_5770.perl >new file mode 100644 >index 00000000000..7e4e7de6d1d >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_5770.perl >@@ -0,0 +1,39 @@ >+$DBversion = '18.12.00.XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ $dbh->do( q{ >+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES >+ ('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'), >+ ('EmailAddressForSuggestions','','','If you choose EmailAddressForSuggestions you should enter a valid email address','free') >+ }); >+ $dbh->do( q{ >+ INSERT IGNORE INTO `letter` (module, code, name, title, content, is_html, message_transport_type) VALUES >+ ('suggestions','NEW_SUGGESTION','New suggestion','New suggestion','<h3>Suggestion pending approval</h3> >+ <p><h4>Suggested by</h4> >+ <ul> >+ <li><<borrowers.firstname>> <<borrowers.surname>></li> >+ <li><<borrowers.cardnumber>></li> >+ <li><<borrowers.phone>></li> >+ <li><<borrowers.email>></li> >+ </ul> >+ </p> >+ <p><h4>Title suggested</h4> >+ <ul> >+ <li><b>Library:</b> <<branches.branchname>></li> >+ <li><b>Title:</b> <<suggestions.title>></li> >+ <li><b>Author:</b> <<suggestions.author>></li> >+ <li><b>Copyright date:</b> <<suggestions.copyrightdate>></li> >+ <li><b>Standard number (ISBN, ISSN or other):</b> <<suggestions.isbn>></li> >+ <li><b>Publisher:</b> <<suggestions.publishercode>></li> >+ <li><b>Collection title:</b> <<suggestions.collectiontitle>></li> >+ <li><b>Publication place:</b> <<suggestions.place>></li> >+ <li><b>Quantity:</b> <<suggestions.quantity>></li> >+ <li><b>Item type:</b> <<suggestions.itemtype>></li> >+ <li><b>Reason for suggestion:</b> <<suggestions.patronreason>></li> >+ <li><b>Notes:</b> <<suggestions.note>></li> >+ </ul> >+ </p>',1, 'email') >+ }); >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 5770 - Email librarian when purchase suggestion made)\n"; >+} >diff --git a/installer/data/mysql/atomicupdate/bug_5770.sql b/installer/data/mysql/atomicupdate/bug_5770.sql >deleted file mode 100644 >index 7537972bcba..00000000000 >--- a/installer/data/mysql/atomicupdate/bug_5770.sql >+++ /dev/null >@@ -1,30 +0,0 @@ >-INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES >-('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'), >-('EmailAddressForSuggestions','','','If you choose EmailAddressForSuggestions you should enter a valid email address','free'); >- >-INSERT IGNORE INTO `letter` (module, code, name, title, content, is_html, message_transport_type) >-VALUES ('suggestions','NEW_SUGGESTION','New suggestion','New suggestion','<h3>Suggestion pending approval</h3> >-<p><h4>Suggested by</h4> >- <ul> >- <li><<borrowers.firstname>> <<borrowers.surname>></li> >- <li><<borrowers.cardnumber>></li> >- <li><<borrowers.phone>></li> >- <li><<borrowers.email>></li> >- </ul> >-</p> >-<p><h4>Title suggested</h4> >- <ul> >- <li><b>Library:</b> <<branches.branchname>></li> >- <li><b>Title:</b> <<suggestions.title>></li> >- <li><b>Author:</b> <<suggestions.author>></li> >- <li><b>Copyright date:</b> <<suggestions.copyrightdate>></li> >- <li><b>Standard number (ISBN, ISSN or other):</b> <<suggestions.isbn>></li> >- <li><b>Publisher:</b> <<suggestions.publishercode>></li> >- <li><b>Collection title:</b> <<suggestions.collectiontitle>></li> >- <li><b>Publication place:</b> <<suggestions.place>></li> >- <li><b>Quantity:</b> <<suggestions.quantity>></li> >- <li><b>Item type:</b> <<suggestions.itemtype>></li> >- <li><b>Reason for suggestion:</b> <<suggestions.patronreason>></li> >- <li><b>Notes:</b> <<suggestions.note>></li> >- </ul> >-</p>',1, 'email'); >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index 16e0dd2a29c..4f2a350af83 100644 >--- a/t/db_dependent/Suggestions.t >+++ b/t/db_dependent/Suggestions.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use DateTime::Duration; >-use Test::More tests => 106; >+use Test::More tests => 107; > use Test::Warn; > > use t::lib::Mocks; >@@ -32,7 +32,6 @@ use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Libraries; > use Koha::Patrons; > use Koha::Suggestions; >- > BEGIN { > use_ok('C4::Suggestions'); > } >@@ -61,6 +60,7 @@ $dbh->do(q|DELETE FROM borrowers|); > $dbh->do(q|DELETE FROM letter|); > $dbh->do(q|DELETE FROM message_queue|); > $dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|); >+$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'NEW_SUGGESTION', 'Content for new suggestion')|); > > # Add CPL if missing. > if (not defined Koha::Libraries->find('CPL')) { >@@ -95,6 +95,7 @@ my $my_suggestion = { > publishercode => 'my publishercode', > suggestedby => $borrowernumber, > biblionumber => $biblionumber1, >+ branchcode => 'CPL', > managedby => '', > manageddate => '', > accepteddate => dt_from_string, >@@ -190,6 +191,7 @@ is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not > > my $messages = C4::Letters::GetQueuedMessages({ > borrowernumber => $borrowernumber, >+ letter_code => 'CHECKED', > }); > is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' ); > >@@ -217,6 +219,7 @@ $suggestion = GetSuggestion($my_suggestionid); > is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); > $messages = C4::Letters::GetQueuedMessages({ > borrowernumber => $borrowernumber, >+ letter_code => 'CHECKED', > }); > is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); > is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email'); >@@ -227,6 +230,7 @@ t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); > ModSuggestion($mod_suggestion3); > $messages = C4::Letters::GetQueuedMessages({ > borrowernumber => $borrowernumber, >+ letter_code => 'CHECKED', > }); > is ($messages->[1]->{message_transport_type}, 'sms', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is sms if the borrower has no email'); > >@@ -242,6 +246,7 @@ my $mod_suggestion4 = { > ModSuggestion($mod_suggestion4); > $messages = C4::Letters::GetQueuedMessages({ > borrowernumber => $borrowernumber2, >+ letter_code => 'CHECKED', > }); > is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email'); > >@@ -462,4 +467,53 @@ subtest 'DelSuggestionsOlderThan' => sub { > is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' ); > }; > >+subtest 'EmailPurchaseSuggestions' => sub { >+ plan tests => 5; >+ >+ $dbh->do(q|DELETE FROM message_queue|); >+ >+ Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' }); >+ t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost'); >+ t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c'); >+ t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress >+ >+ NewSuggestion($my_suggestion); >+ my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ >+ borrowernumber => $borrowernumber, >+ letter_code => 'NEW_SUGGESTION', >+ }); >+ >+ is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' ); >+ my $message1 = C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id}); >+ is ($message1->{to_address}, 'root@localhost', 'to_address is KohaAdminEmailAddress'); >+ >+ t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions"); >+ NewSuggestion($my_suggestion); >+ $newsuggestions_messages = C4::Letters::GetQueuedMessages({ >+ borrowernumber => $borrowernumber, >+ letter_code => 'NEW_SUGGESTION', >+ }); >+ my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id}); >+ is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions'); >+ >+ t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress"); >+ NewSuggestion($my_suggestion); >+ $newsuggestions_messages = C4::Letters::GetQueuedMessages({ >+ borrowernumber => $borrowernumber, >+ letter_code => 'NEW_SUGGESTION', >+ }); >+ my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id}); >+ is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress'); >+ >+ Koha::Libraries->find('CPL')->update({ branchemail => undef }); >+ NewSuggestion($my_suggestion); >+ $newsuggestions_messages = C4::Letters::GetQueuedMessages({ >+ borrowernumber => $borrowernumber, >+ letter_code => 'NEW_SUGGESTION', >+ }); >+ my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id}); >+ isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef'); >+ >+}; >+ > $schema->storage->txn_rollback; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 5770
:
83384
|
83385
|
83386
|
83387
|
83388
|
83390
|
83615
|
83616
|
83617
|
84463
|
84812
|
89139
|
89140
|
89141
|
89142
|
89144
|
89145
|
89146
|
89147
|
89188
|
89189
|
89190
|
89191
|
89192
|
89193
|
89194
|
89195