|
Line 0
Link Here
|
| 0 |
- |
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 Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 1; |
| 21 |
|
| 22 |
use t::lib::TestBuilder; |
| 23 |
|
| 24 |
use C4::Biblio qw( GetMarcSubfieldStructure ); |
| 25 |
|
| 26 |
use Koha::Database; |
| 27 |
|
| 28 |
use Koha::AuthorisedValueCategory; |
| 29 |
use Koha::Caches; |
| 30 |
|
| 31 |
use Koha::RecordProcessor; |
| 32 |
|
| 33 |
my $schema = Koha::Database->schema(); |
| 34 |
my $builder = t::lib::TestBuilder->new(); |
| 35 |
|
| 36 |
subtest 'ExpandAuthorizedValues tests' => sub { |
| 37 |
|
| 38 |
plan tests => 10; |
| 39 |
|
| 40 |
$schema->storage->txn_begin(); |
| 41 |
|
| 42 |
# Add a biblio |
| 43 |
my $biblio = $builder->build_sample_biblio; |
| 44 |
my $record = $biblio->metadata->record; |
| 45 |
$record->field('942')->update( n => 1 ); |
| 46 |
$record->append_fields( |
| 47 |
MARC::Field->new( '590', '', '', a => 'CODE' ), |
| 48 |
); |
| 49 |
|
| 50 |
Koha::AuthorisedValueCategory->new({ category_name => 'TEST' })->store; |
| 51 |
Koha::AuthorisedValue->new( |
| 52 |
{ |
| 53 |
category => 'TEST', |
| 54 |
authorised_value => 'CODE', |
| 55 |
lib => 'Description should show', |
| 56 |
lib_opac => 'Description should show OPAC' |
| 57 |
} |
| 58 |
)->store; |
| 59 |
my $mss = Koha::MarcSubfieldStructures->find({tagfield => "590", tagsubfield => "a", frameworkcode => $biblio->frameworkcode }); |
| 60 |
$mss->update({ authorised_value => "TEST" }); |
| 61 |
|
| 62 |
my $cache = Koha::Caches->get_instance; |
| 63 |
$cache->clear_from_cache("MarcStructure-0-"); |
| 64 |
$cache->clear_from_cache("MarcStructure-1-"); |
| 65 |
$cache->clear_from_cache("default_value_for_mod_marc-"); |
| 66 |
$cache->clear_from_cache("MarcSubfieldStructure-"); |
| 67 |
|
| 68 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
| 69 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
| 70 |
$record = $biblio->metadata->record; |
| 71 |
|
| 72 |
is( $record->field('590')->subfield('a'), 'CODE', 'Record prior to filtering contains AV Code' ); |
| 73 |
is( $record->field('942')->subfield('n'), 1, 'Record suppression is numeric prior to filtering' ); |
| 74 |
|
| 75 |
my $processor = Koha::RecordProcessor->new( |
| 76 |
{ |
| 77 |
schema => 'MARC', |
| 78 |
filters => ['ExpandAuthorizedValues'], |
| 79 |
} |
| 80 |
); |
| 81 |
is( ref($processor), 'Koha::RecordProcessor', 'Created record processor with ExpandAuthorizedValues filter' ); |
| 82 |
|
| 83 |
my $result = $processor->process( $record ); |
| 84 |
is( ref($result), 'MARC::Record', 'It returns a reference to a MARC::Record object' ); |
| 85 |
is( $result->field('590')->subfield('a'), 'Description should show OPAC', 'Returned record contains AV OPAC description (interface defaults to opac)' ); |
| 86 |
is( $record->field('590')->subfield('a'), 'Description should show OPAC', 'Original record now contains AV OPAC description (interface defaults to opac)' ); |
| 87 |
is( $record->field('942')->subfield('n'), 1, 'Record suppression is still numeric after filtering' ); |
| 88 |
|
| 89 |
# reset record for next test |
| 90 |
$record = $biblio->metadata->record; |
| 91 |
is( $record->field('590')->subfield('a'), 'CODE', 'Record reset contains AV Code' ); |
| 92 |
|
| 93 |
# set interface |
| 94 |
$processor->options({ interface => 'intranet' }); |
| 95 |
$result = $processor->process( $record ); |
| 96 |
is( $record->field('590')->subfield('a'), 'Description should show', 'Original record now contains AV description (interface set to intranet)' ); |
| 97 |
is( $record->field('942')->subfield('n'), 1, 'Item suppression field remains numeric after filtering' ); |
| 98 |
|
| 99 |
$schema->storage->txn_rollback(); |
| 100 |
}; |