Bug 18837: (follow-up) Add additional tests
authorAndrew Isherwood <andrew.isherwood@ptfs-europe.com>
Fri, 8 Mar 2019 11:28:09 +0000 (11:28 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 15 Mar 2019 19:33:36 +0000 (19:33 +0000)
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 <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

t/db_dependent/Illrequests.t

index 9046852..d3a6808 100644 (file)
@@ -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}),