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("MarcSubfieldStructure-");
43 # 952 $x $é $y are not linked with a kohafield
44 # $952$x $é repeatable
45 # $952$y is not repeatable
48 $item->more_subfields_xml(undef)->store; # Shouldn't be needed, but we want to make sure
49 my $attributes = $item->additional_attributes;
50 is( ref($attributes), 'Koha::Item::Attributes' );
51 is( $attributes->to_marcxml, undef );
52 is_deeply($attributes->to_hashref, {});
54 my $some_marc_xml = q{<?xml version="1.0" encoding="UTF-8"?>
56 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57 xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
58 xmlns="http://www.loc.gov/MARC21/slim">
62 <datafield tag="999" ind1=" " ind2=" ">
63 <subfield code="x">value for x 1</subfield>
64 <subfield code="x">value for x 2</subfield>
65 <subfield code="y">value for y</subfield>
66 <subfield code="é">value for é 1</subfield>
67 <subfield code="é">value for é 2</subfield>
68 <subfield code="z">value for z 1 | value for z 2</subfield>
74 $item->more_subfields_xml($some_marc_xml)->store;
76 $attributes = $item->additional_attributes;
77 is( ref($attributes), 'Koha::Item::Attributes' );
78 is( $attributes->{'x'}, "value for x 1 | value for x 2");
79 is( $attributes->{'y'}, "value for y");
80 is( $attributes->{'é'}, "value for é 1 | value for é 2");
81 is( $attributes->{'z'}, "value for z 1 | value for z 2");
83 is( $attributes->to_marcxml, $some_marc_xml );
85 $attributes->to_hashref,
87 'x' => "value for x 1 | value for x 2",
89 'é' => "value for é 1 | value for é 2",
90 'z' => "value for z 1 | value for z 2",
94 Koha::Caches->get_instance->clear_from_cache( "MarcStructure-1-" );
98 my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
100 Koha::MarcSubfieldStructures->search(
103 tagfield => $itemtag,
106 )->delete; # In case it exist already
108 Koha::MarcSubfieldStructure->new(
111 tagfield => $itemtag,
119 Koha::MarcSubfieldStructures->search(
122 tagfield => $itemtag,
123 tagsubfield => [ 'x', 'y' ]
125 )->update( { kohafield => undef } );
127 Koha::MarcSubfieldStructures->search(
130 tagfield => $itemtag,
131 tagsubfield => [ 'x', 'é' ],
133 )->update( { repeatable => 1 } );
135 Koha::MarcSubfieldStructures->search(
138 tagfield => $itemtag,
139 tagsubfield => ['y'],
141 )->update( { repeatable => 0 } );
144 for my $sf ( qw( x y é z ) ) {
145 Koha::MarcSubfieldStructures->search(
146 { frameworkcode => '', tagfield => $itemtag, tagsubfield => $sf } )
147 ->update( { display_order => $i++ } );