Bugzilla – Attachment 133401 Details for
Bug 30484
Interlibrary loans should have the ability to send notices based on request supplier updates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30484: Add unit tests
Bug-30484-Add-unit-tests.patch (text/plain), 7.86 KB, created by
Andrew Isherwood
on 2022-04-19 11:02:36 UTC
(
hide
)
Description:
Bug 30484: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2022-04-19 11:02:36 UTC
Size:
7.86 KB
patch
obsolete
>From 5b12e038db2f2ef10aa7429669b9f0c18fc3e69b Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Wed, 13 Apr 2022 11:30:40 +0100 >Subject: [PATCH] Bug 30484: Add unit tests > >--- > t/db_dependent/Illrequest/SupplierUpdate.t | 65 +++++++++++++++++ > .../Illrequest/SupplierUpdateProcessor.t | 38 ++++++++++ > t/db_dependent/Illrequests.t | 72 ++++++++++++++++++- > 3 files changed, 172 insertions(+), 3 deletions(-) > create mode 100755 t/db_dependent/Illrequest/SupplierUpdate.t > create mode 100755 t/db_dependent/Illrequest/SupplierUpdateProcessor.t > >diff --git a/t/db_dependent/Illrequest/SupplierUpdate.t b/t/db_dependent/Illrequest/SupplierUpdate.t >new file mode 100755 >index 0000000000..c6902dbb43 >--- /dev/null >+++ b/t/db_dependent/Illrequest/SupplierUpdate.t >@@ -0,0 +1,65 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::MockObject; >+ >+use Koha::Illrequest; >+use Koha::Illrequest::SupplierUpdate; >+ >+use Test::More tests => 4; >+ >+use_ok('Koha::Illrequest::SupplierUpdate'); >+ >+my $update = Koha::Illrequest::SupplierUpdate->new( >+ 'test_type', >+ 'test_name', >+ 'Arbitrary update text' >+); >+ >+isa_ok( $update, 'Koha::Illrequest::SupplierUpdate' ); >+ >+my $processor = Test::MockObject->new; >+$processor->set_isa('Koha::Illrequest::Processor'); >+$processor->{name} = 'Test processor'; >+$processor->mock('run', sub { >+ my ( $self, $update, $result ) = @_; >+ push @{$result->{success}}, 'Hello'; >+}); >+ >+# attach_processor >+$update->attach_processor($processor); >+is( >+ scalar @{$update->{processors}}, >+ 1, >+ 'attach_processors works' >+); >+ >+# run_processors >+is_deeply( >+ $update->run_processors(), >+ [{ >+ name => 'Test processor', >+ result => { >+ success => ['Hello'], >+ error => [] >+ } >+ }], >+ 'run_processors calls attached processors' >+); >+ >diff --git a/t/db_dependent/Illrequest/SupplierUpdateProcessor.t b/t/db_dependent/Illrequest/SupplierUpdateProcessor.t >new file mode 100755 >index 0000000000..7e2bca6782 >--- /dev/null >+++ b/t/db_dependent/Illrequest/SupplierUpdateProcessor.t >@@ -0,0 +1,38 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Illrequest::SupplierUpdateProcessor; >+ >+use Test::More tests => 3; >+use Test::Warn; >+ >+my $processor = Koha::Illrequest::SupplierUpdateProcessor->new( >+ 'test_type', >+ 'test_name', >+ 'Test processor name' >+); >+ >+use_ok('Koha::Illrequest::SupplierUpdateProcessor'); >+ >+isa_ok( $processor, 'Koha::Illrequest::SupplierUpdateProcessor' ); >+ >+warning_like { >+ $processor->run() >+} qr/run should only be invoked by a subclass/, 'Invoking base class "run" warns'; >+ >diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t >index df8ebbdecb..9267599ebc 100755 >--- a/t/db_dependent/Illrequests.t >+++ b/t/db_dependent/Illrequests.t >@@ -636,7 +636,7 @@ subtest 'Backend testing (mocks)' => sub { > > subtest 'Backend core methods' => sub { > >- plan tests => 19; >+ plan tests => 20; > > $schema->storage->txn_begin; > >@@ -799,6 +799,20 @@ subtest 'Backend core methods' => sub { > }, > "Backend confirm: arbitrary stage."); > >+ # backend_get_update >+ $backend->mock( >+ 'get_supplier_update', >+ sub { >+ my ( $self, $delay ) = @_; >+ return { >+ delay => $delay >+ } >+ } >+ ); >+ $backend->mock('capabilities', sub { return sub { return 1; } }); >+ is_deeply($illrq->backend_get_update(), 1, >+ "Backend get_update method."); >+ > $config->set_always('partner_code', "ILLTSTLIB"); > $backend->set_always('metadata', { Test => "Foobar" }); > my $illbrn = $builder->build({ >@@ -838,7 +852,7 @@ subtest 'Backend core methods' => sub { > > subtest 'Helpers' => sub { > >- plan tests => 21; >+ plan tests => 25; > > $schema->storage->txn_begin; > >@@ -882,6 +896,30 @@ subtest 'Helpers' => sub { > $illrq_obj->_config($config); > $illrq_obj->_backend($backend); > >+ #attach_processors >+ my $type = 'test_type_1'; >+ my $name = 'test_name_1'; >+ my $update = Test::MockObject->new; >+ $update->set_isa('Koha::Illrequest::SupplierUpdate'); >+ $update->{source_type} = $type; >+ $update->{source_name} = $name; >+ $update->{processors} = []; >+ $update->mock('attach_processor', sub { >+ my ( $self, $to_attach ) = @_; >+ push @{$self->{processors}}, $to_attach; >+ }); >+ my $processor = Test::MockObject->new; >+ $processor->{target_source_type} = $type; >+ $processor->{target_source_name} = $name; >+ $illrq_obj->init_processors(); >+ $illrq_obj->push_processor($processor); >+ $illrq_obj->attach_processors($update); >+ is_deeply( >+ scalar @{$update->{processors}}, >+ 1, >+ 'attaching processors as appropriate works' >+ ); >+ > # getPrefix > $config->set_series('getPrefixes', > { HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, >@@ -933,6 +971,27 @@ subtest 'Helpers' => sub { > ); > is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created"); > >+ # ill update notice, passes additional text parameter >+ my $attr_update = Koha::MessageAttributes->find({ message_name => 'Ill_update' }); >+ C4::Members::Messaging::SetMessagingPreference({ >+ borrowernumber => $patron->{borrowernumber}, >+ message_attribute_id => $attr_update->message_attribute_id, >+ message_transport_types => ['email'] >+ }); >+ my $return_patron_update = $illrq_obj->send_patron_notice('ILL_REQUEST_UPDATE', 'Some additional text'); >+ my $notice_update = $schema->resultset('MessageQueue')->search({ >+ letter_code => 'ILL_REQUEST_UPDATE', >+ message_transport_type => 'email', >+ borrowernumber => $illrq_obj->borrowernumber >+ })->next()->letter_code; >+ is_deeply( >+ $return_patron_update, >+ { result => { success => ['email'], fail => [] } }, >+ "Correct return when notice created" >+ ); >+ is($notice_update, 'ILL_REQUEST_UPDATE' ,"Notice is correctly created"); >+ >+ > my $return_patron_fail = $illrq_obj->send_patron_notice(); > is_deeply( > $return_patron_fail, >@@ -1013,6 +1072,13 @@ subtest 'Helpers' => sub { > 'Correct content returned from get_notice with metadata correctly ordered' > ); > >+ $illrq_obj->append_to_note('Some text'); >+ like( >+ $illrq_obj->notesstaff, >+ qr/Some text$/, >+ 'appending to a note works' >+ ); >+ > $schema->storage->txn_rollback; > }; > >@@ -1460,4 +1526,4 @@ subtest 'Checking in hook' => sub { > is( $illrq->status, 'RET' ); > > $schema->storage->txn_rollback; >-}; >+}; >\ No newline at end of file >-- >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 30484
:
133394
|
133395
|
133396
|
133399
|
133400
|
133401
|
134486
|
134487
|
134488
|
134569
|
134570
|
134571
|
134572
|
134573
|
134574
|
134626
|
134627
|
134628
|
138859
|
138860
|
138861
|
138862