Bugzilla – Attachment 89146 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
Bug-5770-Unit-test.patch (text/plain), 6.12 KB, created by
Liz Rea
on 2019-04-30 17:20:10 UTC
(
hide
)
Description:
Bug 5770: Unit test
Filename:
MIME Type:
Creator:
Liz Rea
Created:
2019-04-30 17:20:10 UTC
Size:
6.12 KB
patch
obsolete
>From fe95a7441f886fbcb60537ead23fb790d0030bbe Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= <nazli@devinim.com.tr> >Date: Tue, 30 Apr 2019 15:56:26 +0000 >Subject: [PATCH] Bug 5770: Unit test > >Signed-off-by: Liz Rea <wizzyrea@gmail.com> >--- > C4/Letters.pm | 5 ++++ > t/db_dependent/Suggestions.t | 57 +++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 61 insertions(+), 1 deletion(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index b8175f5521..8b086a79ab 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -1081,6 +1081,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/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index 16e0dd2a29..56e7d2240e 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; >@@ -61,6 +61,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 +96,7 @@ my $my_suggestion = { > publishercode => 'my publishercode', > suggestedby => $borrowernumber, > biblionumber => $biblionumber1, >+ branchcode => 'CPL', > managedby => '', > manageddate => '', > accepteddate => dt_from_string, >@@ -190,6 +192,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 +220,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 +231,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 +247,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 +468,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