From 5e1964ee804c7f01d54100433258ce0e0f3c2e80 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 10 May 2021 11:17:57 -0300 Subject: [PATCH] Bug 28299: Unit tests for buildKohaItemsNamespace Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/XSLT.t | 61 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 87e00a4bf52..ee2437777f2 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Warn; use t::lib::TestBuilder; use t::lib::Mocks; @@ -125,3 +125,62 @@ subtest 'buildKohaItemsNamespace status tests' => sub { }; $schema->storage->txn_rollback; + +subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { + + plan tests => 14; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio; + + # Have two known libraries for testing purposes + my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); + my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); + + my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_1->id }); + my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_2->id }); + + ## Test passing items_rs only + my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $biblio->items ); + + my $library_1_name = $library_1->branchname; + my $library_2_name = $library_2->branchname; + + like( $xml, qr{$library_1_name}, '$item_1 present in the XML' ); + like( $xml, qr{$library_2_name}, '$item_2 present in the XML' ); + + ## Test passing one item in hidden_items and items_rs + $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $biblio->items ); + + unlike( $xml, qr{$library_1_name}, '$item_1 not present in the XML' ); + like( $xml, qr{$library_2_name}, '$item_2 present in the XML' ); + + ## Test passing both items in hidden_items and items_rs + $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $biblio->items ); + + unlike( $xml, qr{$library_1_name}, '$item_1 not present in the XML' ); + unlike( $xml, qr{$library_2_name}, '$item_2 present in the XML' ); + is( $xml, '', 'Empty XML' ); + + ## Test passing both items in hidden_items and no items_rs + $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ] ); + + unlike( $xml, qr{$library_1_name}, '$item_1 not present in the XML' ); + unlike( $xml, qr{$library_2_name}, '$item_2 present in the XML' ); + is( $xml, '', 'Empty XML' ); + + ## Test passing one item in hidden_items and items_rs + $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] ); + + unlike( $xml, qr{$library_1_name}, '$item_1 not present in the XML' ); + like( $xml, qr{$library_2_name}, '$item_2 present in the XML' ); + + ## Test not passing any param + $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber ); + + like( $xml, qr{$library_1_name}, '$item_1 present in the XML' ); + like( $xml, qr{$library_2_name}, '$item_2 present in the XML' ); + + $schema->storage->txn_rollback; +}; -- 2.31.1