Bug 9259: Use is instead of is_deeply
[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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use strict;
21 use warnings;
22 use File::Spec;
23 use MARC::Record;
24 use Koha::MetadataRecord::Authority;
25
26 use Test::More;
27 use Test::MockModule;
28 use Test::MockObject;
29
30 BEGIN {
31         use_ok('Koha::RecordProcessor');
32 }
33
34 my $module = new Test::MockModule('MARC::Record');
35 $module->mock('new_from_xml', sub {
36     my $record = MARC::Record->new;
37
38     $record->add_fields(
39         [ '001', '1234' ],
40         [ '150', ' ', ' ', a => 'Cooking' ],
41         [ '450', ' ', ' ', a => 'Cookery' ],
42         );
43
44     return $record;
45 });
46
47 my $bib = MARC::Record->new;
48 $bib->add_fields(
49     [ '245', '0', '4', a => 'The Ifrane cookbook' ],
50     [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ]
51     );
52
53 my $resultbib = MARC::Record->new;
54 $resultbib->add_fields(
55     [ '245', '0', '4', a => 'The Ifrane cookbook' ],
56     [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ],
57     [ '650', 'z', ' ', a => 'Cookery' ]
58     );
59
60 my $processor = Koha::RecordProcessor->new( { filters => ( 'EmbedSeeFromHeadings' ) } );
61 is(ref($processor), 'Koha::RecordProcessor', 'Created record processor');
62
63 my $result = $processor->process($bib);
64
65 is_deeply($result, $resultbib, 'Inserted see-from heading to record');
66
67
68 subtest "EmbedSeeFromHeadings should skip holdings fields" => sub {
69
70     plan tests => 1;
71
72     my $biblio_record = MARC::Record->new;
73     $biblio_record->add_fields(
74         [ '245', '0', '4', a => 'The Ifrane cookbook' ],
75         [ '952', ' ', ' ', a => 'Cooking', 9 => '1234' ]
76     );
77
78     my $record_copy = MARC::Record->new;
79     $record_copy->add_fields(
80         [ '245', '0', '4', a => 'The Ifrane cookbook' ],
81         [ '952', ' ', ' ', a => 'Cooking', 9 => '1234' ]
82     );
83
84
85     my $koha_authority = new Test::MockModule('Koha::MetadataRecord::Authority');
86     $koha_authority->mock( 'get_from_authid', sub {
87
88         my $auth_record = MARC::Record->new;
89
90         $auth_record->add_fields(
91             [ '001', '1234' ],
92             [ '150', ' ', ' ', a => 'Cooking' ],
93             [ '450', ' ', ' ', a => 'Cookery' ],
94         );
95
96         my $authority_object = Test::MockObject->new();
97         $authority_object->mock( 'authid',   sub { return '1234'; });
98         $authority_object->mock( 'authtype', sub { return 'TOPIC_TERM'; });
99         $authority_object->mock( 'schema',   sub { return 'marc21'; });
100         $authority_object->mock( 'record',   sub { return $auth_record; });
101
102         return $authority_object;
103     });
104
105     my $processor = Koha::RecordProcessor->new({
106             filters => ( 'EmbedSeeFromHeadings' )
107     });
108
109     my $result = $processor->process($biblio_record);
110
111     is_deeply($result, $record_copy, 'Holdings fields not processed to introduce See-from heading');
112 };
113
114 done_testing();