From 4f13d7d77099eb4185cb8bfd1f929761c9eebf3b Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Wed, 8 Jan 2014 16:11:28 -0700 Subject: [PATCH] Bug 10486 QA followup: Fix license headers, add tests XSLT.t is the only one modified, so to run the tests, just do: prove t/XSLT.t --- koha-tmpl/opac-tmpl/lib/pz2.js | 18 +++++++- opac/opac-external-search.pl | 22 +++++----- opac/svc/pazpar2_init | 27 ++++++------ t/XSLT.t | 94 +++++++++++++++++++++++++++++++++++------- 4 files changed, 120 insertions(+), 41 deletions(-) diff --git a/koha-tmpl/opac-tmpl/lib/pz2.js b/koha-tmpl/opac-tmpl/lib/pz2.js index 9d693b2..4234c07 100644 --- a/koha-tmpl/opac-tmpl/lib/pz2.js +++ b/koha-tmpl/opac-tmpl/lib/pz2.js @@ -1,6 +1,20 @@ /* - * $Id: 3a9980787bb5d0fe966140b243a4a5eb6768913e $ -** pz2.js - pazpar2's javascript client library. + * pz2.js - pazpar2's javascript client library. + * Copyright (C) 2006-2013 Index Data. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //since explorer is flawed diff --git a/opac/opac-external-search.pl b/opac/opac-external-search.pl index 70737e2..8bd3f4f 100755 --- a/opac/opac-external-search.pl +++ b/opac/opac-external-search.pl @@ -1,21 +1,21 @@ #!/usr/bin/perl -# Copyright 2009 BibLibre SARL +# Copyright 2013 ByWater Solutions # # 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. +# 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 . use strict; use warnings; diff --git a/opac/svc/pazpar2_init b/opac/svc/pazpar2_init index 5a0a472..3c9fc6d 100755 --- a/opac/svc/pazpar2_init +++ b/opac/svc/pazpar2_init @@ -1,21 +1,21 @@ #!/usr/bin/perl -# Copyright 2013 ByWater +# Copyright 2013 ByWater Solutions # # 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. +# 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 . =head1 NAME @@ -23,12 +23,13 @@ svc/pazpar2_init: Initialize a Pazpar2 session =head1 SYNOPSIS -svc/pazpar2_init?targets=3,5,9 -> ../pazpar2/search.pz2?command=init&... +svc/pazpar2_init -> ../pazpar2/search.pz2?command=init&... =head1 DESCRIPTION This services connects to pazpar2 and authenticates connections on behalf of -client-side search code. +client-side search code. The proxy is necessary to prevent exposing +authentication information. =cut diff --git a/t/XSLT.t b/t/XSLT.t index 64cd597..d9aaf24 100755 --- a/t/XSLT.t +++ b/t/XSLT.t @@ -6,7 +6,11 @@ use strict; use warnings; -use Test::More tests => 8; +use C4::Context; +use C4::Templates; +use Test::More tests => 13; +use Test::MockModule; +use File::Basename qw/dirname/; use File::Temp; use File::Path qw/make_path/; @@ -14,36 +18,96 @@ BEGIN { use_ok('C4::XSLT'); } -my $dir = File::Temp->newdir(); +my $opacdir = File::Temp->newdir(); +my $staffdir = File::Temp->newdir(); my @themes = ('prog', 'test'); my @langs = ('en', 'es-ES'); +sub make_test_file { + my ( $filename, $contents ) = @_; + + make_path(dirname($filename)); + open my $fh, '>', $filename or die "Could not create test file: $filename"; + print $fh $contents; + close $fh; +} + # create temporary files to be tested later foreach my $theme (@themes) { foreach my $lang (@langs) { - make_path("$dir/$theme/$lang/xslt"); - open my $fh, '>', "$dir/$theme/$lang/xslt/my_file.xslt"; - print $fh "Theme $theme, language $lang"; - close $fh; + foreach my $dir ($opacdir, $staffdir) { + make_test_file( "$dir/$theme/$lang/xslt/my_file.xslt", "Theme $theme, language $lang" ); + make_test_file( "$dir/$theme/$lang/xslt/MARC21slim2intranetDetail.xsl", "Theme $theme, language $lang, MARC21slim2intranetDetail" ); + make_test_file( "$dir/$theme/$lang/xslt/test_en.xsl", "Theme $theme, language $lang, test_en" ); + make_test_file( "$dir/$theme/$lang/xslt/UNIMARCslim2OPACDetail.xsl", "Theme $theme, language $lang, UNIMARCslim2OPACDetail" ); + make_test_file( "$dir/$theme/$lang/xslt/nondefault_test.xsl", "Theme $theme, language $lang, nondefault_test" ); + make_test_file( "$dir/$theme/$lang/xslt/MARC21slim2OPACResults.xsl", "Theme $theme, language $lang, MARC21slim2OPACResults" ); + } } } -sub find_and_slurp { +sub find_and_slurp_default { my ($dir, $theme, $lang) = @_; my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt'); - open my $fh, '<', $filename; + open my $fh, '<', $filename or return "Could not open: $filename"; my $str = <$fh>; close $fh; return $str; } +sub find_and_slurp { + my ($marcflavour, $xslsyspref) = @_; + + my $filename = C4::XSLT::XSLTGetFilename( $marcflavour, $xslsyspref ); + open my $fh, '<', $filename or return "Could not open: $filename"; + my $str = <$fh>; + close $fh; + return $str; +} + +my $module_context = new Test::MockModule('C4::Context'); +$module_context->mock( + 'config', + sub { + my ( $self, $var ) = @_; + my %predefs = ( + opachtdocs => $opacdir, + intrahtdocs => $staffdir, + ); + + return $predefs{$var} || $module_context->original('config')->(@_); + } +); +$module_context->mock( + 'preference', + sub { + my ( $self, $var ) = @_; + my %predefs = ( + template => 'prog', + marcflavour => 'MARC21', + opacthemes => 'test', + XSLTDetailsDisplay => 'default', + XSLTResultsDisplay => "$staffdir/prog/en/xslt/test_en.xsl", + OPACXSLTDetailsDisplay => "$opacdir/test/en/xslt/nondefault_test.xsl", + OPACXSLTResultsDisplay => '"default"', + ); + + return $predefs{$var} || $module_context->original('preference')->(@_); + } +); + # These tests verify that we're finding the right XSLT file when present, # and falling back to the right XSLT file when an exact match is not present. -is(find_and_slurp($dir, 'test', 'en' ), 'Theme test, language en', 'Found test/en'); -is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES'); -is(find_and_slurp($dir, 'prog', 'en', ), 'Theme prog, language en', 'Found test/en'); -is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES'); -is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en', 'Fell back to test/en for test/fr-FR'); -is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES'); -is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR'); +is(find_and_slurp_default($opacdir, 'test', 'en' ), 'Theme test, language en', 'Found test/en'); +is(find_and_slurp_default($opacdir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES'); +is(find_and_slurp_default($opacdir, 'prog', 'en', ), 'Theme prog, language en', 'Found test/en'); +is(find_and_slurp_default($opacdir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES'); +is(find_and_slurp_default($opacdir, 'test', 'fr-FR'), 'Theme test, language en', 'Fell back to test/en for test/fr-FR'); +is(find_and_slurp_default($opacdir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES'); +is(find_and_slurp_default($opacdir, 'nope', 'fr-FR'), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR'); +is(find_and_slurp('MARC21', 'XSLTDetailsDisplay'), 'Theme prog, language en, MARC21slim2intranetDetail', 'Used default for staff/details'); +is(find_and_slurp('MARC21', 'XSLTResultsDisplay'), 'Theme prog, language en, test_en', 'Used non-default with langcode for staff/results'); +is(find_and_slurp('MARC21', 'OPACXSLTDetailsDisplay'), 'Theme test, language en, nondefault_test', 'not-prog: Used non-default for local marcflavour and opac/details'); +is(find_and_slurp('UNIMARC', 'OPACXSLTDetailsDisplay'), 'Theme test, language en, UNIMARCslim2OPACDetail', 'not-prog: Used default for non-local marcflavour and opac/details'); +is(find_and_slurp('MARC21', 'OPACXSLTResultsDisplay'), 'Theme test, language en, MARC21slim2OPACResults', 'not-prog: Used "default" for opac/results'); -- 1.8.5.2