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>.
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;
40 [ '150', ' ', ' ', a
=> 'Cooking' ],
41 [ '450', ' ', ' ', a
=> 'Cookery' ],
47 my $bib = MARC
::Record
->new;
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 {
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::Authority');
86 $koha_authority->mock( 'get_from_authid', sub {
88 my $auth_record = MARC
::Record
->new;
90 $auth_record->add_fields(
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');