Bugzilla – Attachment 27870 Details for
Bug 11826
Improving code for XSLT handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 11826: Add unit tests for Koha::XSLT_Handler
SIGNED-OFF-Bug-11826-Add-unit-tests-for-KohaXSLTHa.patch (text/plain), 8.24 KB, created by
Bernardo Gonzalez Kriegel
on 2014-05-01 13:13:56 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 11826: Add unit tests for Koha::XSLT_Handler
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2014-05-01 13:13:56 UTC
Size:
8.24 KB
patch
obsolete
>From f5fb847c2dfd8cc71be025bb6e59fe752dd6655b Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 21 Feb 2014 17:21:55 +0100 >Subject: [PATCH] [SIGNED-OFF] Bug 11826: Add unit tests for > Koha::XSLT_Handler > >Test plan: >Verify if XSLT_Handler.t passes. >You could also sabotage the test by removing one of the test xsl files. >Or you could 'repair' the bad xsl file (test02). Remove the second line >redefining the xsl variable. >In all those cases the unit test should fail now.. Discard your changes :) > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Test pass. No koha-qa errors. >--- > t/db_dependent/XSLT_Handler.t | 119 ++++++++++++++++++++++++++++++++ > t/db_dependent/XSLT_Handler/test01.xsl | 24 +++++++ > t/db_dependent/XSLT_Handler/test02.xsl | 13 ++++ > t/db_dependent/XSLT_Handler/test03.xsl | 17 +++++ > 4 files changed, 173 insertions(+) > create mode 100644 t/db_dependent/XSLT_Handler.t > create mode 100644 t/db_dependent/XSLT_Handler/test01.xsl > create mode 100644 t/db_dependent/XSLT_Handler/test02.xsl > create mode 100644 t/db_dependent/XSLT_Handler/test03.xsl > >diff --git a/t/db_dependent/XSLT_Handler.t b/t/db_dependent/XSLT_Handler.t >new file mode 100644 >index 0000000..8bdfdef >--- /dev/null >+++ b/t/db_dependent/XSLT_Handler.t >@@ -0,0 +1,119 @@ >+#!/usr/bin/perl >+ >+# Copyright 2014 Rijksmuseum >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use FindBin; >+use Test::More tests => 24; >+ >+use Koha::XSLT_Handler; >+ >+my $engine=Koha::XSLT_Handler->new; >+is( ref $engine, 'Koha::XSLT_Handler', 'Testing creation of handler object' ); >+ >+$engine->transform(''); #we passed no file at first time >+is( $engine->err, 1, 'Engine returns error on no file' ); >+ >+$engine->transform( '', 'thisfileshouldnotexist.%$#@' ); >+is( $engine->err, 2, 'Engine returns error on bad file' ); >+ >+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; >+ >+#Testing not-xml strings (undef, empty, some text, malformed xml >+my $output= $engine->transform( undef, $xsltfile_1 ); >+is( $engine->err, 7, 'Engine returns error on undefined text' ); >+$output= $engine->transform( '', $xsltfile_1 ); >+is( $engine->err, 5, 'Engine returns error on empty string' ); >+$output= $engine->transform( 'abcdef', $xsltfile_1 ); >+is( $engine->err, 5, 'Engine returns error on non-xml' ); >+$output= $engine->transform( '<a></b>', $xsltfile_1 ); >+is( $engine->err, 5, 'Engine returns error on malformed xml' ); >+ >+#Test not returning source on failure when asked for >+#Include passing do_not_return via constructor on second engine >+my $secondengine=Koha::XSLT_Handler->new( { >+ do_not_return_source => 'very_true', >+ some_unknown_attrib => 'just_for_fun', >+}); >+$engine->do_not_return_source(1); >+$output= $engine->transform( '<a></b>', $xsltfile_1 ); >+is( defined $output? 1: 0, 0, 'Engine respects do_not_return_source==1'); >+$output= $secondengine->transform( '<a></b>', $xsltfile_1 ); >+is( defined $output? 1: 0, 0, 'Second engine respects it too'); >+undef $secondengine; #bye >+$engine->do_not_return_source(0); >+$output= $engine->transform( '<a></b>', $xsltfile_1 ); >+is( defined $output? 1: 0, 1, 'Engine respects do_not_return_source==0'); >+ >+#Testing valid refresh now >+is( $engine->refresh($xsltfile_1), 1, 'Test on valid refresh' ); >+#A second time (for all) should return 0 now >+is( $engine->refresh, 0, 'Test on repeated refresh' ); >+ >+#Testing a string that should not change too much >+my $xml_1=<<'EOT'; >+<just_a_tagname> >+</just_a_tagname> >+EOT >+$output= $engine->transform( $xml_1, $xsltfile_1 ); >+is( $engine->err, undef, 'Engine returned no error for xml_1' ); >+is( index($output,'<just_a_tagname>')>0, 1, 'No real change expected for xml_1' ); #Just very simple check if the tag was still there >+ >+#Test of adding a new datafield to rudimentary 'marc record' >+my $xml_2=<<'EOT'; >+<?xml version="1.0" encoding="UTF-8"?> >+<collection> >+<record> >+<controlfield tag="001">1234</controlfield> >+<datafield tag="245" ind1="1" ind2="0"><subfield tag="a">My favorite title</subfield></datafield> >+</record> >+</collection> >+EOT >+$output= $engine->transform( $xml_2 ); >+ #note: second parameter (file) not passed again >+is( $engine->err, undef, 'Engine returned no error for xml_2' ); >+is( index($output,'I saw you')>0, 1, 'Saw the expected change for xml_2' ); #Just very simple check if new datafield was added >+ >+#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; >+ >+$output= $engine->transform( $xml_2, $xsltfile_2 ); >+is( $engine->err, 4, 'Engine returned error for parsing bad xsl' ); >+is( defined($engine->errstr), 1, 'Error string contains text'); >+ >+#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; >+$output= $engine->transform( $xml_2, $xsltfile_3 ); >+is( $engine->err, undef, 'Unexpected error on transform with third xsl' ); >+is( $engine->refresh, 2, 'Final test on clearing cache' ); >+ >+#End of tests >diff --git a/t/db_dependent/XSLT_Handler/test01.xsl b/t/db_dependent/XSLT_Handler/test01.xsl >new file mode 100644 >index 0000000..3c2b188 >--- /dev/null >+++ b/t/db_dependent/XSLT_Handler/test01.xsl >@@ -0,0 +1,24 @@ >+<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"> >+ <record> >+ <xsl:apply-templates/> >+ <datafield tag="990"> >+ <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 >new file mode 100644 >index 0000000..89f11a5 >--- /dev/null >+++ b/t/db_dependent/XSLT_Handler/test02.xsl >@@ -0,0 +1,13 @@ >+<!-- 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 >new file mode 100644 >index 0000000..6ade551 >--- /dev/null >+++ b/t/db_dependent/XSLT_Handler/test03.xsl >@@ -0,0 +1,17 @@ >+<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> >-- >1.7.9.5
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 11826
:
25573
|
25574
|
27229
|
27230
|
27869
|
27870
|
27871
|
27872
|
28093
|
28094
|
28095
|
28096
|
28174