Merge remote-tracking branch 'origin/new/bug_8520'
[koha.git] / t / db_dependent / RecordProcessor_EmbedSeeFromHeadings.t
1 #!/usr/bin/perl
2
3 # Copyright 2012 C & P Bibliography Services
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22 use File::Spec;
23 use MARC::Record;
24 use Koha::Authority;
25
26 use Test::More;
27 use Test::MockModule;
28
29 BEGIN {
30         use_ok('Koha::RecordProcessor');
31 }
32
33 my $module = new Test::MockModule('MARC::Record');
34 $module->mock('new_from_xml', sub {
35     my $record = MARC::Record->new;
36
37     $record->add_fields(
38         [ '001', '1234' ],
39         [ '150', ' ', ' ', a => 'Cooking' ],
40         [ '450', ' ', ' ', a => 'Cookery' ],
41         );
42
43     return $record;
44 });
45
46 my $bib = MARC::Record->new;
47 $bib->add_fields(
48     [ '245', '0', '4', a => 'The Ifrane cookbook' ],
49     [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ]
50     );
51
52 my $resultbib = MARC::Record->new;
53 $resultbib->add_fields(
54     [ '245', '0', '4', a => 'The Ifrane cookbook' ],
55     [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ],
56     [ '650', 'z', ' ', a => 'Cookery' ]
57     );
58
59 my $processor = Koha::RecordProcessor->new( { filters => ( 'EmbedSeeFromHeadings' ) } );
60 is(ref($processor), 'Koha::RecordProcessor', 'Created record processor');
61
62 my $result = $processor->process($bib);
63
64 is_deeply($result, $resultbib, 'Inserted see-from heading to record');
65
66 done_testing();