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 <scott@masslibsystem.org> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
b11597b16a
commit
b3d26c4e96
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue