Lines 21-27
use Modern::Perl;
Link Here
|
21 |
|
21 |
|
22 |
use FindBin; |
22 |
use FindBin; |
23 |
use File::Slurp; |
23 |
use File::Slurp; |
24 |
use Test::More tests => 41; |
24 |
use Test::More tests => 35; |
25 |
use Test::Warn; |
25 |
use Test::Warn; |
26 |
|
26 |
|
27 |
use Koha::XSLT_Handler; |
27 |
use Koha::XSLT_Handler; |
Lines 29-43
use Koha::XSLT_Handler;
Link Here
|
29 |
my $engine=Koha::XSLT_Handler->new; |
29 |
my $engine=Koha::XSLT_Handler->new; |
30 |
is( ref $engine, 'Koha::XSLT_Handler', 'Testing creation of handler object' ); |
30 |
is( ref $engine, 'Koha::XSLT_Handler', 'Testing creation of handler object' ); |
31 |
|
31 |
|
32 |
warning_is { $engine->transform('') } #we passed no file at first time |
32 |
$engine->transform(''); |
33 |
"No XSLT file passed.", |
33 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_1, 'Engine returns error on no file' ); |
34 |
"No XSLT warning correctly displayed"; |
|
|
35 |
is( $engine->err, 1, 'Engine returns error on no file' ); |
36 |
|
34 |
|
37 |
warning_is { $engine->transform( '', 'thisfileshouldnotexist.%$#@' ) } |
35 |
$engine->transform( '', 'thisfileshouldnotexist.%$#@' ); |
38 |
"XSLT file not found.", |
36 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_2, 'Engine returns error on bad file' ); |
39 |
"No XSLT warning correctly displayed"; |
|
|
40 |
is( $engine->err, 2, 'Engine returns error on bad file' ); |
41 |
is( $engine->refresh( 'asdjhaskjh'), 0, 'Test on invalid refresh' ); |
37 |
is( $engine->refresh( 'asdjhaskjh'), 0, 'Test on invalid refresh' ); |
42 |
|
38 |
|
43 |
#check first test xsl |
39 |
#check first test xsl |
Lines 51-78
$xsltfile_1= $path.$xsltfile_1;
Link Here
|
51 |
my $output; |
47 |
my $output; |
52 |
|
48 |
|
53 |
# Undefined text tests |
49 |
# Undefined text tests |
54 |
warning_is { $output = $engine->transform( undef, $xsltfile_1 ) } |
50 |
$output = $engine->transform( undef, $xsltfile_1 ); |
55 |
"No string to transform.", |
51 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_7, 'Engine returns error on undefined text' ); |
56 |
"No string warning correctly displayed"; |
|
|
57 |
is( $engine->err, 7, 'Engine returns error on undefined text' ); |
58 |
|
52 |
|
59 |
# Empty string tests |
53 |
# Empty string tests |
60 |
warning_is { $output = $engine->transform( '', $xsltfile_1 ) } |
54 |
$output = $engine->transform( '', $xsltfile_1 ); |
61 |
"Error while parsing input: Empty String", |
55 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_5, 'Engine returns error on empty string' ); |
62 |
"Empty string warning correctly displayed"; |
|
|
63 |
is( $engine->err, 5, 'Engine returns error on empty string' ); |
64 |
|
56 |
|
65 |
# Non-XML tests |
57 |
# Non-XML tests |
|
|
58 |
$engine->print_warns(1); |
66 |
warning_like { $output = $engine->transform( 'abcdef', $xsltfile_1 ) } |
59 |
warning_like { $output = $engine->transform( 'abcdef', $xsltfile_1 ) } |
67 |
qr{^Error while parsing input: :1: parser error : Start tag expected, '<' not found}, |
60 |
qr{parser error : Start tag expected, '<' not found}, |
68 |
"Non-XML warning correctly displayed"; |
61 |
"Non-XML warning correctly displayed"; |
69 |
is( $engine->err, 5, 'Engine returns error on non-xml' ); |
62 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_5, 'Engine returns error on non-xml' ); |
70 |
|
63 |
|
71 |
# Malformed XML tests |
64 |
# Malformed XML tests |
72 |
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) } |
65 |
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) } |
73 |
qr{^Error while parsing input: :1: parser error : Opening and ending tag mismatch: a line 1 and b}, |
66 |
qr{parser error : Opening and ending tag mismatch: a line 1 and b}, |
74 |
"Malformed XML warning correctly displayed"; |
67 |
"Malformed XML warning correctly displayed"; |
75 |
is( $engine->err, 5, 'Engine returns error on malformed xml' ); |
68 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_5, 'Engine returns error on malformed xml' ); |
76 |
|
69 |
|
77 |
#Test not returning source on failure when asked for |
70 |
#Test not returning source on failure when asked for |
78 |
#Include passing do_not_return via constructor on second engine |
71 |
#Include passing do_not_return via constructor on second engine |
Lines 82-99
my $secondengine=Koha::XSLT_Handler->new( {
Link Here
|
82 |
}); |
75 |
}); |
83 |
$engine->do_not_return_source(1); |
76 |
$engine->do_not_return_source(1); |
84 |
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) } |
77 |
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) } |
85 |
qr{^Error while parsing input: :1: parser error : Opening and ending tag mismatch: a line 1 and b}, |
78 |
qr{parser error : Opening and ending tag mismatch: a line 1 and b}, |
86 |
"Malformed XML warning correctly displayed"; |
79 |
"Malformed XML warning correctly displayed"; |
87 |
is( defined $output? 1: 0, 0, 'Engine respects do_not_return_source==1'); |
80 |
is( defined $output? 1: 0, 0, 'Engine respects do_not_return_source==1'); |
|
|
81 |
$secondengine->print_warns(1); |
88 |
warning_like { $output = $secondengine->transform( '<a></b>', $xsltfile_1 ) } |
82 |
warning_like { $output = $secondengine->transform( '<a></b>', $xsltfile_1 ) } |
89 |
qr{^Error while parsing input: :1: parser error : Opening and ending tag mismatch: a line 1 and b}, |
83 |
qr{parser error : Opening and ending tag mismatch: a line 1 and b}, |
90 |
"Malformed XML warning correctly displayed"; |
84 |
"Malformed XML warning correctly displayed"; |
91 |
is( defined $output? 1: 0, 0, 'Second engine respects it too'); |
85 |
is( defined $output? 1: 0, 0, 'Second engine respects it too'); |
92 |
undef $secondengine; #bye |
86 |
undef $secondengine; #bye |
93 |
$engine->do_not_return_source(0); |
87 |
$engine->do_not_return_source(0); |
94 |
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) } |
88 |
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) } |
95 |
qr{^Error while parsing input: :1: parser error : Opening and ending tag mismatch: a line 1 and b}, |
89 |
qr{parser error : Opening and ending tag mismatch: a line 1 and b}, |
96 |
"Malformed XML warning correctly displayed"; |
90 |
"Malformed XML warning correctly displayed"; |
97 |
is( defined $output? 1: 0, 1, 'Engine respects do_not_return_source==0'); |
91 |
is( defined $output? 1: 0, 1, 'Engine respects do_not_return_source==0'); |
98 |
|
92 |
|
99 |
#Testing valid refresh now |
93 |
#Testing valid refresh now |
Lines 146-156
is( -e $path.$xsltfile_2, 1, "Found my test stylesheet $xsltfile_2" );
Link Here
|
146 |
exit if !-e $path.$xsltfile_2; |
140 |
exit if !-e $path.$xsltfile_2; |
147 |
$xsltfile_2= $path.$xsltfile_2; |
141 |
$xsltfile_2= $path.$xsltfile_2; |
148 |
|
142 |
|
149 |
warning_like { $output = $engine->transform( $xml_2, $xsltfile_2 ) } |
143 |
$engine->print_warns(0); |
150 |
qr{^Error while parsing stylesheet:}, |
144 |
$output = $engine->transform( $xml_2, $xsltfile_2 ); |
151 |
"Bad XSL warning correctly displayed"; |
145 |
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_4, 'Engine returned error for parsing bad xsl' ); |
152 |
is( $engine->err, 4, 'Engine returned error for parsing bad xsl' ); |
|
|
153 |
is( defined($engine->errstr), 1, 'Error string contains text'); |
154 |
|
146 |
|
155 |
#The third test xsl is okay again; main use is clearing two items from cache |
147 |
#The third test xsl is okay again; main use is clearing two items from cache |
156 |
my $xsltfile_3 = 'test03.xsl'; |
148 |
my $xsltfile_3 = 'test03.xsl'; |
157 |
- |
|
|