3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 1;
22 use t::lib::TestBuilder;
24 use C4::Biblio qw( GetMarcSubfieldStructure );
27 use Koha::RecordProcessor;
29 my $schema = Koha::Database->schema();
30 my $builder = t::lib::TestBuilder->new();
32 subtest 'EmbedItems tests' => sub {
36 $schema->storage->txn_begin();
39 my $biblio = $builder->build_sample_biblio;
41 $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
44 my $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 0 } );
45 my $item_tag = $mss->{'items.itemnumber'}[0]->{tagfield};
47 $biblio->discard_changes;
48 my $record = $biblio->metadata->record;
49 my @items = $biblio->items->as_list;
51 my $processor = Koha::RecordProcessor->new(
54 filters => ('EmbedItems'),
60 is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
62 my $result = $processor->process( $record );
63 is( ref($result), 'MARC::Record', 'It returns a reference to a MARC::Record object' );
65 my @item_fields = $record->field($item_tag);
67 is( scalar @item_fields, 10, 'One field for each item has been added' );
69 is( $processor->process(), undef, 'undef returned if no record passed' );
71 $schema->storage->txn_rollback();