|
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 |
use Test::NoWarnings; |
| 20 |
use Test::More tests => 2; # N + 1 (NoWarnings) |
| 21 |
use Test::MockModule; |
| 22 |
use Test::Exception; |
| 23 |
|
| 24 |
use DDP; |
| 25 |
use MARC::Record; |
| 26 |
use MARC::File::XML; |
| 27 |
|
| 28 |
use Koha::Caches; |
| 29 |
use Koha::Database; |
| 30 |
use Koha::OAI::Server::Repository; |
| 31 |
|
| 32 |
use t::lib::Mocks; |
| 33 |
use t::lib::TestBuilder; |
| 34 |
|
| 35 |
my $schema = Koha::Database->new->schema; |
| 36 |
my $builder = t::lib::TestBuilder->new; |
| 37 |
|
| 38 |
subtest 'get_biblio_marcxml() tests' => sub { |
| 39 |
|
| 40 |
plan tests => 2; |
| 41 |
|
| 42 |
$schema->storage->txn_begin; |
| 43 |
|
| 44 |
# disable config, we are gonna force it |
| 45 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
| 46 |
t::lib::Mocks::mock_preference( 'OAI-PMH:ConfFile', 1 ); # so it loads the mocked one |
| 47 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); |
| 48 |
|
| 49 |
my $library = |
| 50 |
$builder->build_object( { class => 'Koha::Libraries', value => { branchname => q{Nick's Library} } } ); |
| 51 |
my $item = $builder->build_sample_item( { library => $library->id } ); |
| 52 |
|
| 53 |
my $cache = Koha::Caches->get_instance; |
| 54 |
$cache->clear_from_cache("MarcCodedFields-"); |
| 55 |
|
| 56 |
# Clear GetAuthorisedValueDesc-generated cache |
| 57 |
$cache->clear_from_cache("libraries:name"); |
| 58 |
$cache->clear_from_cache("itemtype:description:en"); |
| 59 |
$cache->clear_from_cache("cn_sources:description"); |
| 60 |
|
| 61 |
my $cgi = Test::MockModule->new('CGI'); |
| 62 |
$cgi->mock( 'Vars', sub { ( 'verb', 'Identify' ); } ); |
| 63 |
my $yaml = Test::MockModule->new('YAML::XS'); |
| 64 |
$yaml->mock( |
| 65 |
'LoadFile', |
| 66 |
sub { |
| 67 |
return { |
| 68 |
format => { |
| 69 |
not_expanded => { |
| 70 |
include_items => 1, |
| 71 |
expanded_avs => 0, |
| 72 |
}, |
| 73 |
expanded => { |
| 74 |
include_items => 1, |
| 75 |
expanded_avs => 1, |
| 76 |
} |
| 77 |
} |
| 78 |
}; |
| 79 |
} |
| 80 |
); |
| 81 |
|
| 82 |
# Initialize $repository object, silence output |
| 83 |
my $repository; |
| 84 |
{ |
| 85 |
my $stdout; |
| 86 |
local *STDOUT; |
| 87 |
open STDOUT, '>', \$stdout; |
| 88 |
$repository = Koha::OAI::Server::Repository->new(); |
| 89 |
} |
| 90 |
|
| 91 |
# not expanded case |
| 92 |
my ($xml) = $repository->get_biblio_marcxml( $item->biblionumber, 'not_expanded' ); |
| 93 |
my $record = MARC::Record->new_from_xml($xml); |
| 94 |
my $item_field = $record->field('952'); |
| 95 |
|
| 96 |
is( $item_field->subfield('a'), $library->branchcode ); |
| 97 |
|
| 98 |
# expanded case |
| 99 |
($xml) = $repository->get_biblio_marcxml( $item->biblionumber, 'expanded' ); |
| 100 |
$record = MARC::Record->new_from_xml($xml); |
| 101 |
$item_field = $record->field('952'); |
| 102 |
|
| 103 |
is( $item_field->subfield('a'), $library->branchname ); |
| 104 |
|
| 105 |
$schema->storage->txn_rollback; |
| 106 |
}; |