Bugzilla – Attachment 76661 Details for
Bug 21006
GetMarcBiblio is slow for records with many items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21006: Unit tests for GetMarcItems
Bug-21006-Unit-tests-for-GetMarcItems.patch (text/plain), 5.31 KB, created by
Nick Clemens (kidclamp)
on 2018-07-04 01:27:59 UTC
(
hide
)
Description:
Bug 21006: Unit tests for GetMarcItems
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2018-07-04 01:27:59 UTC
Size:
5.31 KB
patch
obsolete
>From 7b679f953d50119f7203ac1fbe5071c5b17efde4 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 4 Jul 2018 01:26:02 +0000 >Subject: [PATCH] Bug 21006: Unit tests for GetMarcItems > >To test: >prove -v t/db_dependent/Items.t >--- > t/db_dependent/Items.t | 98 ++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 96 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index 6fe469e..28a5110 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -32,7 +32,7 @@ use C4::Items; > use t::lib::Mocks; > use t::lib::TestBuilder; > >-use Test::More tests => 15; >+use Test::More tests => 16; > > use Test::Warn; > >@@ -868,7 +868,6 @@ subtest 'tests for GetMarcItem' => sub { > cn_sort => "", > } > }); >- my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber",""); > my $get_itemnumber = $item1->itemnumber; > my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber ); > my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} ); >@@ -881,6 +880,101 @@ subtest 'tests for GetMarcItem' => sub { > > }; > >+subtest 'tests for GetMarcItems' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ #Setup the information we need >+ my $builder = t::lib::TestBuilder->new; >+ my $library = $builder->build({ source => 'Branch', }); >+ my $itemtype = $builder->build({ source => 'Itemtype', }); >+ my $biblio = $builder->build({ >+ source => 'Biblio', >+ value=>{ >+ frameworkcode => "", >+ } >+ }); >+ my $biblioitem = $builder->build({ >+ source => 'Biblioitem', >+ value => { biblionumber => $biblio->{biblionumber} }, >+ }); >+ my @items; >+ my $item1 = $builder->build_object({ >+ class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ itype => $itemtype->{itemtype}, >+ homebranch => $library->{branchcode}, >+ barcode => undef, >+ restricted => 1, >+ itemcallnumber => "", >+ cn_sort => "", >+ withdrawn => 0, >+ } >+ }); >+ push @items, GetItem( $item1->itemnumber ); >+ my $item2 = $builder->build_object({ >+ class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ itype => $itemtype->{itemtype}, >+ homebranch => $library->{branchcode}, >+ barcode => undef, >+ restricted => 1, >+ itemcallnumber => "", >+ cn_sort => "", >+ withdrawn => 0, >+ } >+ }); >+ push @items, GetItem( $item2->itemnumber ); >+ my $item3 = $builder->build_object({ >+ class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ itype => $itemtype->{itemtype}, >+ homebranch => $library->{branchcode}, >+ barcode => undef, >+ restricted => 1, >+ itemcallnumber => "", >+ cn_sort => "", >+ withdrawn => 1, >+ } >+ }); >+ push @items, GetItem( $item3->itemnumber ); >+ >+ #Get the marc for our items individually for comparison later >+ my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber ); >+ my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item2->itemnumber ); >+ my $item3_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item3->itemnumber ); >+ my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber",""); #get itemnumber tag >+ $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it >+ $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match >+ >+ #Testing with hidden items >+ my $opachiddenitems = " >+ withdrawn: [1]"; >+ t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); >+ my @hidden = GetHiddenItemnumbers( @items ); >+ my $marc_items = C4::Items::GetMarcItems( $biblio->{biblionumber}, \@hidden ); >+ @$marc_items[0]->delete_subfield(code => $item_num_subfield); >+ @$marc_items[1]->delete_subfield(code => $item_num_subfield); >+ is(scalar @$marc_items,2,"We should not get a hidden item"); >+ is_deeply( $item1_marc->field($itemtag), @$marc_items[0], "We should get the first item"); >+ is_deeply( $item2_marc->field($itemtag), @$marc_items[1], "We should also get the second item"); >+ >+ #Testing with specified items >+ $marc_items = C4::Items::GetMarcItems( $biblio->{biblionumber}, undef ,[ $item3->itemnumber ] ); >+ is(scalar @$marc_items,1,"We should only get the specifically requested item"); >+ is_deeply( $item3_marc->field($itemtag), @$marc_items[0], "We should get the third item when explicitly requested"); >+ >+ $schema->storage->txn_rollback; >+ >+}; >+ > # Helper method to set up a Biblio. > sub get_biblio { > my ( $frameworkcode ) = @_; >-- >2.1.4
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 21006
:
76475
|
76490
|
76659
|
76660
| 76661