From 2b10699d8c93b500ba19a1624f648fff9cfa9635 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 13 Jul 2023 10:58:42 +0200 Subject: [PATCH] Bug 34266: Add unit tests Signed-off-by: joubu Signed-off-by: tuxayo Took the opportunity to perltidy this file as I was signing off Signed-off-by: Chris Cormack --- .../UI/Form/Builder/Item/itemtypes-default.t | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 t/db_dependent/Koha/UI/Form/Builder/Item/itemtypes-default.t diff --git a/t/db_dependent/Koha/UI/Form/Builder/Item/itemtypes-default.t b/t/db_dependent/Koha/UI/Form/Builder/Item/itemtypes-default.t new file mode 100755 index 00000000000..6c05f9d0720 --- /dev/null +++ b/t/db_dependent/Koha/UI/Form/Builder/Item/itemtypes-default.t @@ -0,0 +1,77 @@ +#!/usr/bin/perl + +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Test::More tests => 2; + +use Koha::Database; +use Koha::UI::Form::Builder::Item; +use t::lib::TestBuilder; + +my $schema = Koha::Database->schema; +$schema->storage->txn_begin; + +my $marc_subfield_structure_rs = $schema->resultset('MarcSubfieldStructure'); +my $itemtag = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '995' : '952'; +my ($itype_subfield) = $marc_subfield_structure_rs->search( + { + frameworkcode => '', + authorised_value => 'itemtypes', + tagfield => $itemtag, + } +); +unless ($itype_subfield) { + $itype_subfield = $marc_subfield_structure_rs->create( + { + frameworkcode => '', + tagfield => $itemtag, + tagsubfield => 'Z', + authorised_value => 'itemtypes', + } + ); +} + +my $builder = t::lib::TestBuilder->new; + +my $biblio = $builder->build_sample_biblio(); +my $form_builder = Koha::UI::Form::Builder::Item->new( { biblionumber => $biblio->biblionumber } ); +my $tagslib = { + $itemtag => { + $itype_subfield->tagsubfield => { $itype_subfield->get_columns, lib => $itype_subfield->liblibrarian }, + }, +}; +my $subfield_data = $form_builder->generate_subfield_form( + { + tag => $itemtag, + subfieldtag => $itype_subfield->tagsubfield, + tagslib => $tagslib, + } +); + +is( $subfield_data->{marc_value}->{default}, $biblio->itemtype, 'defaults to biblio itemtype if valid' ); + +my $biblioitem = $biblio->biblioitem(); +$biblioitem->itemtype('ZZZZZZ'); +$biblioitem->store(); +$subfield_data = $form_builder->generate_subfield_form( + { + tag => $itemtag, + subfieldtag => $itype_subfield->tagsubfield, + tagslib => $tagslib, + } +); +is( $subfield_data->{marc_value}->{default}, undef, 'defaults to nothing if biblio itemtype is not valid' ); -- 2.30.2