Bug 12748: Code tidy
[koha.git] / t / db_dependent / Koha / GetKohaAuthorisedValuesMapping.t
1 #!/usr/bin/perl
2 #
3 # This file is part of Koha.
4 #
5 # Copyright (c) 2015   Mark Tompsett
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use C4::Context;
23
24 use Test::More tests => 8;
25
26 BEGIN {
27     use_ok('C4::Context');
28     use_ok('C4::Koha');
29 }
30
31 can_ok('C4::Koha','GetKohaAuthorisedValuesMapping');
32
33 my $avMappingOPAC;
34 my $avMappingStaff;
35 my $avMappingUndef1;
36 my $avMappingUndef2;
37 my $avMappingUndef3;
38 SKIP: {
39     my $dbh = C4::Context->dbh;
40     my $count = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM marc_subfield_structure WHERE kohafield LIKE 'item%';");
41     skip "Lacking item mappings in marc_subfield_structure",5 unless ($count && $count->[0]>0);
42     $count = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM authorised_values;");
43     skip "Lacking authorised_values",5 unless ($count && $count->[0]>0);
44     $avMappingOPAC   = GetKohaAuthorisedValuesMapping( { interface => 'opac' });
45     $avMappingStaff  = GetKohaAuthorisedValuesMapping( { interface => 'staff' });
46     $avMappingUndef1 = GetKohaAuthorisedValuesMapping( { interface => undef });
47     $avMappingUndef2 = GetKohaAuthorisedValuesMapping( { } );
48     $avMappingUndef3 = GetKohaAuthorisedValuesMapping();
49     is_deeply($avMappingUndef1,$avMappingStaff,"Undefined interface = Staff test 1");
50     is_deeply($avMappingUndef2,$avMappingStaff,"Undefined interface = Staff test 2");
51     is_deeply($avMappingUndef3,$avMappingStaff,"Undefined interface = Staff test 3");
52     isnt($avMappingOPAC ,undef,"OPAC has a mapping");
53     isnt($avMappingStaff,undef,"Staff has a mapping");
54 }