From 001cee47e92e0ddbed62d3a7c65d84b04f4f85e2 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 3 Jul 2018 17:05:21 +0000 Subject: [PATCH] Bug 20664: Add unit tests for GetMarcItem To test: prove -v t/db_dependent/Items.t Signed-off-by: Josef Moravec Signed-off-by: Martin Renvoize --- t/db_dependent/Items.t | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 9198ebc5d5..9261651cff 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -34,7 +34,7 @@ use Koha::AuthorisedValues; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 15; +use Test::More tests => 16; use Test::Warn; @@ -992,3 +992,45 @@ subtest 'Split subfields in Item2Marc (Bug 21774)' => sub { $schema->storage->txn_rollback; }; + +subtest 'tests for GetMarcItem' => sub { + plan tests => 1; + $schema->storage->txn_begin; + + 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 $item1 = $builder->build_object({ + class => 'Koha::Items', + value => { + biblionumber => $biblio->{biblionumber}, + biblioitemnumber => $biblioitem->{biblioitemnumber}, + itype => $itemtype->{itype}, + homebranch => $library->{branchcode}, + barcode => undef, + restricted => 1, + itemcallnumber => "", + 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} ); + my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 ); + ($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 + is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same"); + $schema->storage->txn_rollback; +}; -- 2.17.1