Bugzilla – Attachment 138861 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.59 KB, created by
Katrin Fischer
on 2022-08-08 21:01:30 UTC
(
hide
)
Description:
Bug 30484: Add unit tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2022-08-08 21:01:30 UTC
Size:
7.59 KB
patch
obsolete
>From 012eedebf98cbf3609241d29c1f0ab3a079d85b1 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 > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> > >https://bugs.koha-community.org/show_bug.cgi?id=28909 >--- > t/db_dependent/Illrequest/SupplierUpdate.t | 64 ++++++++++++++++++ > .../Illrequest/SupplierUpdateProcessor.t | 37 +++++++++++ > t/db_dependent/Illrequests.t | 66 ++++++++++++++++++- > 3 files changed, 166 insertions(+), 1 deletion(-) > 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 ccd6b98949..d3b1ab2f20 100755 >--- a/t/db_dependent/Illrequests.t >+++ b/t/db_dependent/Illrequests.t >@@ -799,6 +799,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({ >@@ -838,7 +850,7 @@ subtest 'Backend core methods' => sub { > > subtest 'Helpers' => sub { > >- plan tests => 21; >+ plan tests => 25; > > $schema->storage->txn_begin; > >@@ -882,6 +894,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 +969,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 +1070,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.30.2
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