Koha/t/XSLT.t
Galen Charlton b0eeb00d48 bug 10292: improve fallback logic for picking XSLT
This patch fixes a bug whereby XSLT files from the
prog theme would be used (for English OPACs and staff
interfaces) even if the user had created and enabled a
custom theme that provided override XSLT files.

This patch provides a clearer implementation of the fallback
logic and adds test cases.

To reproduce the bug:

[1] Set OPACXSLTDetailsDisplay to 'default' and English as the OPAC
    language.
[2] Create a new OPAC theme, including copying the XSLT files.
[3] Set opactheme to the new theme.
[4] Make a change to koha-tmpl/opac-tmpl/NEWTHEME/en/xslt/MARC21slim2OPACDetail.xsl
[5] View a bib record in the OPAC. The change made in the previous step
    is not reflected.

To test after applying the patch:

[6] Reload the bib record in the OPAC. The change made in step 4 should
    now be reflected.
[7] (To be thorough) Go through the test plan for bug 8947
    and verify that there is no regression.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2013-05-29 07:39:41 -07:00

49 lines
1.7 KiB
Perl
Executable file

#!/usr/bin/perl
#
# This Koha test module is a stub!
# Add more tests here!!!
use strict;
use warnings;
use Test::More tests => 8;
use File::Temp;
use File::Path qw/make_path/;
BEGIN {
use_ok('C4::XSLT');
}
my $dir = File::Temp->newdir();
my @themes = ('prog', 'test');
my @langs = ('en', 'es-ES');
# 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;
}
}
sub find_and_slurp {
my ($dir, $theme, $lang) = @_;
my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt');
open my $fh, '<', $filename;
my $str = <$fh>;
close $fh;
return $str;
}
# 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');