Bugzilla – Attachment 86876 Details for
Bug 17385
Add custom export formats for bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17385: Add tests for CustomXSLTExportList
Bug-17385-Add-tests-for-CustomXSLTExportList.patch (text/plain), 9.08 KB, created by
Marcel de Rooy
on 2019-03-22 09:02:46 UTC
(
hide
)
Description:
Bug 17385: Add tests for CustomXSLTExportList
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2019-03-22 09:02:46 UTC
Size:
9.08 KB
patch
obsolete
>From b7df81563a78ec29e9969f04205211a50e6040b7 Mon Sep 17 00:00:00 2001 >From: David Bourgault <dav.bour@gmail.com> >Date: Fri, 20 Apr 2018 16:03:34 -0400 >Subject: [PATCH] Bug 17385: Add tests for CustomXSLTExportList >Content-Type: text/plain; charset=utf-8 > >+ 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 <carnold@dgiinc.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/XSLT.pm | 29 +++++++++--------- > .../prog/en/modules/admin/preferences/opac.pref | 1 + > .../bootstrap/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 5a2f76a260..d17a3b9894 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 da1d86540c..93d3ac89b0 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' %] > <li><a role="menuitem" href="#" data-toggle="modal" data-target="#exportModal_">Dublin Core</a></li> >- [% ELSE %] >+ [% ELSIF option != 'custom' %] > <li> > <a role="menuitem" href="/cgi-bin/koha/opac-export.pl?op=export&bib=[% biblio.biblionumber | html %]&format=[% option | html %]"> > [% SWITCH option %] >@@ -66,11 +66,12 @@ > [% END %] > </a> > </li> >+ [% ELSE %] >+ [% FOREACH filesOption IN filesOptions %] >+ <li><a role="menuitem" href="/cgi-bin/koha/opac-export.pl?format=[% filesOption.format %]&op=exportxsl&file=[% filesOption.value %]&bib=[% biblionumber %]">[% filesOption.filename %]</a></li> >+ [% END %] > [% END %] > [% END %] >- [% FOREACH filesOption IN filesOptions %] >- <li><a role="menuitem" href="/cgi-bin/koha/opac-export.pl?format=[% filesOption.format %]&op=exportxsl&file=[% filesOption.value %]&bib=[% biblionumber %]">[% filesOption.filename %]</a></li> >- [% END %] > </ul> > </div> > </div> >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{<syspref name="singleBranchMode">0</syspref>}; > 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|<?xml version="1.0" encoding="UTF-8"?> >+<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim" >+ title="Export 01"> >+</xsl:stylesheet>|; >+close $fh; >+ >+# Make XSL without title >+open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_02.xsl"; >+print $fh qq|<?xml version="1.0" encoding="UTF-8"?> >+<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim"> >+</xsl:stylesheet>|; >+close $fh; >+ >+open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_03.xsl"; >+print $fh qq|<?xml version="1.0" encoding="UTF-8"?>|; >+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.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17385
:
55961
|
58308
|
64033
|
64034
|
67357
|
67579
|
74660
|
74661
|
79055
|
79056
|
80675
|
81385
|
81386
|
84388
|
84389
|
84390
|
86875
|
86876
|
86877
|
86878
|
86879
|
86880
|
97076
|
97101
|
97102
|
97103
|
97104
|
97105
|
100289
|
100290
|
100291
|
100292
|
100293
|
100663
|
100670
|
100671
|
100672
|
100673
|
100674
|
100675
|
112671
|
112672
|
112673
|
112674
|
112675
|
112676
|
112677
|
112678
|
112679
|
112680
|
112681
|
112682
|
112956
|
112957
|
112958
|
112959
|
130283
|
130284
|
130285
|
130286
|
130287
|
130691
|
130692
|
130693
|
130694
|
130695
|
131492
|
132488
|
132489
|
132490
|
132491
|
132492
|
132493
|
132581
|
133498
|
133499
|
133500
|
133501
|
133502
|
133503
|
133504
|
138031
|
138032
|
138033
|
138034
|
138035
|
138036
|
138037
|
138082
|
138083
|
138084
|
138085
|
138086
|
138087
|
138088
|
138132
|
139277
|
139278
|
139279
|
139280
|
139281
|
139282
|
139283
|
139284
|
141157
|
141158
|
141159
|
141160
|
141161
|
141162
|
141163
|
141164
|
144335
|
144336
|
144380
|
144384
|
151095
|
151096
|
151097
|
151098
|
151099
|
151102
|
151103
|
151104
|
151105
|
151106
|
151377
|
151378
|
151379
|
151380
|
151381
|
154379
|
154380
|
154381
|
154382
|
154383
|
156815
|
156816
|
156817
|
156818
|
156819
|
159142
|
159143
|
159144
|
159145
|
159146
|
159147
|
159148
|
163623
|
170014
|
170015
|
170016
|
170017
|
170018
|
170019
|
170026
|
170027
|
170028
|
170029
|
170030
|
170031
|
170983
|
170984
|
170985
|
170986
|
170987
|
170988