Bug 19074: Fix category display in Batch patron modification.
[koha.git] / xt / author / icondirectories.t
1 #!/usr/bin/env 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 =head1 NAME
19
20 icondirectories.t - test to ensure that the two directories of icons
21 in the staff and opac interface are identical.
22
23 =head1 DESCRIPTION
24
25 Tere are two directories of icons for media types, one for the opac
26 and one for the staff interface. They need to be identical. This
27 ensures that they are.
28
29 =cut
30
31 use Modern::Perl;
32
33 use lib qw( .. );
34
35 use Data::Dumper;
36 use File::Find;
37 use Test::More tests => 3;
38
39 # hardcoded OPAC & STAFF dirs
40 my $opac_dir  = 'koha-tmpl/opac-tmpl';
41 my $staff_dir = 'koha-tmpl/intranet-tmpl';
42
43 # Find OPAC themes
44 opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
45 my @opac_themes = grep { not /^\.|lib|js|xslt/ } readdir($dh);
46 close $dh;
47
48 # Find STAFF themes
49 opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
50 my @staff_themes = grep { not /^\.|lib|js/ } readdir($dh);
51 close $dh;
52
53 # Check existence of OPAC icon dirs
54 for my $theme ( @opac_themes ) {
55     my $test_dir = "$opac_dir/$theme/itemtypeimg";
56     ok( -d $test_dir, "opac_icon_directory: $test_dir exists" );
57 }
58
59 # Check existence of STAFF icon dirs
60 for my $theme ( @staff_themes ) {
61     my $test_dir = "$staff_dir/$theme/img/itemtypeimg";
62     ok( -d $test_dir, "staff_icon_directory: $test_dir exists" );
63 }
64
65 # Check for same contents on STAFF and OPAC icondirs
66 # foreach STAFF theme
67 for my $staff_theme ( @staff_themes ) {
68     my $staff_icons; # hashref of filenames to sizes
69     my $staff_icon_directory = "$staff_dir/$staff_theme/img/itemtypeimg";
70     my $staff_wanted = sub {
71         my $file = $File::Find::name;
72         $file =~ s/^$staff_icon_directory//;
73         $staff_icons->{ $file } = -s $_;
74     };
75     find( { wanted => $staff_wanted }, $staff_icon_directory );
76
77     # foreach OPAC theme
78     for my $opac_theme ( @opac_themes ) {
79         next if ( $opac_theme =~ /ccsr/ );  # FIXME: skip CCSR opac theme, it fails and there is no point to fix it
80         my $opac_icons; # hashref of filenames to sizes
81         my $opac_icon_directory  = "$opac_dir/$opac_theme/itemtypeimg";
82         my $opac_wanted  = sub {
83             my $file = $File::Find::name;
84             $file =~ s/^$opac_icon_directory//;
85             $opac_icons->{ $file } = -s $_;
86         };
87         find( { wanted => $opac_wanted }, $opac_icon_directory );
88
89         is_deeply( $opac_icons, $staff_icons, "STAFF $staff_theme and OPAC $opac_theme icon directories have same contents" )
90             or diag( Data::Dumper->Dump( [ $opac_icons ], [ 'opac_icons' ] ) );
91     }
92 }
93
94 1;