Bugzilla – Attachment 116073 Details for
Bug 24254
Add Koha::Items->filter_by_visible_in_opac
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[20.05.x] Bug 24254: Read the OpacHiddenItems preference internally
2005x-Bug-24254-Read-the-OpacHiddenItems-preferenc.patch (text/plain), 4.71 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-01-29 18:35:20 UTC
(
hide
)
Description:
[20.05.x] Bug 24254: Read the OpacHiddenItems preference internally
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-01-29 18:35:20 UTC
Size:
4.71 KB
patch
obsolete
>From 884ba3f752bdce84321052a4e5d28984ac8670f4 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Sat, 19 Dec 2020 10:21:18 -0300 >Subject: [PATCH] [20.05.x] Bug 24254: Read the OpacHiddenItems preference > internally > >After discussing the 'rules' parameter usefulness we decided it was not >the best idea, and the gains in terms of 'performance' would me >meaningless (in-memory caching of sysprefs). This patch makes a really >minor tweak to the tests so they mock the C4::Context->yaml_preference >method, but keeping the same original rules to highlight no behaviour >change takes place. > >Then the rules parameter is removed from the calls, and the tests should >keep passing. > >A minor change to make $rules = undef is made to highlight the // {} >behaviour when reading the syspref.. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Items.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Items.pm | 7 +++---- > t/db_dependent/Koha/Items.t | 23 +++++++++++++++-------- > 2 files changed, 18 insertions(+), 12 deletions(-) > >diff --git a/Koha/Items.pm b/Koha/Items.pm >index a004dc47aa7..be7889b13a7 100644 >--- a/Koha/Items.pm >+++ b/Koha/Items.pm >@@ -39,18 +39,17 @@ Koha::Items - Koha Item object set class > > =head3 filter_by_visible_in_opac > >- my $filered_items = $items->filter_by_visible_in_opac({ rules => $rules }); >+ my $filered_items = $items->filter_by_visible_in_opac; > > Returns a new resultset, containing those items that are not expected to be hidden in OPAC. >-If no I<rules> are passed, it returns the whole resultset, with the only caveat that the >-I<hidelostitems> system preference is honoured. >+The I<OpacHiddenItems> and I<hidelostitems> system preferences are honoured. > > =cut > > sub filter_by_visible_in_opac { > my ($self, $params) = @_; > >- my $rules = $params->{rules} // {}; >+ my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {}; > > my $rules_params; > foreach my $field (keys %$rules){ >diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t >index 5aa78512352..26480c4302f 100644 >--- a/t/db_dependent/Koha/Items.t >+++ b/t/db_dependent/Koha/Items.t >@@ -303,41 +303,48 @@ subtest 'filter_by_visible_in_opac() tests' => sub { > } > ); > >- my $rules = {}; >+ my $rules = undef; >+ >+ my $mocked_context = Test::MockModule->new('C4::Context'); >+ $mocked_context->mock( 'yaml_preference', sub { >+ return $rules; >+ }); > > t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); > is( $biblio->items->filter_by_visible_in_opac->count, > 6, 'No rules passed, hidelostitems unset' ); > >+ $rules = {}; >+ > t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, >+ $biblio->items->filter_by_visible_in_opac->count, > 3, > 'No rules passed, hidelostitems set' > ); > > $rules = { withdrawn => [ 1, 2 ] }; > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, >+ $biblio->items->filter_by_visible_in_opac->count, > 2, > 'Rules on withdrawn, hidelostitems set' > ); > > $rules = { itype => [ $itype_1->itemtype ] }; > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, >+ $biblio->items->filter_by_visible_in_opac->count, > 2, > 'Rules on itype, hidelostitems set' > ); > > $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] }; > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, >+ $biblio->items->filter_by_visible_in_opac->count, > 1, > 'Rules on itype and withdrawn, hidelostitems set' > ); > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } ) >+ $biblio->items->filter_by_visible_in_opac > ->next->itemnumber, > $item_4->itemnumber, > 'The right item is returned' >@@ -345,12 +352,12 @@ subtest 'filter_by_visible_in_opac() tests' => sub { > > $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] }; > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, >+ $biblio->items->filter_by_visible_in_opac->count, > 1, > 'Rules on itype and withdrawn, hidelostitems set' > ); > is( >- $biblio->items->filter_by_visible_in_opac( { rules => $rules } ) >+ $biblio->items->filter_by_visible_in_opac > ->next->itemnumber, > $item_5->itemnumber, > 'The right item is returned' >-- >2.30.0
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 24254
:
96373
|
114159
|
114160
|
114206
|
114207
|
114278
|
114279
|
114539
|
114540
|
114548
|
114549
|
114550
|
114551
|
114574
|
114594
|
114595
|
114596
|
114597
|
114598
|
114599
|
114664
|
114665
|
114666
|
114667
|
114668
|
115131
|
115132
|
115147
|
115148
|
115149
|
115150
|
115151
|
115152
|
115153
|
116070
|
116071
|
116072
| 116073 |
116074
|
116075