Bugzilla – Attachment 99687 Details for
Bug 24052
Koha::XSLT housekeeping for bug 23290 (follow-up)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24052: Fix Koha/XSLT/Base.t
Bug-24052-Fix-KohaXSLTBaset.patch (text/plain), 11.05 KB, created by
Marcel de Rooy
on 2020-02-27 08:37:54 UTC
(
hide
)
Description:
Bug 24052: Fix Koha/XSLT/Base.t
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2020-02-27 08:37:54 UTC
Size:
11.05 KB
patch
obsolete
>From 6c6e8ff28c17fea1328c95263c6cebee7f3aa66e Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Tue, 25 Feb 2020 14:56:15 +0000 >Subject: [PATCH] Bug 24052: Fix Koha/XSLT/Base.t >Content-Type: text/plain; charset=utf-8 > >Moving the separate small attachments into the test script. >Creating them now as temporary files. >Deleting original files. > >Since Breeding.t also used one of these files, a similar change was made in >that script. > >Test plan: >Run t/db_dependent/Koha/XSLT/Base.t. Should pass now. >Run t/db_dependent/Breeding.t again. >Git grep on XSLT_Handler. You should only find release notes. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/Breeding.t | 40 +++++++++++- > t/db_dependent/Koha/XSLT/Base.t | 115 +++++++++++++++++++++++++++------ > t/db_dependent/XSLT_Handler/test01.xsl | 24 ------- > t/db_dependent/XSLT_Handler/test02.xsl | 13 ---- > t/db_dependent/XSLT_Handler/test03.xsl | 17 ----- > t/db_dependent/XSLT_Handler/test04.xsl | 18 ------ > 6 files changed, 131 insertions(+), 96 deletions(-) > delete mode 100644 t/db_dependent/XSLT_Handler/test01.xsl > delete mode 100644 t/db_dependent/XSLT_Handler/test02.xsl > delete mode 100644 t/db_dependent/XSLT_Handler/test03.xsl > delete mode 100644 t/db_dependent/XSLT_Handler/test04.xsl > >diff --git a/t/db_dependent/Breeding.t b/t/db_dependent/Breeding.t >index 5cd6a46f9b..f3eb54373a 100755 >--- a/t/db_dependent/Breeding.t >+++ b/t/db_dependent/Breeding.t >@@ -25,10 +25,10 @@ > # TODO We need additional tests for Z3950SearchAuth, BreedingSearch > > use Modern::Perl; >- >-use FindBin; >+use File::Temp qw/tempfile/; > use Test::More tests => 5; > use Test::Warn; >+ > use t::lib::Mocks qw( mock_preference ); > > use C4::Context; >@@ -206,7 +206,7 @@ sub test_do_xslt { > MARC::Field->new('100', ' ', ' ', a => 'John Writer'), > MARC::Field->new('245', ' ', ' ', a => 'Just a title'), > ); >- my $file= $FindBin::Bin.'/XSLT_Handler/test01.xsl'; >+ my $file= xsl_file(); > my $server= { add_xslt => $file }; > my $engine=Koha::XSLT::Base->new; > >@@ -266,3 +266,37 @@ sub test_add_rowdata { > # Test repeatble tags,the trailing whitespace is a normal side-effect of _add_custom_row_data > is_deeply(\$returned_row->{"035\$a"}, \["First 035 ", "Second 035 "],"_add_rowdata supports repeatable tags"); > } >+ >+sub xsl_file { >+ return mytempfile( q{<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim" >+> >+ <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> >+ >+ <xsl:template match="record|marc:record"> >+ <record> >+ <xsl:apply-templates/> >+ <datafield tag="990" ind1='' ind2=''> >+ <subfield code="a"> >+ <xsl:text>I saw you</xsl:text> >+ </subfield> >+ </datafield> >+ </record> >+ </xsl:template> >+ >+ <xsl:template match="node()"> >+ <xsl:copy select="."> >+ <xsl:copy-of select="@*"/> >+ <xsl:apply-templates/> >+ </xsl:copy> >+ </xsl:template> >+</xsl:stylesheet>} ); >+} >+ >+sub mytempfile { >+ my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 ); >+ print $fh $_[0]//''; >+ close $fh; >+ return $fn; >+} >diff --git a/t/db_dependent/Koha/XSLT/Base.t b/t/db_dependent/Koha/XSLT/Base.t >index 6a06d96577..94b3ddfa79 100644 >--- a/t/db_dependent/Koha/XSLT/Base.t >+++ b/t/db_dependent/Koha/XSLT/Base.t >@@ -20,8 +20,9 @@ > use Modern::Perl; > > use FindBin; >+use File::Temp qw/tempfile/; > use File::Slurp; >-use Test::More tests => 35; >+use Test::More tests => 32; > use Test::Warn; > > use Koha::XSLT::Base; >@@ -37,11 +38,8 @@ is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_2, 'Engine returns error on bad fi > is( $engine->refresh( 'asdjhaskjh'), 0, 'Test on invalid refresh' ); > > #check first test xsl >-my $path= $FindBin::Bin.'/XSLT_Handler/'; >-my $xsltfile_1 = 'test01.xsl'; >-is( -e $path.$xsltfile_1, 1, "Found my test stylesheet $xsltfile_1" ); >-exit if !-e $path.$xsltfile_1; >-$xsltfile_1= $path.$xsltfile_1; >+my $xsltfile_1 = xsl_file(1); >+is( -e $xsltfile_1, 1, "Found my test stylesheet $xsltfile_1" ); > > #Testing not-xml strings (undef, empty, some text, malformed xml > my $output; >@@ -135,29 +133,19 @@ is( ref $engine->transform({ > 'Format parameter returns a xml document object' ); > > #The second test xsl contains bad code >-my $xsltfile_2 = 'test02.xsl'; >-is( -e $path.$xsltfile_2, 1, "Found my test stylesheet $xsltfile_2" ); >-exit if !-e $path.$xsltfile_2; >-$xsltfile_2= $path.$xsltfile_2; >- >+my $xsltfile_2 = xsl_file(2); > $engine->print_warns(0); > $output = $engine->transform( $xml_2, $xsltfile_2 ); > is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_4, 'Engine returned error for parsing bad xsl' ); > > #The third test xsl is okay again; main use is clearing two items from cache >-my $xsltfile_3 = 'test03.xsl'; >-is( -e $path.$xsltfile_3, 1, "Found my test stylesheet $xsltfile_3" ); >-exit if !-e $path.$xsltfile_3; >-$xsltfile_3= $path.$xsltfile_3; >+my $xsltfile_3 = xsl_file(3); > $output= $engine->transform( $xml_2, $xsltfile_3 ); > is( $engine->err, undef, 'Unexpected error on transform with third xsl' ); > is( $engine->refresh, 3, 'Final test on clearing cache' ); > >-my $xsltfile_4 = 'test04.xsl'; >-is( -e $path.$xsltfile_4, 1, "Found my test stylesheet $xsltfile_4" ); >-exit if !-e $path.$xsltfile_4; >-$xsltfile_4 = $path.$xsltfile_4; >- >+# File no 4 >+my $xsltfile_4 = xsl_file(4); > my $parameters = { injected_variable => "'this is a test'",}; > $output = $engine->transform({ > xml => $xml_1, >@@ -176,4 +164,89 @@ $output = $engine->transform({ > $dom = XML::LibXML->load_xml(string => $output); > $result = $dom->find( '/just_a_tagname' ); > is ( $result->to_literal(), '', "As expected, no XSLT parameters/variables were added"); >-#End of tests >+ >+sub xsl_file { >+ my $i = shift; >+ return mytempfile( q{<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim" >+> >+ <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> >+ >+ <xsl:template match="record|marc:record"> >+ <record> >+ <xsl:apply-templates/> >+ <datafield tag="990" ind1='' ind2=''> >+ <subfield code="a"> >+ <xsl:text>I saw you</xsl:text> >+ </subfield> >+ </datafield> >+ </record> >+ </xsl:template> >+ >+ <xsl:template match="node()"> >+ <xsl:copy select="."> >+ <xsl:copy-of select="@*"/> >+ <xsl:apply-templates/> >+ </xsl:copy> >+ </xsl:template> >+</xsl:stylesheet>} ) if $i == 1; >+ >+ return mytempfile( q{<!-- This is BAD coded xslt stylesheet --> >+<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim" >+> >+ <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> >+ >+ <xsl:variable name="redefine" select="0"/> >+ <xsl:variable name="redefine" select="1"/> >+ <!-- Intentional redefine to generate parsing error --> >+ <xsl:template match="record"> >+ </xsl:template> >+</xsl:stylesheet>} ) if $i == 2; >+ >+ return mytempfile( q{<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim" >+> >+ <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/> >+ >+ <xsl:template match="/"> >+ <xsl:apply-templates/> >+ </xsl:template> >+ >+ <xsl:template match="node()"> >+ <xsl:copy select="."> >+ <xsl:copy-of select="@*"/> >+ <xsl:apply-templates/> >+ </xsl:copy> >+ </xsl:template> >+</xsl:stylesheet>} ) if $i == 3; >+ >+ return mytempfile( q{<xsl:stylesheet version="1.0" >+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >+ xmlns:marc="http://www.loc.gov/MARC21/slim" >+> >+ <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/> >+ <xsl:param name="injected_variable" /> >+ >+ <xsl:template match="/"> >+ <xsl:apply-templates/> >+ </xsl:template> >+ >+ <xsl:template match="node()"> >+ <xsl:copy> >+ <xsl:value-of select="$injected_variable"/> >+ </xsl:copy> >+ </xsl:template> >+ >+</xsl:stylesheet>} ) if $i == 4; >+} >+ >+sub mytempfile { >+ my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 ); >+ print $fh $_[0]//''; >+ close $fh; >+ return $fn; >+} >diff --git a/t/db_dependent/XSLT_Handler/test01.xsl b/t/db_dependent/XSLT_Handler/test01.xsl >deleted file mode 100644 >index 9200198b8a..0000000000 >--- a/t/db_dependent/XSLT_Handler/test01.xsl >+++ /dev/null >@@ -1,24 +0,0 @@ >-<xsl:stylesheet version="1.0" >- xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >- xmlns:marc="http://www.loc.gov/MARC21/slim" >-> >- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> >- >- <xsl:template match="record|marc:record"> >- <record> >- <xsl:apply-templates/> >- <datafield tag="990" ind1='' ind2=''> >- <subfield code="a"> >- <xsl:text>I saw you</xsl:text> >- </subfield> >- </datafield> >- </record> >- </xsl:template> >- >- <xsl:template match="node()"> >- <xsl:copy select="."> >- <xsl:copy-of select="@*"/> >- <xsl:apply-templates/> >- </xsl:copy> >- </xsl:template> >-</xsl:stylesheet> >diff --git a/t/db_dependent/XSLT_Handler/test02.xsl b/t/db_dependent/XSLT_Handler/test02.xsl >deleted file mode 100644 >index 89f11a5421..0000000000 >--- a/t/db_dependent/XSLT_Handler/test02.xsl >+++ /dev/null >@@ -1,13 +0,0 @@ >-<!-- This is BAD coded xslt stylesheet to test XSLT_Handler --> >-<xsl:stylesheet version="1.0" >- xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >- xmlns:marc="http://www.loc.gov/MARC21/slim" >-> >- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> >- >- <xsl:variable name="redefine" select="0"/> >- <xsl:variable name="redefine" select="1"/> >- <!-- Intentional redefine to generate parsing error --> >- <xsl:template match="record"> >- </xsl:template> >-</xsl:stylesheet> >diff --git a/t/db_dependent/XSLT_Handler/test03.xsl b/t/db_dependent/XSLT_Handler/test03.xsl >deleted file mode 100644 >index 6ade5517c7..0000000000 >--- a/t/db_dependent/XSLT_Handler/test03.xsl >+++ /dev/null >@@ -1,17 +0,0 @@ >-<xsl:stylesheet version="1.0" >- xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >- xmlns:marc="http://www.loc.gov/MARC21/slim" >-> >- <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/> >- >- <xsl:template match="/"> >- <xsl:apply-templates/> >- </xsl:template> >- >- <xsl:template match="node()"> >- <xsl:copy select="."> >- <xsl:copy-of select="@*"/> >- <xsl:apply-templates/> >- </xsl:copy> >- </xsl:template> >-</xsl:stylesheet> >diff --git a/t/db_dependent/XSLT_Handler/test04.xsl b/t/db_dependent/XSLT_Handler/test04.xsl >deleted file mode 100644 >index 7b20ed71fc..0000000000 >--- a/t/db_dependent/XSLT_Handler/test04.xsl >+++ /dev/null >@@ -1,18 +0,0 @@ >-<xsl:stylesheet version="1.0" >- xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >- xmlns:marc="http://www.loc.gov/MARC21/slim" >-> >- <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/> >- <xsl:param name="injected_variable" /> >- >- <xsl:template match="/"> >- <xsl:apply-templates/> >- </xsl:template> >- >- <xsl:template match="node()"> >- <xsl:copy> >- <xsl:value-of select="$injected_variable"/> >- </xsl:copy> >- </xsl:template> >- >-</xsl:stylesheet> >-- >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 24052
:
99686
|
99687
|
99688
|
99689
|
100371
|
100372
|
100373
|
100374
|
100406
|
100407
|
100408
|
100409
|
100453
|
100454
|
100455
|
100456
|
101118
|
101119
|
101120
|
101121