From 878631a7fffaa36d89a1a8eb86364b3cf667d11a 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 Signed-off-by: Marcel de Rooy Signed-off-by: David Nind --- C4/XSLT.pm | 29 +++++++++------- .../en/modules/admin/preferences/opac.pref | 1 + .../en/includes/opac-detail-sidebar.inc | 33 ++++++++++++++++++ opac/opac-downloadcart.pl | 2 +- opac/opac-export.pl | 2 +- t/XSLT.t | 34 +++++++++++++++++-- 6 files changed, 84 insertions(+), 17 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 0532c04f63..14a3d186de 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -193,7 +193,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); @@ -201,17 +201,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; @@ -424,7 +424,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 3d8cd4fab9..fda2187f1a 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 @@ -313,6 +313,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 fe14391a76..d7e9f108ce 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 @@ -57,6 +57,7 @@
  • +======= + Save record + + + +>>>>>>> Bug 17385: Add tests for CustomXSLTExportList
  • [% END %] diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index 7237a32aca..222d5646e9 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -118,7 +118,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 8a14aa0362..ca00ccb593 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