View | Details | Raw Unified | Return to bug 24052
Collapse All | Expand All

(-)a/t/db_dependent/Breeding.t (-3 / +37 lines)
Lines 25-34 Link Here
25
# TODO We need additional tests for Z3950SearchAuth, BreedingSearch
25
# TODO We need additional tests for Z3950SearchAuth, BreedingSearch
26
26
27
use Modern::Perl;
27
use Modern::Perl;
28
28
use File::Temp qw/tempfile/;
29
use FindBin;
30
use Test::More tests => 5;
29
use Test::More tests => 5;
31
use Test::Warn;
30
use Test::Warn;
31
32
use t::lib::Mocks qw( mock_preference );
32
use t::lib::Mocks qw( mock_preference );
33
33
34
use C4::Context;
34
use C4::Context;
Lines 206-212 sub test_do_xslt { Link Here
206
        MARC::Field->new('100', ' ', ' ', a => 'John Writer'),
206
        MARC::Field->new('100', ' ', ' ', a => 'John Writer'),
207
        MARC::Field->new('245', ' ', ' ', a => 'Just a title'),
207
        MARC::Field->new('245', ' ', ' ', a => 'Just a title'),
208
    );
208
    );
209
    my $file= $FindBin::Bin.'/XSLT_Handler/test01.xsl';
209
    my $file= xsl_file();
210
    my $server= { add_xslt => $file };
210
    my $server= { add_xslt => $file };
211
    my $engine=Koha::XSLT::Base->new;
211
    my $engine=Koha::XSLT::Base->new;
212
212
Lines 266-268 sub test_add_rowdata { Link Here
266
   # Test repeatble tags,the trailing whitespace is a normal side-effect of _add_custom_row_data
266
   # Test repeatble tags,the trailing whitespace is a normal side-effect of _add_custom_row_data
267
   is_deeply(\$returned_row->{"035\$a"}, \["First 035 ", "Second 035 "],"_add_rowdata supports repeatable tags");
267
   is_deeply(\$returned_row->{"035\$a"}, \["First 035 ", "Second 035 "],"_add_rowdata supports repeatable tags");
268
}
268
}
269
270
sub xsl_file {
271
    return mytempfile( q{<xsl:stylesheet version="1.0"
272
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
273
    xmlns:marc="http://www.loc.gov/MARC21/slim"
274
>
275
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
276
277
  <xsl:template match="record|marc:record">
278
      <record>
279
      <xsl:apply-templates/>
280
      <datafield tag="990" ind1='' ind2=''>
281
        <subfield code="a">
282
          <xsl:text>I saw you</xsl:text>
283
        </subfield>
284
      </datafield>
285
      </record>
286
  </xsl:template>
287
288
  <xsl:template match="node()">
289
    <xsl:copy select=".">
290
      <xsl:copy-of select="@*"/>
291
      <xsl:apply-templates/>
292
    </xsl:copy>
293
  </xsl:template>
294
</xsl:stylesheet>} );
295
}
296
297
sub mytempfile {
298
    my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 );
299
    print $fh $_[0]//'';
300
    close $fh;
301
    return $fn;
302
}
(-)a/t/db_dependent/Koha/XSLT/Base.t (-21 / +94 lines)
Lines 20-27 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use FindBin;
22
use FindBin;
23
use File::Temp qw/tempfile/;
23
use File::Slurp;
24
use File::Slurp;
24
use Test::More tests => 35;
25
use Test::More tests => 32;
25
use Test::Warn;
26
use Test::Warn;
26
27
27
use Koha::XSLT::Base;
28
use Koha::XSLT::Base;
Lines 37-47 is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_2, 'Engine returns error on bad fi Link Here
37
is( $engine->refresh( 'asdjhaskjh'), 0, 'Test on invalid refresh' );
38
is( $engine->refresh( 'asdjhaskjh'), 0, 'Test on invalid refresh' );
38
39
39
#check first test xsl
40
#check first test xsl
40
my $path= $FindBin::Bin.'/XSLT_Handler/';
41
my $xsltfile_1 = xsl_file(1);
41
my $xsltfile_1 = 'test01.xsl';
42
is( -e $xsltfile_1, 1, "Found my test stylesheet $xsltfile_1" );
42
is( -e $path.$xsltfile_1, 1, "Found my test stylesheet $xsltfile_1" );
43
exit if !-e $path.$xsltfile_1;
44
$xsltfile_1= $path.$xsltfile_1;
45
43
46
#Testing not-xml strings (undef, empty, some text, malformed xml
44
#Testing not-xml strings (undef, empty, some text, malformed xml
47
my $output;
45
my $output;
Lines 135-163 is( ref $engine->transform({ Link Here
135
'Format parameter returns a xml document object' );
133
'Format parameter returns a xml document object' );
136
134
137
#The second test xsl contains bad code
135
#The second test xsl contains bad code
138
my $xsltfile_2 = 'test02.xsl';
136
my $xsltfile_2 = xsl_file(2);
139
is( -e $path.$xsltfile_2, 1, "Found my test stylesheet $xsltfile_2" );
140
exit if !-e $path.$xsltfile_2;
141
$xsltfile_2= $path.$xsltfile_2;
142
143
$engine->print_warns(0);
137
$engine->print_warns(0);
144
$output = $engine->transform( $xml_2, $xsltfile_2 );
138
$output = $engine->transform( $xml_2, $xsltfile_2 );
145
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_4, 'Engine returned error for parsing bad xsl' );
139
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_4, 'Engine returned error for parsing bad xsl' );
146
140
147
#The third test xsl is okay again; main use is clearing two items from cache
141
#The third test xsl is okay again; main use is clearing two items from cache
148
my $xsltfile_3 = 'test03.xsl';
142
my $xsltfile_3 = xsl_file(3);
149
is( -e $path.$xsltfile_3, 1, "Found my test stylesheet $xsltfile_3" );
150
exit if !-e $path.$xsltfile_3;
151
$xsltfile_3= $path.$xsltfile_3;
152
$output= $engine->transform( $xml_2, $xsltfile_3 );
143
$output= $engine->transform( $xml_2, $xsltfile_3 );
153
is( $engine->err, undef, 'Unexpected error on transform with third xsl' );
144
is( $engine->err, undef, 'Unexpected error on transform with third xsl' );
154
is( $engine->refresh, 3, 'Final test on clearing cache' );
145
is( $engine->refresh, 3, 'Final test on clearing cache' );
155
146
156
my $xsltfile_4 = 'test04.xsl';
147
# File no 4
157
is( -e $path.$xsltfile_4, 1, "Found my test stylesheet $xsltfile_4" );
148
my $xsltfile_4 = xsl_file(4);
158
exit if !-e $path.$xsltfile_4;
159
$xsltfile_4 = $path.$xsltfile_4;
160
161
my $parameters = { injected_variable => "'this is a test'",};
149
my $parameters = { injected_variable => "'this is a test'",};
162
$output = $engine->transform({
150
$output = $engine->transform({
163
            xml => $xml_1,
151
            xml => $xml_1,
Lines 176-179 $output = $engine->transform({ Link Here
176
$dom = XML::LibXML->load_xml(string => $output);
164
$dom = XML::LibXML->load_xml(string => $output);
177
$result = $dom->find( '/just_a_tagname' );
165
$result = $dom->find( '/just_a_tagname' );
178
is ( $result->to_literal(), '', "As expected, no XSLT parameters/variables were added");
166
is ( $result->to_literal(), '', "As expected, no XSLT parameters/variables were added");
179
#End of tests
167
168
sub xsl_file {
169
    my $i = shift;
170
    return mytempfile( q{<xsl:stylesheet version="1.0"
171
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
172
    xmlns:marc="http://www.loc.gov/MARC21/slim"
173
>
174
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
175
176
  <xsl:template match="record|marc:record">
177
      <record>
178
      <xsl:apply-templates/>
179
      <datafield tag="990" ind1='' ind2=''>
180
        <subfield code="a">
181
          <xsl:text>I saw you</xsl:text>
182
        </subfield>
183
      </datafield>
184
      </record>
185
  </xsl:template>
186
187
  <xsl:template match="node()">
188
    <xsl:copy select=".">
189
      <xsl:copy-of select="@*"/>
190
      <xsl:apply-templates/>
191
    </xsl:copy>
192
  </xsl:template>
193
</xsl:stylesheet>} ) if $i == 1;
194
195
    return mytempfile( q{<!-- This is BAD coded xslt stylesheet -->
196
<xsl:stylesheet version="1.0"
197
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
198
    xmlns:marc="http://www.loc.gov/MARC21/slim"
199
>
200
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
201
202
  <xsl:variable name="redefine" select="0"/>
203
  <xsl:variable name="redefine" select="1"/>
204
      <!-- Intentional redefine to generate parsing error -->
205
  <xsl:template match="record">
206
  </xsl:template>
207
</xsl:stylesheet>} ) if $i == 2;
208
209
    return mytempfile( q{<xsl:stylesheet version="1.0"
210
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
211
    xmlns:marc="http://www.loc.gov/MARC21/slim"
212
>
213
  <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/>
214
215
  <xsl:template match="/">
216
      <xsl:apply-templates/>
217
  </xsl:template>
218
219
  <xsl:template match="node()">
220
    <xsl:copy select=".">
221
      <xsl:copy-of select="@*"/>
222
      <xsl:apply-templates/>
223
    </xsl:copy>
224
  </xsl:template>
225
</xsl:stylesheet>} ) if $i == 3;
226
227
    return mytempfile( q{<xsl:stylesheet version="1.0"
228
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
229
    xmlns:marc="http://www.loc.gov/MARC21/slim"
230
>
231
  <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/>
232
  <xsl:param name="injected_variable" />
233
234
  <xsl:template match="/">
235
      <xsl:apply-templates/>
236
  </xsl:template>
237
238
  <xsl:template match="node()">
239
    <xsl:copy>
240
   <xsl:value-of select="$injected_variable"/>
241
    </xsl:copy>
242
  </xsl:template>
243
244
</xsl:stylesheet>} ) if $i == 4;
245
}
246
247
sub mytempfile {
248
    my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 );
249
    print $fh $_[0]//'';
250
    close $fh;
251
    return $fn;
252
}
(-)a/t/db_dependent/XSLT_Handler/test01.xsl (-24 lines)
Lines 1-24 Link Here
1
<xsl:stylesheet version="1.0"
2
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:marc="http://www.loc.gov/MARC21/slim"
4
>
5
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
6
7
  <xsl:template match="record|marc:record">
8
      <record>
9
      <xsl:apply-templates/>
10
      <datafield tag="990" ind1='' ind2=''>
11
        <subfield code="a">
12
          <xsl:text>I saw you</xsl:text>
13
        </subfield>
14
      </datafield>
15
      </record>
16
  </xsl:template>
17
18
  <xsl:template match="node()">
19
    <xsl:copy select=".">
20
      <xsl:copy-of select="@*"/>
21
      <xsl:apply-templates/>
22
    </xsl:copy>
23
  </xsl:template>
24
</xsl:stylesheet>
(-)a/t/db_dependent/XSLT_Handler/test02.xsl (-13 lines)
Lines 1-13 Link Here
1
<!-- This is BAD coded xslt stylesheet to test XSLT_Handler -->
2
<xsl:stylesheet version="1.0"
3
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
    xmlns:marc="http://www.loc.gov/MARC21/slim"
5
>
6
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
7
8
  <xsl:variable name="redefine" select="0"/>
9
  <xsl:variable name="redefine" select="1"/>
10
      <!-- Intentional redefine to generate parsing error -->
11
  <xsl:template match="record">
12
  </xsl:template>
13
</xsl:stylesheet>
(-)a/t/db_dependent/XSLT_Handler/test03.xsl (-17 lines)
Lines 1-17 Link Here
1
<xsl:stylesheet version="1.0"
2
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:marc="http://www.loc.gov/MARC21/slim"
4
>
5
  <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/>
6
7
  <xsl:template match="/">
8
      <xsl:apply-templates/>
9
  </xsl:template>
10
11
  <xsl:template match="node()">
12
    <xsl:copy select=".">
13
      <xsl:copy-of select="@*"/>
14
      <xsl:apply-templates/>
15
    </xsl:copy>
16
  </xsl:template>
17
</xsl:stylesheet>
(-)a/t/db_dependent/XSLT_Handler/test04.xsl (-19 lines)
Lines 1-18 Link Here
1
<xsl:stylesheet version="1.0"
2
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:marc="http://www.loc.gov/MARC21/slim"
4
>
5
  <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/>
6
  <xsl:param name="injected_variable" />
7
8
  <xsl:template match="/">
9
      <xsl:apply-templates/>
10
  </xsl:template>
11
12
  <xsl:template match="node()">
13
    <xsl:copy>
14
   <xsl:value-of select="$injected_variable"/>
15
    </xsl:copy>
16
  </xsl:template>
17
18
</xsl:stylesheet>
19
- 

Return to bug 24052