3 # This file is part of Koha.
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.
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.
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>.
19 use Test::More tests=> 10;
26 use Koha::Item::Attributes;
27 use Koha::MarcSubfieldStructures;
29 use t::lib::TestBuilder;
31 my $schema = Koha::Database->new->schema;
32 $schema->storage->txn_begin;
34 my $builder = t::lib::TestBuilder->new;
35 my $biblio = $builder->build_sample_biblio({ frameworkcode => '' });
36 my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
38 my $cache = Koha::Caches->get_instance;
39 $cache->clear_from_cache("MarcStructure-0-");
40 $cache->clear_from_cache("MarcStructure-1-");
41 $cache->clear_from_cache("default_value_for_mod_marc-");
42 $cache->clear_from_cache("MarcSubfieldStructure-");
44 # 952 $x $é $y are not linked with a kohafield
45 # $952$x $é repeatable
46 # $952$y is not repeatable
49 $item->more_subfields_xml(undef)->store; # Shouldn't be needed, but we want to make sure
50 my $attributes = $item->additional_attributes;
51 is( ref($attributes), 'Koha::Item::Attributes' );
52 is( $attributes->to_marcxml, undef );
53 is_deeply($attributes->to_hashref, {});
55 my $some_marc_xml = q{<?xml version="1.0" encoding="UTF-8"?>
57 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
58 xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
59 xmlns="http://www.loc.gov/MARC21/slim">
63 <datafield tag="999" ind1=" " ind2=" ">
64 <subfield code="x">value for x 1</subfield>
65 <subfield code="x">value for x 2</subfield>
66 <subfield code="y">value for y</subfield>
67 <subfield code="é">value for é 1</subfield>
68 <subfield code="é">value for é 2</subfield>
69 <subfield code="z">value for z 1|value for z 2</subfield>
75 $item->more_subfields_xml($some_marc_xml)->store;
77 $attributes = $item->additional_attributes;
78 is( ref($attributes), 'Koha::Item::Attributes' );
79 is( $attributes->{'x'}, "value for x 1|value for x 2");
80 is( $attributes->{'y'}, "value for y");
81 is( $attributes->{'é'}, "value for é 1|value for é 2");
82 is( $attributes->{'z'}, "value for z 1|value for z 2");
84 is( $attributes->to_marcxml, $some_marc_xml );
86 $attributes->to_hashref,
88 'x' => "value for x 1|value for x 2",
90 'é' => "value for é 1|value for é 2",
91 'z' => "value for z 1|value for z 2",
95 Koha::Caches->get_instance->clear_from_cache( "MarcStructure-1-" );
99 my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
101 Koha::MarcSubfieldStructures->search(
104 tagfield => $itemtag,
107 )->delete; # In case it exist already
109 Koha::MarcSubfieldStructure->new(
112 tagfield => $itemtag,
120 Koha::MarcSubfieldStructures->search(
123 tagfield => $itemtag,
124 tagsubfield => [ 'x', 'y' ]
126 )->update( { kohafield => undef } );
128 Koha::MarcSubfieldStructures->search(
131 tagfield => $itemtag,
132 tagsubfield => [ 'x', 'é' ],
134 )->update( { repeatable => 1 } );
136 Koha::MarcSubfieldStructures->search(
139 tagfield => $itemtag,
140 tagsubfield => ['y'],
142 )->update( { repeatable => 0 } );
145 for my $sf ( qw( x y é z ) ) {
146 Koha::MarcSubfieldStructures->search(
147 { frameworkcode => '', tagfield => $itemtag, tagsubfield => $sf } )
148 ->update( { display_order => $i++ } );