View | Details | Raw Unified | Return to bug 34266
Collapse All | Expand All

(-)a/t/db_dependent/Koha/UI/Form/Builder/Item/itemtypes-default.t (-1 / +77 lines)
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::More tests => 2;
20
21
use Koha::Database;
22
use Koha::UI::Form::Builder::Item;
23
use t::lib::TestBuilder;
24
25
my $schema = Koha::Database->schema;
26
$schema->storage->txn_begin;
27
28
my $marc_subfield_structure_rs = $schema->resultset('MarcSubfieldStructure');
29
my $itemtag = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '995' : '952';
30
my ($itype_subfield) = $marc_subfield_structure_rs->search(
31
    {
32
        frameworkcode => '',
33
        authorised_value => 'itemtypes',
34
        tagfield => $itemtag,
35
    }
36
);
37
unless ($itype_subfield) {
38
    $itype_subfield = $marc_subfield_structure_rs->create(
39
        {
40
            frameworkcode => '',
41
            tagfield => $itemtag,
42
            tagsubfield => 'Z',
43
            authorised_value => 'itemtypes',
44
        }
45
    );
46
}
47
48
my $builder = t::lib::TestBuilder->new;
49
50
my $biblio = $builder->build_sample_biblio();
51
my $form_builder = Koha::UI::Form::Builder::Item->new({ biblionumber => $biblio->biblionumber });
52
my $tagslib = {
53
    $itemtag => {
54
        $itype_subfield->tagsubfield => { $itype_subfield->get_columns, lib => $itype_subfield->liblibrarian },
55
    },
56
};
57
my $subfield_data = $form_builder->generate_subfield_form(
58
    {
59
        tag => $itemtag,
60
        subfieldtag => $itype_subfield->tagsubfield,
61
        tagslib => $tagslib,
62
    }
63
);
64
65
is($subfield_data->{marc_value}->{default}, $biblio->itemtype, 'defaults to biblio itemtype if valid');
66
67
my $biblioitem = $biblio->biblioitem();
68
$biblioitem->itemtype('ZZZZZZ');
69
$biblioitem->store();
70
$subfield_data = $form_builder->generate_subfield_form(
71
    {
72
        tag => $itemtag,
73
        subfieldtag => $itype_subfield->tagsubfield,
74
        tagslib => $tagslib,
75
    }
76
);
77
is($subfield_data->{marc_value}->{default}, undef, 'defaults to nothing if biblio itemtype is not valid');

Return to bug 34266