From: Tomas Cohen Arazi Date: Mon, 22 Apr 2019 14:54:21 +0000 (-0300) Subject: Bug 22749: Regression tests for Koha::Item->hidden_in_opac X-Git-Tag: v19.05.00~350 X-Git-Url: http://git.equinoxoli.org/?p=koha.git;a=commitdiff_plain;h=6f4565ce686919ada0bc95ea26497ff80e4df250 Bug 22749: Regression tests for Koha::Item->hidden_in_opac 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 Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 0c8281b..f20c2e7 100644 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -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; };