Bugzilla – Attachment 106428 Details for
Bug 22818
ILL should be able to send notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22818: Unit tests
Bug-22818-Unit-tests.patch (text/plain), 9.80 KB, created by
Andrew Isherwood
on 2020-06-30 08:36:13 UTC
(
hide
)
Description:
Bug 22818: Unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2020-06-30 08:36:13 UTC
Size:
9.80 KB
patch
obsolete
>From 0bd04f31daf6ded3519dbd23764c3cb2e98bca2c Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Thu, 9 May 2019 15:35:07 +0100 >Subject: [PATCH] Bug 22818: Unit tests > >This patch adds unit tests for the new methods in Illrequest.pm > >Signed-off-by: Niamh Walker-Headon <Niamh.Walker-Headon@it-tallaght.ie> >Sponsored-by: PTFS Europe >--- > t/db_dependent/Illrequests.t | 188 ++++++++++++++++++++++++++++++++--- > 1 file changed, 173 insertions(+), 15 deletions(-) > >diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t >index bc8e170958..876cb78b3a 100644 >--- a/t/db_dependent/Illrequests.t >+++ b/t/db_dependent/Illrequests.t >@@ -26,6 +26,9 @@ use Koha::Patrons; > use Koha::ItemTypes; > use Koha::Items; > use Koha::Libraries; >+use Koha::MessageAttributes; >+use Koha::MessageAttribute; >+use Koha::Notice::Templates; > use Koha::AuthorisedValueCategories; > use Koha::AuthorisedValues; > use t::lib::Mocks; >@@ -513,7 +516,7 @@ subtest 'Backend testing (mocks)' => sub { > > subtest 'Backend core methods' => sub { > >- plan tests => 19; >+ plan tests => 18; > > $schema->storage->txn_begin; > >@@ -704,20 +707,13 @@ subtest 'Backend core methods' => sub { > }) } > "Generic confirm: missing to dies OK."; > >- dies_ok { $illrq->generic_confirm({ >- current_branchcode => $illbrn->{branchcode}, >- partners => $partner1->{email}, >- stage => 'draft' >- }) } >- "Generic confirm: missing from dies OK."; >- > $schema->storage->txn_rollback; > }; > > > subtest 'Helpers' => sub { > >- plan tests => 7; >+ plan tests => 21; > > $schema->storage->txn_begin; > >@@ -725,6 +721,16 @@ subtest 'Helpers' => sub { > my $backend = Test::MockObject->new; > $backend->set_isa('Koha::Illbackends::Mock'); > $backend->set_always('name', 'Mock'); >+ $backend->mock( >+ 'metadata', >+ sub { >+ my ( $self, $rq ) = @_; >+ return { >+ title => 'mytitle', >+ author => 'myauthor' >+ } >+ } >+ ); > > my $config = Test::MockObject->new; > $config->set_always('backend_dir', "/tmp"); >@@ -733,9 +739,19 @@ subtest 'Helpers' => sub { > source => 'Borrower', > value => { categorycode => "A" } > }); >+ # Create a mocked branch with no email addressed defined >+ my $illbrn = $builder->build({ >+ source => 'Branch', >+ value => { >+ branchcode => 'HDE', >+ branchemail => "", >+ branchillemail => "", >+ branchreplyto => "" >+ } >+ }); > my $illrq = $builder->build({ > source => 'Illrequest', >- value => { branchcode => "CPL", borrowernumber => $patron->{borrowernumber} } >+ value => { branchcode => "HDE", borrowernumber => $patron->{borrowernumber} } > }); > my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); > $illrq_obj->_config($config); >@@ -743,12 +759,12 @@ subtest 'Helpers' => sub { > > # getPrefix > $config->set_series('getPrefixes', >- { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, >+ { HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, > { A => "ATEST", C => "CBAR", default => "DEFAULT" }); >- is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", >+ is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "HDE" }), "TEST", > "getPrefix: branch"); > $config->set_series('getPrefixes', >- { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, >+ { HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, > { A => "ATEST", C => "CBAR", default => "DEFAULT" }); > is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", > "getPrefix: default"); >@@ -758,11 +774,11 @@ subtest 'Helpers' => sub { > > # id_prefix > $config->set_series('getPrefixes', >- { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, >+ { HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, > { AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); > is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); > $config->set_series('getPrefixes', >- { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, >+ { HDET => "TEST", TSLT => "BAR", default => "DEFAULT" }, > { AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); > is($illrq_obj->id_prefix, "", "id_prefix: default"); > >@@ -772,6 +788,148 @@ subtest 'Helpers' => sub { > $illrq_obj->status('CANCREQ')->store; > is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes."); > >+ #send_patron_notice >+ my $attr = Koha::MessageAttributes->find({ message_name => 'Ill_ready' }); >+ C4::Members::Messaging::SetMessagingPreference({ >+ borrowernumber => $patron->{borrowernumber}, >+ message_attribute_id => $attr->message_attribute_id, >+ message_transport_types => ['email'] >+ }); >+ my $return_patron = $illrq_obj->send_patron_notice('ILL_PICKUP_READY'); >+ my $notice = $schema->resultset('MessageQueue')->search({ >+ letter_code => 'ILL_PICKUP_READY', >+ message_transport_type => 'email', >+ borrowernumber => $illrq_obj->borrowernumber >+ })->next()->letter_code; >+ is_deeply( >+ $return_patron, >+ { result => { success => ['email'], fail => [] } }, >+ "Correct return when notice created" >+ ); >+ is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created"); >+ >+ my $return_patron_fail = $illrq_obj->send_patron_notice(); >+ is_deeply( >+ $return_patron_fail, >+ { error => 'notice_no_type' }, >+ "Correct error when missing type" >+ ); >+ >+ #get_staff_to_address >+ # Mock a KohaAdminEmailAddress syspref >+ t::lib::Mocks::mock_preference( >+ 'KohaAdminEmailAddress', >+ 'kohaadmin@nowhere.com' >+ ); >+ # No branch addresses defined and no ILLDefaultStaffEmail, so should >+ # fall back to Koha admin address >+ my $email_kohaadmin = $illrq_obj->get_staff_to_address; >+ ok( >+ $email_kohaadmin eq 'kohaadmin@nowhere.com', >+ 'get_staff_to_address falls back to Koha admin in the absence of other alternatives' >+ ); >+ # General branch address defined, should fall back to that >+ $builder->delete({ source => 'Branch', records => $illbrn }); >+ $illbrn = $builder->build({ >+ source => 'Branch', >+ value => { >+ branchcode => 'HDE', >+ branchemail => 'branch@nowhere.com', >+ branchillemail => "", >+ branchreplyto => "" >+ } >+ }); >+ my $email_gen_branch = $illrq_obj->get_staff_to_address; >+ ok( >+ $email_gen_branch eq 'branch@nowhere.com', >+ 'get_staff_to_address falls back to general branch address when defined' >+ ); >+ # ILL staff syspref address defined, should fall back to that >+ t::lib::Mocks::mock_preference( >+ 'ILLDefaultStaffEmail', >+ 'illstaff@nowhere.com' >+ ); >+ my $email_syspref = $illrq_obj->get_staff_to_address; >+ ok( >+ $email_syspref eq 'illstaff@nowhere.com', >+ 'get_staff_to_address falls back to ILLDefaultStaffEmail when defined' >+ ); >+ # Branch ILL address defined, should use that >+ $builder->delete({ source => 'Branch', records => $illbrn }); >+ $illbrn = $builder->build({ >+ source => 'Branch', >+ value => { >+ branchcode => 'HDE', >+ branchemail => 'branch@nowhere.com', >+ branchillemail => 'branchill@nowhere.com', >+ branchreplyto => "" >+ } >+ }); >+ my $email_branch = $illrq_obj->get_staff_to_address; >+ ok( >+ $email_branch eq 'branchill@nowhere.com', >+ 'get_staff_to_address uses branch ILL address when defined' >+ ); >+ >+ #send_staff_notice >+ # Specify that no staff notices should be send >+ t::lib::Mocks::mock_preference('ILLSendStaffNotices', ''); >+ my $return_staff_cancel_fail = >+ $illrq_obj->send_staff_notice('ILL_REQUEST_CANCEL'); >+ is_deeply( >+ $return_staff_cancel_fail, >+ { error => 'notice_not_enabled' }, >+ "Does not send notices that are not enabled" >+ ); >+ # Specify that the cancel notice can be sent >+ t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL'); >+ my $return_staff_cancel = $illrq_obj->send_staff_notice( >+ 'ILL_REQUEST_CANCEL' >+ ); >+ my $cancel = $schema->resultset('MessageQueue')->search({ >+ letter_code => 'ILL_REQUEST_CANCEL', >+ message_transport_type => 'email', >+ to_address => 'branchill@nowhere.com' >+ })->next()->letter_code; >+ is_deeply( >+ $return_staff_cancel, >+ { success => 'notice_queued' }, >+ "Correct return when staff notice created" >+ ); >+ >+ my $return_staff_fail = $illrq_obj->send_staff_notice(); >+ is_deeply( >+ $return_staff_fail, >+ { error => 'notice_no_type' }, >+ "Correct error when missing type" >+ ); >+ >+ #get_notice >+ my $not = $illrq_obj->get_notice({ >+ notice_code => 'ILL_REQUEST_CANCEL', >+ transport => 'email' >+ }); >+ >+ # We test the properties of the hashref separately because the random >+ # hash ordering of the metadata means we can't test the entire thing >+ # with is_deeply >+ ok( >+ $not->{module} eq 'ill', >+ 'Correct module return from get_notice' >+ ); >+ ok( >+ $not->{name} eq 'ILL request cancelled', >+ 'Correct name return from get_notice' >+ ); >+ ok( >+ $not->{message_transport_type} eq 'email', >+ 'Correct message_transport_type return from get_notice' >+ ); >+ ok( >+ $not->{title} eq 'Interlibrary loan request cancelled', >+ 'Correct title return from get_notice' >+ ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.20.1
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 22818
:
89831
|
89832
|
89833
|
89834
|
89835
|
90063
|
90064
|
90065
|
90066
|
90067
|
90715
|
90716
|
90717
|
90718
|
90719
|
92898
|
92899
|
92900
|
92901
|
92902
|
100234
|
100235
|
100236
|
100237
|
100238
|
103268
|
103269
|
103270
|
103271
|
103272
|
106424
|
106425
|
106426
|
106427
|
106428
|
106675
|
106676
|
106677
|
106678
|
106679
|
106680
|
106681
|
106691
|
106693
|
106694
|
106704
|
106705
|
106706
|
106707
|
106708
|
106709
|
106710
|
106711
|
106712
|
106713
|
110196
|
110197
|
110198
|
110199
|
110201
|
110202
|
110203
|
110204
|
110205
|
110206
|
110207
|
110208
|
111837
|
111838
|
111839
|
111840
|
111841
|
111842
|
111843
|
111844
|
111845
|
111846
|
111847
|
111848
|
111874
|
111880
|
111881
|
111883
|
111884
|
111885
|
111886
|
111887
|
111888
|
111889
|
111890
|
111891
|
111892
|
111893
|
111897
|
111899
|
111900
|
111901
|
111902
|
111903
|
111904
|
111905
|
111906
|
111907
|
111908
|
111909
|
111910
|
111911
|
111912
|
111913
|
113398
|
113399
|
113400
|
113401
|
113402
|
113403
|
113404
|
113405
|
113406
|
113407
|
113408
|
113409
|
113410
|
113411
|
113412
|
113413
|
113463
|
113464
|
113465
|
113466
|
113467
|
113468
|
113469
|
113470
|
113471
|
113472
|
113473
|
113474
|
113475
|
113476
|
113477
|
113478
|
113479
|
113522
|
113549
|
113584