Bugzilla – Attachment 134628 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.67 KB, created by
Andrew Isherwood
on 2022-05-05 09:22:49 UTC
(
hide
)
Description:
Bug 30484: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2022-05-05 09:22:49 UTC
Size:
7.67 KB
patch
obsolete
>From 6f480b61d870a286f77891a49bc506a0afb0502e 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 | 64 +++++++++++++++++ > .../Illrequest/SupplierUpdateProcessor.t | 37 ++++++++++ > t/db_dependent/Illrequests.t | 68 ++++++++++++++++++- > 3 files changed, 167 insertions(+), 2 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..72d2fc280e >--- /dev/null >+++ b/t/db_dependent/Illrequest/SupplierUpdate.t >@@ -0,0 +1,64 @@ >+#!/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, $options, $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..5577fb417c >--- /dev/null >+++ b/t/db_dependent/Illrequest/SupplierUpdateProcessor.t >@@ -0,0 +1,37 @@ >+#!/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 5f4f25cdcc..52c1f56934 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 => 18; >+ plan tests => 19; > > $schema->storage->txn_begin; > >@@ -794,6 +794,18 @@ subtest 'Backend core methods' => sub { > }, > "Backend confirm: arbitrary stage."); > >+ # backend_get_update >+ $backend->mock( >+ 'get_supplier_update', >+ sub { >+ my ( $self, $options ) = @_; >+ return $options; >+ } >+ ); >+ $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({ >@@ -833,7 +845,7 @@ subtest 'Backend core methods' => sub { > > subtest 'Helpers' => sub { > >- plan tests => 21; >+ plan tests => 25; > > $schema->storage->txn_begin; > >@@ -877,6 +889,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" }, >@@ -928,6 +964,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, >@@ -1008,6 +1065,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; > }; > >-- >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