Revert "Bug 15187: (QA follow-up) Fix test permissions"
[koha.git] / t / db_dependent / Koha / Filter / Index880InZebra.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use utf8;
19 use Modern::Perl;
20
21 use Test::More tests => 1;
22
23 use t::lib::TestBuilder;
24
25 use Koha::Database;
26 use Koha::RecordProcessor;
27
28 my $schema  = Koha::Database->schema();
29 my $builder = t::lib::TestBuilder->new();
30
31 subtest 'Index880InZebra tests' => sub {
32
33     plan tests => 10;
34
35     $schema->storage->txn_begin();
36
37     # Add a biblio
38     my $biblio = $builder->build_sample_biblio({ title => 'Pastoral epistles' });
39     my $record = $biblio->metadata->record;
40
41     # Add an 880 alternate
42     $record->append_fields(
43         MARC::Field->new( '880', '', '', 6 => '245-01', a => '教牧書信' ),
44     );
45
46     my @fields_245 = $record->field('245');
47     is( @fields_245, 1, 'One title (245) field present before filtering');
48     is( $fields_245[0]->subfield('a'), 'Pastoral epistles', 'First 245 contains english title before filtering');
49
50     my @fields_880 = $record->field('880');
51     is( @fields_880, 1, 'One alternate graphic represnetation (880) field present before filtering');
52     is( $fields_880[0]->subfield('a'), '教牧書信', 'Alternate graphic represnations contains chinese characters prior to filtering' );
53
54     my $processor = Koha::RecordProcessor->new(
55         {
56             schema  => 'MARC',
57             filters => ['Index880InZebra'],
58         }
59     );
60     is( ref($processor), 'Koha::RecordProcessor', 'Created record processor with Index880InZebra filter' );
61
62     my $result = $processor->process( $record );
63     is( ref($result), 'MARC::Record', 'It returns a reference to a MARC::Record object' );
64
65     @fields_245 = $result->field('245');
66     is( @fields_245, 2, 'Two title (245) fields present after filtering');
67     is( $fields_245[0]->subfield('a'), 'Pastoral epistles', 'First 245 contains english title after filtering');
68     is( $fields_245[1]->subfield('a'), '教牧書信', 'Second 245 contains chinese title from 880 after filtering' );
69
70     @fields_880 = $result->field('880');
71     is( @fields_880, 0, 'No alternate graphic represnetation (880) fields present after filtering');
72
73     $schema->storage->txn_rollback();
74 };