From 0f3928de42c0900f4829d37665b82cdfab318270 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 4 Oct 2017 12:10:13 +0000 Subject: [PATCH] Bug 18201 - Unit tests To test: 1. prove -v t/db_dependent/Exporter/Record.t 2. Tests should pass/be green/make the day a little brighter Signed-off-by: Scott Kehoe --- t/db_dependent/Exporter/Record.t | 69 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Exporter/Record.t b/t/db_dependent/Exporter/Record.t index ac10cbf..6b166ee 100644 --- a/t/db_dependent/Exporter/Record.t +++ b/t/db_dependent/Exporter/Record.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Warn; use t::lib::TestBuilder; @@ -211,5 +211,72 @@ subtest 'export without record_type' => sub { #Depending on your logger config, you might have a warn in your logs }; +subtest '_get_biblio_for_export' => sub { + plan tests => 4; + + my $biblio = MARC::Record->new(); + $biblio->leader('00266nam a22001097a 4500'); + $biblio->append_fields( + MARC::Field->new('100', ' ', ' ', a => 'Thurber, James'), + MARC::Field->new('245', ' ', ' ', a => "The 13 Clocks"), + ); + my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + my $branch_a = $builder->build({ + source => 'Branch', + value => { + } + }); + my $branch_b = $builder->build({ + source => 'Branch', + value => { + } + }); + my $item_branch_a = $builder->build({ + source => 'Item', + value => { + biblionumber => $biblionumber, + homebranch => $branch_a->{branchcode}, + more_subfields_xml => '', + } + }); + my $item_branch_b = $builder->build({ + source => 'Item', + value => { + biblionumber => $biblionumber, + homebranch => $branch_b->{branchcode}, + more_subfields_xml => '', + } + }); + + my $record = Koha::Exporter::Record::_get_biblio_for_export( { + biblionumber => $biblionumber, + export_items => 1, + only_export_items_for_branches => undef + }); + my @items = $record->field('952'); + is(scalar @items,2,"We should retrieve all items if we don't pass specific branches and request items"); + + $record = Koha::Exporter::Record::_get_biblio_for_export( { + biblionumber => $biblionumber, + export_items => 1, + only_export_items_for_branches => [$branch_b->{branchcode}] + }); + @items = $record->field('952'); + is(scalar @items,1,"We should retrieve only item for branch_b item if we request items and pass branch"); + is($items[0]->subfield('a'),$branch_b->{branchcode},"And the homebranch for that item should be branch_b branchcode"); + + $record = Koha::Exporter::Record::_get_biblio_for_export( { + biblionumber => $biblionumber, + export_items => 0, + only_export_items_for_branches => [$branch_b->{branchcode}] + }); + @items = $record->field('952'); + is(@items,0,"We should not have any items if we don't request items and pass a branch"); + +}; + + + + $schema->storage->txn_rollback; -- 2.1.4