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;
26 use C4::Biblio qw/AddBiblio GetMarcBiblio/;
28 use Koha::RecordProcessor;
30 my $schema = Koha::Database->schema();
31 my $builder = t::lib::TestBuilder->new();
33 subtest 'EmbedItemsAvailability tests' => sub {
37 $schema->storage->txn_begin();
40 t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
41 # Create a dummy record
42 my ( $biblionumber, $biblioitemnumber ) = AddBiblio(MARC::Record->new(), '');
44 # Add some items with different onloan values
48 biblionumber => $biblionumber,
49 biblioitemnumber => $biblioitemnumber,
50 onloan => '2017-01-01'
57 biblionumber => $biblionumber,
58 biblioitemnumber => $biblioitemnumber,
66 biblionumber => $biblionumber,
67 biblioitemnumber => $biblioitemnumber,
68 onloan => '2017-01-02'
73 my $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } );
74 is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
76 my $record = GetMarcBiblio($biblionumber);
77 ok( !defined $record->field('999')->subfield('x'), q{The record doesn't originally contain 999$x} );
79 $processor->process($record);
80 is($record->field('999')->subfield('x'), 1, 'There is only one item with undef onloan');
82 $schema->storage->txn_rollback();
84 # UNIMARC tests (999 is not created)
85 t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
87 $schema->storage->txn_begin();
89 # Create a dummy record
90 ( $biblionumber, $biblioitemnumber ) = AddBiblio(MARC::Record->new(), '');
92 # Add some items with different onloan values
96 biblionumber => $biblionumber,
97 biblioitemnumber => $biblioitemnumber,
98 onloan => '2017-01-01'
105 biblionumber => $biblionumber,
106 biblioitemnumber => $biblioitemnumber,
114 biblionumber => $biblionumber,
115 biblioitemnumber => $biblioitemnumber,
116 onloan => '2017-01-02'
121 $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } );
122 is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
124 $record = GetMarcBiblio($biblionumber);
125 ok( !defined $record->field('999')->subfield('x'), q{The record doesn't originally contain 999$x} );
127 $processor->process($record);
128 is($record->field('999')->subfield('x'), 1, 'There is only one item with undef onloan');
130 $schema->storage->txn_rollback();