Bug 17600: Standardize our EXPORT_OK
[srvgit] / t / db_dependent / Koha / Filter / EmbedItems.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 1;
21
22 use t::lib::TestBuilder;
23
24 use C4::Biblio qw( GetMarcSubfieldStructure );
25
26 use Koha::Database;
27 use Koha::RecordProcessor;
28
29 my $schema  = Koha::Database->schema();
30 my $builder = t::lib::TestBuilder->new();
31
32 subtest 'EmbedItems tests' => sub {
33
34     plan tests => 4;
35
36     $schema->storage->txn_begin();
37
38     # Add a biblio
39     my $biblio = $builder->build_sample_biblio;
40     foreach ( 1 .. 10 ) {
41         $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
42     }
43
44     my $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 0 } );
45     my $item_tag = $mss->{'items.itemnumber'}[0]->{tagfield};
46
47     $biblio->discard_changes;
48     my $record = $biblio->metadata->record;
49     my @items  = $biblio->items->as_list;
50
51     my $processor = Koha::RecordProcessor->new(
52         {
53             schema => 'MARC',
54             filters => ('EmbedItems'),
55             options => {
56                 items => \@items
57             }
58         }
59     );
60     is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
61
62     my $result = $processor->process( $record );
63     is( ref($result), 'MARC::Record', 'It returns a reference to a MARC::Record object' );
64
65     my @item_fields = $record->field($item_tag);
66
67     is( scalar @item_fields, 10, 'One field for each item has been added' );
68
69     is( $processor->process(), undef, 'undef returned if no record passed' );
70
71     $schema->storage->txn_rollback();
72 };