Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / t / db_dependent / RecordProcessor_EmbedSeeFromHeadings.t
blob664a0fa0c7a9fff99b7ee7f1190c7814810a7dbf
1 #!/usr/bin/perl
3 # Copyright 2012 C & P Bibliography Services
5 # This file is part of Koha.
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.
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.
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>.
20 use strict;
21 use warnings;
22 use File::Spec;
23 use MARC::Record;
24 use Koha::MetadataRecord::Authority;
26 use Test::More;
27 use Test::MockModule;
28 use Test::MockObject;
30 BEGIN {
31 use_ok('Koha::RecordProcessor');
34 my $module = new Test::MockModule('MARC::Record');
35 $module->mock('new_from_xml', sub {
36 my $record = MARC::Record->new;
38 $record->add_fields(
39 [ '001', '1234' ],
40 [ '150', ' ', ' ', a => 'Cooking' ],
41 [ '450', ' ', ' ', a => 'Cookery' ],
44 return $record;
45 });
47 my $bib = MARC::Record->new;
48 $bib->add_fields(
49 [ '245', '0', '4', a => 'The Ifrane cookbook' ],
50 [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ]
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' ]
60 my $processor = Koha::RecordProcessor->new( { filters => ( 'EmbedSeeFromHeadings' ) } );
61 is(ref($processor), 'Koha::RecordProcessor', 'Created record processor');
63 my $result = $processor->process($bib);
65 is_deeply($result, $resultbib, 'Inserted see-from heading to record');
68 subtest "EmbedSeeFromHeadings should skip holdings fields" => sub {
70 plan tests => 1;
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' ]
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' ]
85 my $koha_authority = new Test::MockModule('Koha::MetadataRecord::Authority');
86 $koha_authority->mock( 'get_from_authid', sub {
88 my $auth_record = MARC::Record->new;
90 $auth_record->add_fields(
91 [ '001', '1234' ],
92 [ '150', ' ', ' ', a => 'Cooking' ],
93 [ '450', ' ', ' ', a => 'Cookery' ],
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; });
102 return $authority_object;
105 my $processor = Koha::RecordProcessor->new({
106 filters => ( 'EmbedSeeFromHeadings' )
109 my $result = $processor->process($biblio_record);
111 is_deeply($result, $record_copy, 'Holdings fields not processed to introduce See-from heading');
114 done_testing();