From 4c6a7984368e229f5032c9fbd6b746c113c55ca5 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Fri, 20 Apr 2018 16:03:34 -0400 Subject: [PATCH] Bug 17385: Add tests for CustomXSLTExportList + Added tests for CustomXSLTExportList to C4::XSLT + Added an eval block in CustomXSLTExportList to handle invalid XML. * Removed Opac parameter, but now handle "OPACXSLTCustomExport" as equivalent + Added "Custom" option to OPACExportOptions preference. Tested with invalid XML (not originally on purpose, but...) and then added a new field to add to the simple export. Walked through the testing steps. Question: should this also apply to the cataloging page as an export option? It doesn't now. Signed-off-by: Cori Lynn Arnold --- C4/XSLT.pm | 29 +++++++++------- .../en/modules/admin/preferences/opac.pref | 1 + .../en/includes/opac-detail-sidebar.inc | 9 ++--- opac/opac-downloadcart.pl | 2 +- opac/opac-export.pl | 2 +- t/XSLT.t | 34 +++++++++++++++++-- 6 files changed, 56 insertions(+), 21 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 6e078ab5e4..8363718582 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -191,7 +191,7 @@ sub get_xslt_sysprefs { } sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang , $opac) = @_; + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang) = @_; $sysxml ||= C4::Context->preference($xslsyspref); $xslfilename ||= C4::Context->preference($xslsyspref); @@ -199,17 +199,17 @@ sub XSLTParse4Display { if ($xslsyspref eq "XSLTCustomExport") { my $dir; - if ($opac) { - $dir = C4::Context->config('opachtdocs') . - '/' . C4::Context->preference("opacthemes") . - '/' . C4::Languages::getlanguage() . - '/xslt/biblioexport'; - } else { - $dir = C4::Context->config('intrahtdocs') . - '/' . C4::Context->preference("template") . - '/' . C4::Languages::getlanguage() . - '/xslt/biblioexport'; - } + $dir = C4::Context->config('intrahtdocs') . + '/' . C4::Context->preference("template") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + $xslfilename = $dir . "/" . $xslfilename; + } elsif ($xslsyspref eq "OPACXSLTCustomExport") { + my $dir; + $dir = C4::Context->config('opachtdocs') . + '/' . C4::Context->preference("opacthemes") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; $xslfilename = $dir . "/" . $xslfilename; } elsif( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my $htdocs; @@ -389,7 +389,10 @@ sub CustomXSLTExportList { (my $text = $file) =~ s/.*\///g; ## Get title of the option - my $dom = XML::LibXML->load_xml( location => $file ); + my $dom; + eval { $dom = XML::LibXML->load_xml( location => $file ); }; + next unless $dom; + my $node = $dom->documentElement(); my $title = $node->{"title"}; ($title = $text) =~ s/\.xsl// unless defined $title; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 3033b2d691..4b4a00e49d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -298,6 +298,7 @@ OPAC: mods: MODS ris: RIS isbd: ISBD + custom: Custom - - pref: OpacSeparateHoldings choices: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index 0772c85cbd..26f2515ce7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -50,7 +50,7 @@ [% FOREACH option IN export_options %] [% IF option == 'dc' %]
  • Dublin Core
  • - [% ELSE %] + [% ELSIF option != 'custom' %]
  • [% SWITCH option %] @@ -66,11 +66,12 @@ [% END %]
  • + [% ELSE %] + [% FOREACH filesOption IN filesOptions %] +
  • [% filesOption.filename %]
  • + [% END %] [% END %] [% END %] - [% FOREACH filesOption IN filesOptions %] -
  • [% filesOption.filename %]
  • - [% END %] diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index e829561ec5..a73f772799 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -110,7 +110,7 @@ if ($bib_list && $format) { $type = "text/plain"; } elsif ($format =~ /^xsl\.(.*)$/) { - $output .= XSLTParse4Display($biblio, $record, 'XSLTCustomExport', 1, undef, undef, $1, '', 1); + $output .= XSLTParse4Display($biblio, $record, 'OPACXSLTCustomExport', 1, undef, undef, $1, ''); } } } diff --git a/opac/opac-export.pl b/opac/opac-export.pl index fd3b9daa51..271e16d6bd 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -127,7 +127,7 @@ elsif ($format =~ /html/ ) { $marc = C4::Biblio::GetMarcBiblio({biblionumber => $biblionumber}); my @hiddenitems; - $marc = XSLTParse4Display($biblionumber, $marc, 'XSLTCustomExport', 1, \@hiddenitems, undef, $xslFile, undef, 1); + $marc = XSLTParse4Display($biblionumber, $marc, 'OPACXSLTCustomExport', 1, \@hiddenitems, undef, $xslFile, undef); } } else { diff --git a/t/XSLT.t b/t/XSLT.t index e3a733251c..4e64e8b24d 100755 --- a/t/XSLT.t +++ b/t/XSLT.t @@ -21,13 +21,13 @@ use Test::More; use File::Temp; use File::Path qw/make_path/; -use t::lib::Mocks; +use t::lib::Mocks qw( mock_preference ); use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 9; + plan tests => 12; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -77,3 +77,33 @@ my $matching_string = q{0}; my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs(); ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has a value of 0'); +t::lib::Mocks::mock_config('opachtdocs', "$dir"); +make_path("$dir/bootstrap/en/xslt/biblioexport"); + +# Make XSL with title +open my $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_01.xsl"; +print $fh qq| + +|; +close $fh; + +# Make XSL without title +open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_02.xsl"; +print $fh qq| + +|; +close $fh; + +open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_03.xsl"; +print $fh qq||; +close $fh; + +my @custom_xslts = @{C4::XSLT::CustomXSLTExportList(1)}; +ok((scalar @custom_xslts) == 2, "CustomXSLTExportList finds custom XSLTs"); +ok($custom_xslts[0]->{filename} eq "Export 01", "Title is specified in root node"); +ok($custom_xslts[1]->{filename} eq "export_02", "Title is filename if not specified"); \ No newline at end of file -- 2.17.1