Bugzilla – Attachment 174524 Details for
Bug 35604
ILL - Allow for automatic backend selection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35604: Add tests
Bug-35604-Add-tests.patch (text/plain), 9.36 KB, created by
Pedro Amorim
on 2024-11-14 13:01:07 UTC
(
hide
)
Description:
Bug 35604: Add tests
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-11-14 13:01:07 UTC
Size:
9.36 KB
patch
obsolete
>From db4d84f31e067d76cf6c3c8c51ba4f56161faffe Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Wed, 3 Apr 2024 15:51:33 +0000 >Subject: [PATCH] Bug 35604: Add tests > >Test plan: >Apply patches > >Staff: >1) Visit the ILL sysprefs page: >/cgi-bin/koha/admin/preferences.pl?tab=interlibrary_loans >2) Enable ILLModule >3) Check the new AutoILLBackendPriority syspref. Notice it shows "No available backends" >4) Install 2 backend plugins from here: >https://github.com/PTFS-Europe/koha-ill-backend-plugin/releases/tag/v2.0.5 >https://github.com/PTFS-Europe/koha-ill-reprintsdesk/releases/tag/rc-v3.0.0 >5) Repeat 1. Notice the backends now show. >6) Enable both for AutoILLBackendPriority by ticking each respective checkbox. Save. >7) Visit ILL requests: >http://localhost:8081/cgi-bin/koha/ill/ill-requests.pl >8) Press "New auto ILL request" >9) You are presented the "Standard" create form. Pick type "journal" and put '123' on DOI. Enter '42' on cardnumber and pick a library. Click Create. >10) Notice you are now shown the "Confirm auto backend" stage screen. >11) PluginBackend has a 50% chance of being available or not for testing purposes. If it is, it'll suggest PluginBackend, if not, it'll default to Standard. ReprintsDesk will always error because it's missing credentials. >12) Pick any of the backends or accept the suggested one, click 'Create'. The request has been placed in that specific backend. > >OPAC: >1) Following from the previous test plan, visit OPAC ill requests: >http://localhost:8080/cgi-bin/koha/opac-illrequests.pl >2) Click "Create a new auto request" and repeat the same inputs as before. Click 'Create'. >3) Notice you're directed to "Confirming your request" screen. It's doing the same as it does in the Staff UI, except it does not allow the patron to pick a different backend, it'll always selected the first available backend in the priority. >4) Create more requests, you'll notice some of them will land on PluginBackend, others will land on 'Standard' because PluginBackend will sometimes be available and others not. > >Do more testing: >- Reorder the backends in the AutoILLBackendPriority syspref and save, notice they're shown and suggested accordingly after creating a request. >- Disable all backends from AutoILLBackendPriority. Notice the original behaviour of requiring the user to select a backend before creating the request is restored on both opac and staff. > >Run unit tests: >prove t/db_dependent/Illrequest/ConfirmAuto.t >prove t/db_dependent/Koha/ILL/Backends.t > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/Koha/ILL/Backends.t | 84 ++++++++++++++ > .../Koha/ILL/Request/Workflow/ConfirmAuto.t | 104 ++++++++++++++++++ > t/lib/plugins/Koha/Plugin/Test.pm | 5 + > 3 files changed, 193 insertions(+) > create mode 100755 t/db_dependent/Koha/ILL/Backends.t > create mode 100755 t/db_dependent/Koha/ILL/Request/Workflow/ConfirmAuto.t > >diff --git a/t/db_dependent/Koha/ILL/Backends.t b/t/db_dependent/Koha/ILL/Backends.t >new file mode 100755 >index 0000000000..d83cba1c91 >--- /dev/null >+++ b/t/db_dependent/Koha/ILL/Backends.t >@@ -0,0 +1,84 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 Koha Development team >+# >+# 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 File::Basename; >+use File::Path qw(make_path remove_tree); >+use Test::MockModule; >+ >+use Test::More tests => 4; >+ >+use Koha::ILL::Backends; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+BEGIN { >+ # Mock pluginsdir before loading Plugins module >+ my $path = dirname(__FILE__) . '/../../../lib/plugins'; >+ t::lib::Mocks::mock_config( 'pluginsdir', $path ); >+ >+ use_ok('Koha::Plugins'); >+ use_ok('Koha::Plugins::Handler'); >+ use_ok('Koha::Plugin::Test'); >+} >+ >+my $builder = t::lib::TestBuilder->new; >+my $schema = Koha::Database->new->schema; >+ >+t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ >+subtest 'installed_backends() tests' => sub { >+ >+ # dir backend = An ILL backend installed through backend_directory in koha-conf.xml >+ # plugin backend = An ILL backend installed through a plugin >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ # Install a plugin_backend >+ my $plugins = Koha::Plugins->new; >+ $plugins->InstallPlugins; >+ is_deeply( >+ Koha::ILL::Backends->installed_backends, ['Test Plugin'], >+ 'Only one backend installed, happens to be a plugin' >+ ); >+ >+ # Install a dir backend >+ my $dir_backend = '/tmp/ill_backend_test/Old_Backend'; >+ my $ill_config = Test::MockModule->new('Koha::ILL::Request::Config'); >+ $ill_config->mock( >+ 'backend_dir', >+ sub { >+ return '/tmp/ill_backend_test'; >+ } >+ ); >+ make_path($dir_backend); >+ my $installed_backends = Koha::ILL::Backends->installed_backends; >+ is_deeply( >+ $installed_backends, [ 'Old_Backend', 'Test Plugin' ], >+ 'Two backends are installed, one plugin and one directory backend' >+ ); >+ >+ #cleanup >+ remove_tree($dir_backend); >+ Koha::Plugins::Methods->delete; >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/Koha/ILL/Request/Workflow/ConfirmAuto.t b/t/db_dependent/Koha/ILL/Request/Workflow/ConfirmAuto.t >new file mode 100755 >index 0000000000..0f9208abbc >--- /dev/null >+++ b/t/db_dependent/Koha/ILL/Request/Workflow/ConfirmAuto.t >@@ -0,0 +1,104 @@ >+#!/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::More tests => 5; >+ >+use Test::MockModule; >+use Test::MockObject; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::ILL::Request::Workflow::ConfirmAuto; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+use_ok('Koha::ILL::Request::Workflow::ConfirmAuto'); >+ >+my $metadata = { >+ title => 'This is a title', >+ author => 'This is an author' >+}; >+ >+# Because hashes can reorder themselves, we need to make sure ours is in a >+# predictable order >+my $sorted = {}; >+foreach my $key ( keys %{$metadata} ) { >+ $sorted->{$key} = $metadata->{$key}; >+} >+ >+my $confirm_auto = >+ Koha::ILL::Request::Workflow::ConfirmAuto->new( $sorted, 'staff' ); >+ >+isa_ok( $confirm_auto, 'Koha::ILL::Request::Workflow::ConfirmAuto' ); >+ >+is( >+ $confirm_auto->prep_metadata($sorted), >+'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A', >+ 'prep_metadata works' >+); >+ >+# Mock ILLBackend (as object) >+my $backend = Test::MockObject->new; >+$backend->set_isa('Koha::Illbackends::Mock'); >+$backend->set_always( 'name', 'Mock' ); >+$backend->set_always( 'capabilities', sub { return can_create_request => 1 } ); >+$backend->mock( >+ 'metadata', >+ sub { >+ my ( $self, $rq ) = @_; >+ return { >+ ID => $rq->illrequest_id, >+ Title => $rq->patron->borrowernumber >+ }; >+ } >+); >+$backend->mock( 'status_graph', sub { }, ); >+ >+# Mock Koha::ILL::Request::load_backend (to load Mocked Backend) >+my $illreqmodule = Test::MockModule->new('Koha::ILL::Request'); >+$illreqmodule->mock( 'load_backend', >+ sub { my $self = shift; $self->{_my_backend} = $backend; return $self } ); >+ >+# Mock AutoILLBackendPriority enabled >+t::lib::Mocks::mock_preference( 'AutoILLBackendPriority', 'PluginBackend' ); >+ >+my $req_1 = $builder->build_object( >+ { >+ class => 'Koha::ILL::Requests', >+ value => {} >+ } >+); >+ >+my $request = $req_1->load_backend('Mock'); >+ >+is( $confirm_auto->show_confirm_auto($request), >+ 1, 'able to show confirm auto screen' ); >+ >+# Mock AutoILLBackendPriority disabled >+t::lib::Mocks::mock_preference( 'AutoILLBackendPriority', '' ); >+ >+is( $confirm_auto->show_confirm_auto($request), >+ '', 'not able to show confirm auto screen' ); >+ >+$schema->storage->txn_rollback; >diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm >index 7472928fff..b5d5f142d0 100644 >--- a/t/lib/plugins/Koha/Plugin/Test.pm >+++ b/t/lib/plugins/Koha/Plugin/Test.pm >@@ -426,6 +426,11 @@ sub transform_prepared_letter { > Koha::Exception->throw("transform_prepared_letter called with letter content $params->{letter}->{content}"); > } > >+sub ill_backend { >+ my ( $class, $args ) = @_; >+ return 'Test Plugin'; >+} >+ > sub auth_client_get_user { > my ( $self, $params ) = @_; > >-- >2.39.5
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 35604
:
160035
|
164883
|
164884
|
164885
|
164886
|
164887
|
164888
|
165135
|
165164
|
165165
|
165294
|
165295
|
165296
|
165297
|
165298
|
165299
|
165300
|
166897
|
166898
|
166899
|
166900
|
166901
|
166902
|
166903
|
166995
|
166996
|
166997
|
166998
|
166999
|
167000
|
167001
|
171326
|
171327
|
171328
|
171329
|
171330
|
171331
|
171332
|
174515
|
174516
|
174517
|
174518
|
174519
|
174520
|
174521
|
174522
|
174524
|
174792
|
175828
|
175829
|
175830
|
175831
|
175832
|
175833
|
175834
|
175835
|
175836
|
176036
|
176261
|
176262
|
176263
|
176264
|
176265
|
176266
|
176267
|
176268
|
176269
|
176270
|
176572
|
176662
|
176681
|
176682
|
176683
|
176684
|
176685
|
176686
|
176687
|
176688
|
176689
|
176690
|
176691
|
176692