From 2f585edb4cbe036b873d5e0124d008fffe3fb23c Mon Sep 17 00:00:00 2001
From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Date: Mon, 11 Aug 2014 01:19:52 -0300
Subject: [PATCH] Bug 12653: PROG/CCSR deprecation: Correct hard-coded
opac-tmpl/prog path in tests
This patch removes explicit references of themes
from
xt/single_quotes.t
xt/author/valid-templates.t
xt/author/icondirectories.t
xt/author/translatable-templates.t
xt/tt_valid.t
To test:
1. Apply the patch
2. Run each test, all must pass
Some have been slightly rewritten, check
that intended or similar test is performed.
xt/author/valid-templates.t has been touched
to only test files and not dirs
---
xt/author/icondirectories.t | 71 ++++++++++++++++----------------
xt/author/translatable-templates.t | 5 ++-
xt/author/valid-templates.t | 78 +++++++++++++++++++++++-------------
xt/single_quotes.t | 25 +++++++++---
xt/tt_valid.t | 24 +++++++++--
5 files changed, 130 insertions(+), 73 deletions(-)
diff --git a/xt/author/icondirectories.t b/xt/author/icondirectories.t
index a4145fa..5d2ebf7 100644
--- a/xt/author/icondirectories.t
+++ b/xt/author/icondirectories.t
@@ -20,44 +20,47 @@ 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 C4::Context;
+
+use Test::More tests => 8;
+
+my @themes;
+my $dh;
+# OPAC
+my $htdocs = C4::Context->config('opachtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib/ } readdir($dh) ) {
+ push @themes, {
+ theme => $theme,
+ icondir => "$htdocs/$theme/itemtypeimg",
+ };
}
-
-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 $_;
+close $dh;
+# Intranet
+$htdocs = C4::Context->config('intrahtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+ push @themes, {
+ theme => $theme,
+ icondir => "$htdocs/$theme/img/itemtypeimg",
+ };
}
-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' ] ) );
-
-
-
-
-
-
-
-
-
+close $dh;
+my $icons;
+foreach my $theme ( @themes ) {
+ ok( -d $theme->{'icondir'}, "$theme->{'theme'}: directory exists");
+ $icons = undef;
+ my $where = $theme->{'icondir' };
+ sub wanted {
+ my $file = $_;
+ $icons->{ $file } = -s $_;
+ }
+ find( \&wanted, $where );
+ ok ( defined $icons, "Some contents in $where dir")
+ or diag( Data::Dumper->Dump( [ $icons ], [ 'icons' ] ) );
+}
diff --git a/xt/author/translatable-templates.t b/xt/author/translatable-templates.t
index 8079cd6..9f2e365 100644
--- a/xt/author/translatable-templates.t
+++ b/xt/author/translatable-templates.t
@@ -12,6 +12,7 @@ construct that the extractor cannot parse.
=cut
+use C4::Context;
use Test::More tests => 2;
use File::Temp qw/tempdir/;
use IPC::Open3;
@@ -22,8 +23,8 @@ use utf8;
my $po_dir = tempdir(CLEANUP => 1);
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);
+test_string_extraction("opac", "../../koha-tmpl/opac-tmpl/". C4::Context->preference('opacthemes')."/en", $po_dir);
+test_string_extraction("intranet", "../../koha-tmpl/intranet-tmpl/".C4::Context->preference('template' )."/en", $po_dir);
sub test_string_extraction {
my $module = shift;
diff --git a/xt/author/valid-templates.t b/xt/author/valid-templates.t
index e02b6f3..6b181f7 100644
--- a/xt/author/valid-templates.t
+++ b/xt/author/valid-templates.t
@@ -35,32 +35,52 @@ 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
+use C4::Context;
+
+my @themes;
+my $dh;
+# OPAC
+my $htdocs = C4::Context->config('opachtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib/ } readdir($dh) ) {
+ push @themes, {
+ theme => $theme,
+ modules => "$htdocs/$theme/en/modules",
+ includes => "$htdocs/$theme/en/includes",
+ }
+}
+close $dh;
+# Intranet
+$htdocs = C4::Context->config('intrahtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+ push @themes, {
+ theme => $theme,
+ modules => "$htdocs/$theme/en/modules",
+ includes => "$htdocs/$theme/en/includes",
+ }
+}
+close $dh;
+
+foreach my $theme ( @themes ) {
+ print "Testing $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 +114,10 @@ sub create_template_test {
}
my $vars;
my $output;
- if ( !ok( $tt->process( $_, $vars, \$output ), $_ ) ) {
- diag( $tt->error );
+ if ( ! -d $_ ) {
+ if ( !ok( $tt->process( $_, $vars, \$output ), $_ ) ) {
+ diag( $tt->error );
+ }
}
}
}
diff --git a/xt/single_quotes.t b/xt/single_quotes.t
index 89b539c..4dc5808 100755
--- a/xt/single_quotes.t
+++ b/xt/single_quotes.t
@@ -21,6 +21,24 @@ use warnings;
use strict;
use Test::More tests => 1;
use File::Find;
+use C4::Context;
+
+my @themes;
+my $dh;
+# OPAC
+my $htdocs = C4::Context->config('opachtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib/ } readdir($dh) ) {
+ push @themes, "$htdocs/$theme";
+}
+close $dh;
+# Intranet
+$htdocs = C4::Context->config('intrahtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+ push @themes, "$htdocs/$theme";
+}
+close $dh;
my @files;
find(
@@ -28,11 +46,8 @@ find(
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 _(' " )
diff --git a/xt/tt_valid.t b/xt/tt_valid.t
index e33b760..9b556f1 100755
--- a/xt/tt_valid.t
+++ b/xt/tt_valid.t
@@ -23,7 +23,24 @@ use Test::More tests => 2;
use File::Find;
use Cwd;
use C4::TTParser;
-
+use C4::Context;
+
+my @themes;
+my $dh;
+# OPAC
+my $htdocs = C4::Context->config('opachtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib/ } readdir($dh) ) {
+ push @themes, "$htdocs/$theme";
+}
+close $dh;
+# Intranet
+$htdocs = C4::Context->config('intrahtdocs');
+opendir ($dh, $htdocs);
+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
+ push @themes, "$htdocs/$theme";
+}
+close $dh;
my @files_with_directive_in_tag = do {
my @files;
@@ -42,13 +59,12 @@ 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;
};
-
ok( !@files_with_directive_in_tag, "TT syntax: not using TT directive within HTML tag" )
or diag(
"Files list: \n",
--
1.7.9.5