Bug 22749: Regression tests for Koha::Item->hidden_in_opac
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 22 Apr 2019 14:54:21 +0000 (11:54 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 24 Apr 2019 10:39:55 +0000 (10:39 +0000)
This patch introduces regression tests for Koha::Item->hidden_in_opac to
verify it is not considering the hidelostitems syspref when determining
if an item should be hidden (per policy) in the OPAC.

To test:
- Apply this patch
- Run:
  $ kshell
 k$ prove t/db_dependent/Koha/Item.t
=> FAIL: Tests fail!

Signed-off-by: Liz Rea <wizzyrea@gmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

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

t/db_dependent/Koha/Item.t

index 0c8281b..f20c2e7 100644 (file)
@@ -32,21 +32,32 @@ my $builder = t::lib::TestBuilder->new;
 
 subtest 'hidden_in_opac() tests' => sub {
 
-    plan tests => 3;
+    plan tests => 4;
 
     $schema->storage->txn_begin;
 
-    my $item  = $builder->build_sample_item;
+    my $item  = $builder->build_sample_item({ itemlost => 2 });
     my $rules = {};
 
+    # disable hidelostitems as it interteres with OpachiddenItems for the calculation
+    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
+
     ok( !$item->hidden_in_opac, 'No rules passed, shouldn\'t hide' );
     ok( !$item->hidden_in_opac({ rules => $rules }), 'Empty rules passed, shouldn\'t hide' );
 
+    # enable hidelostitems to verify correct behaviour
+    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
+    ok( $item->hidden_in_opac, 'Even with no rules, item should hide because of hidelostitems syspref' );
+
+    # disable hidelostitems
+    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
     my $withdrawn = $item->withdrawn + 1; # make sure this attribute doesn't match
 
     $rules = { withdrawn => [$withdrawn], itype => [ $item->itype ] };
 
     ok( $item->hidden_in_opac({ rules => $rules }), 'Rule matching itype passed, should hide' );
 
+
+
     $schema->storage->txn_rollback;
 };