Bug 15870: MARC Filter to exclude fields/subfields lacking visibility
[koha.git] / t / db_dependent / RecordProcessor_ViewPolicy.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2015 Mark Tompsett
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 Modern::Perl;
21 use MARC::Record;
22 use MARC::Field;
23 use Test::More;
24 use C4::Context;
25 use Koha::Database;
26 use Data::Dumper;
27
28 BEGIN {
29     use_ok('Koha::RecordProcessor');
30 }
31
32 our $VERSION = '3.23';    # Master version that I hope it gets in.
33
34 my $dbh = C4::Context->dbh;
35
36 my $database = Koha::Database->new();
37 my $schema   = $database->schema();
38 $schema->storage->txn_begin();
39
40 $dbh->{RaiseError} = 1;
41
42 $dbh->do(q{UPDATE marc_subfield_structure SET hidden=2 WHERE tagfield='020';});
43
44 my $isbn        = '0590353403';
45 my $title       = 'Foundation';
46 my $marc_record = MARC::Record->new;
47 my $field       = MARC::Field->new( '020', q{}, q{}, 'a' => $isbn );
48 $marc_record->append_fields($field);
49 $field = MARC::Field->new( '245', q{}, q{}, 'a' => $title );
50 $marc_record->append_fields($field);
51
52 my $processor = Koha::RecordProcessor->new(
53     { filters => ('ViewPolicy'), options => { 'test' => 'value1' } } );
54 is(
55     ref( $processor->filters->[0] ),
56     'Koha::Filter::MARC::ViewPolicy',
57     'Created record processor with implicitly scoped ViewPolicy filter'
58 );
59 my $after_record    = $processor->process($marc_record);
60 my $modified_record = $marc_record->clone;
61 my @isbn            = $modified_record->field('020');
62 $modified_record->delete_fields(@isbn);
63 is_deeply( $modified_record, $after_record,
64     'Filtered and modified MARC record match' );
65
66 $schema->storage->txn_rollback();
67
68 done_testing();