Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Tests for C4::AuthoritiesMarc::GetTagsLabels |
4 |
|
5 |
# Copyright 2022 Rijksmuseum, Koha Development Team |
6 |
# |
7 |
# This file is part of Koha. |
8 |
# |
9 |
# Koha is free software; you can redistribute it and/or modify it |
10 |
# under the terms of the GNU General Public License as published by |
11 |
# the Free Software Foundation; either version 3 of the License, or |
12 |
# (at your option) any later version. |
13 |
# |
14 |
# Koha is distributed in the hope that it will be useful, but |
15 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
# GNU General Public License for more details. |
18 |
# |
19 |
# You should have received a copy of the GNU General Public License |
20 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
21 |
|
22 |
use Modern::Perl; |
23 |
use Test::More tests => 1; |
24 |
|
25 |
use t::lib::TestBuilder; |
26 |
|
27 |
use C4::AuthoritiesMarc qw( GetTagsLabels ); |
28 |
use Koha::Authority::Types; |
29 |
use Koha::Database; |
30 |
|
31 |
my $schema = Koha::Database->new->schema; |
32 |
our $builder = t::lib::TestBuilder->new; |
33 |
|
34 |
$schema->storage->txn_begin; |
35 |
|
36 |
subtest 'GetTagsLabels' => sub { |
37 |
plan tests => 8; |
38 |
|
39 |
# Clear auth_tag_structure and subfields (via constraints) |
40 |
Koha::Authority::Types->delete; |
41 |
my $tagslib = GetTagsLabels(); |
42 |
is( $tagslib, undef, 'Nothing in table' ); |
43 |
|
44 |
# Add one tag (and auth type), test librarian flag |
45 |
my $tag = $builder->build_object({ class => 'Koha::Authority::Tags', value => { authtypecode => 'XX1', tagfield => '177' } }); |
46 |
$tagslib = GetTagsLabels( 1, $tag->authtypecode ); |
47 |
is( ref($tagslib), 'HASH', 'Should be a hash' ); |
48 |
is( scalar keys %$tagslib, 1, 'Only one entry' ); |
49 |
is( ref( $tagslib->{177} ), 'HASH' , 'Should be a hash' ); |
50 |
is( $tagslib->{177}->{lib}, $tag->liblibrarian, 'passed librarian flag' ); |
51 |
|
52 |
# Add subfield, test opac flag |
53 |
my $sub = $builder->build_object({ class => 'Koha::Authority::Subfields', value => { authtypecode => 'XX1', tagfield => '177', tagsubfield => 'a' } }); |
54 |
$tagslib = GetTagsLabels( 0, $tag->authtypecode ); |
55 |
is( $tagslib->{177}->{lib}, $tag->libopac, 'passed opac flag' ); |
56 |
is( ref( $tagslib->{177}->{a} ), 'HASH' , 'Should be a hash' ); |
57 |
is( $tagslib->{177}->{a}->{lib}, $sub->libopac, 'opac lib in subfield' ); |
58 |
}; |
59 |
|
60 |
$schema->storage->txn_rollback; |