Bugzilla – Attachment 21125 Details for
Bug 10872
C4::Items GetHiddenItems fix and optimization
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10872: UT for GetHiddenItemnumbers and POD fix
Bug-10872-UT-for-GetHiddenItemnumbers-and-POD-fix.patch (text/plain), 7.78 KB, created by
Tomás Cohen Arazi
on 2013-09-16 18:39:08 UTC
(
hide
)
Description:
Bug 10872: UT for GetHiddenItemnumbers and POD fix
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2013-09-16 18:39:08 UTC
Size:
7.78 KB
patch
obsolete
>From e4860e3e5e67b1fc3111ca60b9d960c03ab90e24 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Mon, 16 Sep 2013 15:29:04 -0300 >Subject: [PATCH] Bug 10872: UT for GetHiddenItemnumbers and POD fix > >This patch adds several unit tests for GetHiddenItemnumbers and fixes the POD for it. >It also wraps the tests for rollback, modernizes and adds a license text to it. > >Regards >To+ > >Sponsored-by: Universidad Nacional de Cordoba >--- > C4/Items.pm | 8 +-- > t/db_dependent/Items.t | 158 +++++++++++++++++++++++++++++++++++++++--------- > 2 files changed, 133 insertions(+), 33 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index 1715724..8116c22 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1617,11 +1617,11 @@ sub GetBarcodeFromItemnumber { > > =head2 GetHiddenItemnumbers > >-=over 4 >- >-$result = GetHiddenItemnumbers(@items); >+ my @itemnumbers_to_hide = GetHiddenItemnumbers(@items); > >-=back >+Given a list of items it checks which should be hidden from the OPAC given >+the current configuration. Returns a list of itemnumbers corresponding to >+those that should be hidden. > > =cut > >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index eff5249..5ec8d34 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -1,47 +1,146 @@ > #!/usr/bin/perl > # >-# This Koha test module is a stub! >-# Add more tests here!!! >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA >+# >+ >+use Modern::Perl; > >-use strict; >-use warnings; > use MARC::Record; > use C4::Biblio; > >-use Test::More tests => 7; >+use Test::More tests => 3; > > BEGIN { > use_ok('C4::Items'); > } > >-# Helper biblio. >-diag("Creating biblio instance for testing."); >-my ($bibnum, $bibitemnum) = get_biblio(); >+my $dbh = C4::Context->dbh; > >-# Add an item. >-my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); >-cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); >-cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); >+subtest 'General Add, Get and Del tests' => sub { > >-# Get item. >-my $getitem = GetItem($itemnumber); >-cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); >-cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); >+ plan tests => 6; > >-# Modify item; setting barcode. >-ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); >-my $moditem = GetItem($itemnumber); >-cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); >+ # Start transaction >+ $dbh->{AutoCommit} = 0; >+ $dbh->{RaiseError} = 1; > >-# Delete item. >-my $dbh = C4::Context->dbh; >-DelItem($dbh, $bibnum, $itemnumber); >-my $getdeleted = GetItem($itemnumber); >-is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); >+ # Helper biblio. >+ diag("Creating biblio instance for testing."); >+ my ($bibnum, $bibitemnum) = get_biblio(); >+ >+ # Add an item. >+ my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); >+ cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); >+ cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); >+ >+ # Get item. >+ my $getitem = GetItem($itemnumber); >+ cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); >+ cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); >+ >+ # Modify item; setting barcode. >+ ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); >+ my $moditem = GetItem($itemnumber); >+ cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); >+ >+ # Delete item. >+ DelItem($dbh, $bibnum, $itemnumber); >+ my $getdeleted = GetItem($itemnumber); >+ is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); >+ >+ $dbh->rollback; >+}; >+ >+subtest 'GetHiddenItemnumbers tests' => sub { >+ >+ plan tests => 9; >+ >+ # This sub is controlled by the OpacHiddenItems system preference. >+ >+ # Start transaction >+ $dbh->{AutoCommit} = 0; >+ $dbh->{RaiseError} = 1; >+ >+ # Create a new biblio >+ my ($biblionumber, $biblioitemnumber) = get_biblio(); >+ >+ # Add two items >+ my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( >+ { homebranch => 'CPL', >+ holdingbranch => 'CPL', >+ withdrawn => 1 }, >+ $biblionumber >+ ); >+ my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem( >+ { homebranch => 'MPL', >+ holdingbranch => 'MPL', >+ withdrawn => 0 }, >+ $biblionumber >+ ); >+ >+ my $opachiddenitems; >+ my @itemnumbers = ($item1_itemnumber,$item2_itemnumber); >+ my @hidden; >+ my @items; >+ push @items, GetItem( $item1_itemnumber ); >+ push @items, GetItem( $item2_itemnumber ); >+ >+ # Empty OpacHiddenItems >+ C4::Context->set_preference('OpacHiddenItems',''); >+ ok( !defined( GetHiddenItemnumbers( @items ) ), >+ "Hidden items list undef if OpacHiddenItems empty"); >+ >+ # Blank spaces >+ C4::Context->set_preference('OpacHiddenItems',' '); >+ ok( scalar GetHiddenItemnumbers( @items ) == 0, >+ "Hidden items list empty if OpacHiddenItems only contains blanks"); >+ >+ # One variable / value >+ $opachiddenitems = " >+ withdrawn: [1]"; >+ C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems ); >+ @hidden = GetHiddenItemnumbers( @items ); >+ ok( scalar @hidden == 1, "Only one hidden item"); >+ is( $hidden[0], $item1_itemnumber, "withdrawn=1 is hidden"); >+ >+ # One variable, two values >+ $opachiddenitems = " >+ withdrawn: [1,0]"; >+ C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems ); >+ @hidden = GetHiddenItemnumbers( @items ); >+ ok( scalar @hidden == 2, "Two items hidden"); >+ is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden"); >+ >+ # Two variables, a value each >+ $opachiddenitems = " >+ withdrawn: [1] >+ homebranch: [MPL] >+ "; >+ C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems ); >+ @hidden = GetHiddenItemnumbers( @items ); >+ ok( scalar @hidden == 2, "Two items hidden"); >+ is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch=MPL hidden"); >+ >+ # Valid OpacHiddenItems, empty list >+ @items = (); >+ @hidden = GetHiddenItemnumbers( @items ); >+ ok( scalar @hidden == 0, "Empty items list, no item hidden"); > >-# Delete helper Biblio. >-diag("Deleting biblio testing instance."); >-DelBiblio($bibnum); >+ $dbh->rollback; >+}; > > # Helper method to set up a Biblio. > sub get_biblio { >@@ -50,5 +149,6 @@ sub get_biblio { > MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), > MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), > ); >- return ($bibnum, $bibitemnum) = AddBiblio($bib, ''); >+ my ($bibnum, $bibitemnum) = AddBiblio($bib, ''); >+ return ($bibnum, $bibitemnum); > } >-- >1.7.9.5
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 10872
:
20973
|
20977
|
21069
|
21075
| 21125