Bug 12653: PROG/CCSR deprecation: Correct hard-coded opac-tmpl/prog path in tests
authorBernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Thu, 16 Oct 2014 22:35:52 +0000 (19:35 -0300)
committerChris Cormack <chrisc@catalyst.net.nz>
Wed, 29 Oct 2014 20:35:12 +0000 (09:35 +1300)
This patch removes explicit references of themes from

  xt/author/icondirectories.t
  xt/author/translatable-templates.t
  xt/author/valid-templates.t
  xt/single_quotes.t
  xt/tt_valid.t

For xt/author/icondirectories.t it fixes a small difference on
two bootstrap files, previously unchecked, crystal-clear/_COPYING.txt
and crystal-clear/_README.txt

Some updates to license information

To test:
1. Apply the patch
2. Run each test, all must pass
prove xt/author/icondirectories.t xt/author/translatable-templates.t xt/author/valid-templates.t xt/single_quotes.t xt/tt_valid.t

3. Try to fail each test

a) xt/author/icondirectories.t
create a new file on any of icon dirs, e.g.
touch koha-tmpl/opac-tmpl/bootstrap/itemtypeimg/newfile.png
test must fail

b) xt/author/translatable-templates.t
change the name of 'en' dir on any theme opac or staff
test must fail

Add following line to any template file
<span [% IF ( value ) %]name="name"[% ELSE %] js="_('">TEST [% INCLUDE 'fail.inc' %]</span>

c) xt/author/valid-templates.t must fail
d) xt/single_quotes.t must fail
e) xt/tt_valid.t must fail

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

xt/author/icondirectories.t
xt/author/translatable-templates.t
xt/author/valid-templates.t
xt/single_quotes.t
xt/tt_valid.t

index a4145fa..08f1368 100644 (file)
@@ -1,5 +1,20 @@
 #!/usr/bin/env 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 <http://www.gnu.org/licenses>.
+
 =head1 NAME
 
 icondirectories.t - test to ensure that the two directories of icons
@@ -20,44 +35,60 @@ use lib qw( .. );
 
 use Data::Dumper;
 use File::Find;
-use Test::More tests => 3;
-
-my $opac_icon_directory  = 'koha-tmpl/opac-tmpl/prog/itemtypeimg';
-my $staff_icon_directory = 'koha-tmpl/intranet-tmpl/prog/img/itemtypeimg';
-
-ok( -d $opac_icon_directory, "opac_icon_directory: $opac_icon_directory exists" );
-ok( -d $staff_icon_directory, "staff_icon_directory: $staff_icon_directory exists" );
-
-my $opac_icons; # hashref of filenames to sizes
-sub opac_wanted {
-    my $file = $File::Find::name;
-    $file =~ s/^$opac_icon_directory//;
-    $opac_icons->{ $file } = -s $_;
+use Test::More tests => 6;
+
+# hardcoded OPAC & STAFF dirs
+my $opac_dir  = 'koha-tmpl/opac-tmpl';
+my $staff_dir = 'koha-tmpl/intranet-tmpl';
+
+# Find OPAC themes
+opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
+my @opac_themes = grep { not /^\.|lib|js/ } readdir($dh);
+close $dh;
+
+# Find STAFF themes
+opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
+my @staff_themes = grep { not /^\.|lib|js/ } readdir($dh);
+close $dh;
+
+# Check existence of OPAC icon dirs
+for my $theme ( @opac_themes ) {
+    my $test_dir = "$opac_dir/$theme/itemtypeimg";
+    ok( -d $test_dir, "opac_icon_directory: $test_dir exists" );
 }
 
-find( \&opac_wanted, $opac_icon_directory );
-
-my $staff_icons; # hashref of filenames to sizes
-sub staff_wanted {
-    my $file = $File::Find::name;
-    $file =~ s/^$staff_icon_directory//;
-    $staff_icons->{ $file } = -s $_;
+# Check existence of STAFF icon dirs
+for my $theme ( @staff_themes ) {
+    my $test_dir = "$staff_dir/$theme/img/itemtypeimg";
+    ok( -d $test_dir, "staff_icon_directory: $test_dir exists" );
 }
-find( \&staff_wanted, $staff_icon_directory );
-
-is_deeply( $opac_icons, $staff_icons, "staff and OPAC icon directories have same contents" )
-  or diag( Data::Dumper->Dump( [ $opac_icons ], [ 'opac_icons' ] ) );
-
-
-
-
-
-
-
-
-
-
-
-
 
+# Check for same contents on STAFF and OPAC icondirs
+# foreach STAFF theme
+for my $staff_theme ( @staff_themes ) {
+    my $staff_icons; # hashref of filenames to sizes
+    my $staff_icon_directory = "$staff_dir/$staff_theme/img/itemtypeimg";
+    my $staff_wanted = sub {
+        my $file = $File::Find::name;
+        $file =~ s/^$staff_icon_directory//;
+        $staff_icons->{ $file } = -s $_;
+    };
+    find( { wanted => $staff_wanted }, $staff_icon_directory );
+
+    # foreach OPAC theme
+    for my $opac_theme ( @opac_themes ) {
+        next if ( $opac_theme =~ /ccsr/ );  # FIXME: skip CCSR opac theme, it fails and there is no point to fix it
+        my $opac_icons; # hashref of filenames to sizes
+        my $opac_icon_directory  = "$opac_dir/$opac_theme/itemtypeimg";
+        my $opac_wanted  = sub {
+            my $file = $File::Find::name;
+            $file =~ s/^$opac_icon_directory//;
+            $opac_icons->{ $file } = -s $_;
+        };
+        find( { wanted => $opac_wanted }, $opac_icon_directory );
+
+        is_deeply( $opac_icons, $staff_icons, "STAFF $staff_theme and OPAC $opac_theme icon directories have same contents" )
+            or diag( Data::Dumper->Dump( [ $opac_icons ], [ 'opac_icons' ] ) );
+    }
+}
 
index 8079cd6..59c3ff3 100644 (file)
@@ -1,5 +1,20 @@
 #!/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 <http://www.gnu.org/licenses>.
+
 use strict;
 use warnings;
 
@@ -12,7 +27,7 @@ construct that the extractor cannot parse.
 
 =cut
 
-use Test::More tests => 2;
+use Test::More;
 use File::Temp qw/tempdir/;
 use IPC::Open3;
 use File::Spec;
@@ -21,9 +36,29 @@ use utf8;
 
 my $po_dir = tempdir(CLEANUP => 1);
 
+# Find OPAC themes
+my $opac_dir  = 'koha-tmpl/opac-tmpl';
+opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
+my @opac_themes = grep { not /^\.|lib|js/ } readdir($dh);
+close $dh;
+
+# Find STAFF themes
+my $staff_dir = 'koha-tmpl/intranet-tmpl';
+opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
+my @staff_themes = grep { not /^\.|lib|js/ } readdir($dh);
+close $dh;
+
 chdir "misc/translator"; # for now, tmpl_process3.pl works only if run from its directory
-test_string_extraction("opac",     "../../koha-tmpl/opac-tmpl/prog/en",     $po_dir);
-test_string_extraction("intranet", "../../koha-tmpl/intranet-tmpl/prog/en", $po_dir);
+
+# Check translatable of OPAC themes
+for my $theme ( @opac_themes ) {
+    test_string_extraction("opac_$theme",     "../../koha-tmpl/opac-tmpl/$theme/en",     $po_dir);
+}
+
+# Check translatable of STAFF themes
+for my $theme ( @staff_themes ) {
+    test_string_extraction("staff_$theme",     "../../koha-tmpl/intranet-tmpl/$theme/en",     $po_dir);
+}
 
 sub test_string_extraction {
     my $module       = shift;
@@ -53,3 +88,5 @@ sub test_string_extraction {
 
     ok($#warnings == -1, "$module templates are translatable") or diag join("\n", @warnings, '');
 }
+
+done_testing();
index e02b6f3..bc61264 100644 (file)
@@ -1,21 +1,21 @@
 #!/usr/bin/perl
 
-# Copyright 2011 Catalyst IT
-# 
 # 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 2 of the License, or (at your option) any later
-# version.
+# Copyright 2011 Catalyst IT
+#
+# 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.
+# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
@@ -35,32 +35,55 @@ use File::Find;
 use File::Spec;
 use Template;
 use Test::More;
-# use FindBin;
-# use IPC::Open3;
-
-print "Testing intranet prog templates\n";
-run_template_test(
-    'koha-tmpl/intranet-tmpl/prog/en/modules',
-    'koha-tmpl/intranet-tmpl/prog/en/includes'
-);
-
-print "Testing opac bootstrap templates\n";
-run_template_test(
-    'koha-tmpl/opac-tmpl/bootstrap/en/modules',
-    'koha-tmpl/opac-tmpl/bootstrap/en/includes',
-    # templates to exclude from testing because
-    # they cannot stand alone
-    'doc-head-close.inc',
-    'opac-bottom.inc',
-);
-
-print "Testing opac prog templates\n";
-run_template_test(
-    'koha-tmpl/opac-tmpl/prog/en/modules',
-    'koha-tmpl/opac-tmpl/prog/en/includes'
-);
-
-# TODO add test of opac ccsr templates
+
+my @themes;
+
+# OPAC themes
+my $opac_dir  = 'koha-tmpl/opac-tmpl';
+opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+    push @themes, {
+        type     => "opac",
+        theme    => $theme,
+        modules  => "$opac_dir/$theme/en/modules",
+        includes => "$opac_dir/$theme/en/includes",
+    }
+}
+close $dh;
+
+# STAFF themes
+my $staff_dir = 'koha-tmpl/intranet-tmpl';
+opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+    push @themes, {
+        type     => "staff",
+        theme    => $theme,
+        modules  => "$staff_dir/$theme/en/modules",
+        includes => "$staff_dir/$theme/en/includes",
+    }
+}
+close $dh;
+
+# Tests
+foreach my $theme ( @themes ) {
+    print "Testing $theme->{'type'} $theme->{'theme'} templates\n";
+    if ( $theme->{'theme'} eq 'bootstrap' ) {
+        run_template_test(
+            $theme->{'modules'},
+            $theme->{'includes'},
+            # templates to exclude from testing because
+            # they cannot stand alone
+            'doc-head-close.inc',
+            'opac-bottom.inc',
+        );
+    }
+    else {
+        run_template_test(
+            $theme->{'modules'},
+            $theme->{'includes'},
+        );
+    }
+}
 
 done_testing();
 
@@ -94,8 +117,10 @@ sub create_template_test {
         }
         my $vars;
         my $output;
-        if ( !ok( $tt->process( $_, $vars, \$output ), $_ ) ) {
-            diag( $tt->error );
+        if ( ! -d $_ ) {    # skip dirs
+            if ( !ok( $tt->process( $_, $vars, \$output ), $_ ) ) {
+                diag( $tt->error );
+            }
         }
     }
 }
index 89b539c..75681d1 100755 (executable)
@@ -1,38 +1,53 @@
 #!/usr/bin/perl
 
-# Copyright (C) 2013 Horowhenua Library Trust
-#
 # 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.
+# Copyright (C) 2013 Horowhenua Library Trust
+#
+# 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.
+# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use warnings;
 use strict;
 use Test::More tests => 1;
 use File::Find;
 
+my @themes;
+
+# OPAC themes
+my $opac_dir  = 'koha-tmpl/opac-tmpl';
+opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+    push @themes, "$opac_dir/$theme/en";
+}
+close $dh;
+
+# STAFF themes
+my $staff_dir = 'koha-tmpl/intranet-tmpl';
+opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+    push @themes, "$staff_dir/$theme/en";
+}
+close $dh;
+
 my @files;
 find(
     sub {
         open my $fh, $_ or die "Could not open $_: $!";
         my @lines = sort grep /\_\(\'/, <$fh>;
         push @files, { name => "$_", lines => \@lines } if @lines;
-    },qw#
-    ./koha-tmpl/opac-tmpl/prog/en
-    ./koha-tmpl/opac-tmpl/bootstrap/en
-    ./koha-tmpl/intranet-tmpl/prog/en
-    #
+    },
+    @themes
 );
 
 ok( !@files, "Files do not contain single quotes _(' " )
index e33b760..507210f 100755 (executable)
@@ -1,21 +1,21 @@
 #!/usr/bin/perl
 
-# Copyright (C) 2011 Tamil s.a.r.l.
-#
 # 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 2 of the License, or (at your option) any later
-# version.
+# Copyright (C) 2011 Tamil s.a.r.l.
+#
+# 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.
+# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use warnings;
 use strict;
@@ -24,6 +24,23 @@ use File::Find;
 use Cwd;
 use C4::TTParser;
 
+my @themes;
+
+# OPAC themes
+my $opac_dir  = 'koha-tmpl/opac-tmpl';
+opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+    push @themes, "$opac_dir/$theme/en";
+}
+close $dh;
+
+# STAFF themes
+my $staff_dir = 'koha-tmpl/intranet-tmpl';
+opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+    push @themes, "$staff_dir/$theme/en";
+}
+close $dh;
 
 my @files_with_directive_in_tag = do {
     my @files;
@@ -42,8 +59,7 @@ my @files_with_directive_in_tag = do {
         }
         ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
         push @files, { name => "$dir/$name", lines => \@lines } if @lines;
-      }, ( "./koha-tmpl/opac-tmpl/prog/en",
-           "./koha-tmpl/intranet-tmpl/prog/en" )
+      }, @themes
     );
     @files;
 };