From d18353b87eb40988745cb9fe66a1346ef8a13125 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 4 Apr 2022 11:50:01 +0000 Subject: [PATCH] Bug 30446: Add a test for GetTagsLabels Content-Type: text/plain; charset=utf-8 Moved from obsoleted bug 2222 on its own. Test plan: Run t/db_dependent/Authority/GetTagsLabels.t Signed-off-by: Marcel de Rooy --- t/db_dependent/Authority/GetTagsLabels.t | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 t/db_dependent/Authority/GetTagsLabels.t diff --git a/t/db_dependent/Authority/GetTagsLabels.t b/t/db_dependent/Authority/GetTagsLabels.t new file mode 100755 index 0000000000..f5d98e3542 --- /dev/null +++ b/t/db_dependent/Authority/GetTagsLabels.t @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# Tests for C4::AuthoritiesMarc::GetTagsLabels + +# Copyright 2022 Rijksmuseum, Koha Development Team +# +# 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 => 1; + +use t::lib::TestBuilder; + +use C4::AuthoritiesMarc qw( GetTagsLabels ); +use Koha::Authority::Types; +use Koha::Database; + +my $schema = Koha::Database->new->schema; +our $builder = t::lib::TestBuilder->new; + +$schema->storage->txn_begin; + +subtest 'GetTagsLabels' => sub { + plan tests => 8; + + # Clear auth_tag_structure and subfields (via constraints) + Koha::Authority::Types->delete; + my $tagslib = GetTagsLabels(); + is( $tagslib, undef, 'Nothing in table' ); + + # Add one tag (and auth type), test librarian flag + my $tag = $builder->build_object({ class => 'Koha::Authority::Tags', value => { authtypecode => 'XX1', tagfield => '177' } }); + $tagslib = GetTagsLabels( 1, $tag->authtypecode ); + is( ref($tagslib), 'HASH', 'Should be a hash' ); + is( scalar keys %$tagslib, 1, 'Only one entry' ); + is( ref( $tagslib->{177} ), 'HASH' , 'Should be a hash' ); + is( $tagslib->{177}->{lib}, $tag->liblibrarian, 'passed librarian flag' ); + + # Add subfield, test opac flag + my $sub = $builder->build_object({ class => 'Koha::Authority::Subfields', value => { authtypecode => 'XX1', tagfield => '177', tagsubfield => 'a' } }); + $tagslib = GetTagsLabels( 0, $tag->authtypecode ); + is( $tagslib->{177}->{lib}, $tag->libopac, 'passed opac flag' ); + is( ref( $tagslib->{177}->{a} ), 'HASH' , 'Should be a hash' ); + is( $tagslib->{177}->{a}->{lib}, $sub->libopac, 'opac lib in subfield' ); +}; + +$schema->storage->txn_rollback; -- 2.20.1