From 9e8c18572b1b6dd36edef72d5e47fd62f0c271d1 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Fri, 8 Mar 2019 11:28:09 +0000 Subject: [PATCH] Bug 18837: (follow-up) Add additional tests As requested by Josef on IRC, we now mock the unmediated_ill backend method and ensure it is called when the ILLModuleUnmediated syspref is enabled and ensure it is not called when the syspref is disabled Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- t/db_dependent/Illrequests.t | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t index 9046852b45..d3a68084bc 100644 --- a/t/db_dependent/Illrequests.t +++ b/t/db_dependent/Illrequests.t @@ -376,7 +376,7 @@ subtest 'Backend testing (mocks)' => sub { subtest 'Backend core methods' => sub { - plan tests => 17; + plan tests => 19; $schema->storage->txn_begin; @@ -384,6 +384,7 @@ subtest 'Backend core methods' => sub { my $backend = Test::MockObject->new; $backend->set_isa('Koha::Illbackends::Mock'); $backend->set_always('name', 'Mock'); + $backend->mock('capabilities', sub { return 'Mock'; }); my $config = Test::MockObject->new; $config->set_always('backend_dir', "/tmp"); @@ -423,6 +424,8 @@ subtest 'Backend core methods' => sub { $backend->set_series('create', { stage => 'bar', method => 'create' }, { stage => 'commit', method => 'create' }, + { stage => 'commit', method => 'create' }, + { stage => 'commit', method => 'create' }, { stage => 'commit', method => 'create' }); # Test non-commit is_deeply($illrq->backend_create({test => 1}), @@ -452,6 +455,45 @@ subtest 'Backend core methods' => sub { "Backend create: arbitrary stage, permitted."); is($illrq->status, "NEW", "Backend create: not-queued."); + # Test that enabling the unmediated workflow causes the backend's + # 'unmediated_ill' method to be called + t::lib::Mocks::mock_preference('ILLModuleUnmediated', '1'); + $backend->mock( + 'capabilities', + sub { + my ($self, $name) = @_; + if ($name eq 'unmediated_ill') { + return sub { + return { unmediated_ill => 1 }; + }; + } + } + ); + $illrq->status('NEW'); + is_deeply( + $illrq->backend_create({test => 1}), + { + 'opac_template' => '/tmp/Mock/opac-includes/.inc', + 'template' => '/tmp/Mock/intra-includes/.inc', + 'unmediated_ill' => 1 + }, + "Backend create: commit stage, permitted, ILLModuleUnmediated enabled." + ); + + # Test that disabling the unmediated workflow causes the backend's + # 'unmediated_ill' method to be NOT called + t::lib::Mocks::mock_preference('ILLModuleUnmediated', '0'); + $illrq->status('NEW'); + is_deeply( + $illrq->backend_create({test => 1}), + { + stage => 'commit', method => 'create', permitted => 1, + template => "/tmp/Mock/intra-includes/create.inc", + opac_template => "/tmp/Mock/opac-includes/create.inc", + }, + "Backend create: commit stage, permitted, ILLModuleUnmediated disabled." + ); + # backend_renew $backend->set_series('renew', { stage => 'bar', method => 'renew' }); is_deeply($illrq->backend_renew({test => 1}), -- 2.39.5