libxslt-ruby 1.1.1-x64-mingw32 → 1.2.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,70 +1,69 @@
1
- # encoding: UTF-8
2
- require 'test/unit'
3
- require 'test_helper'
4
-
5
- class TestExslt < Test::Unit::TestCase
6
- def setup
7
- @namespace = 'http://test.ext'
8
- @name = 'ext-func'
9
- @func = lambda { |xp| xp.to_a.join('|') }
10
- end
11
-
12
- def teardown
13
- LibXSLT::XSLT.instance_variable_get(:@module_function_registry).clear
14
- # or
15
- #LibXSLT::XSLT.unregister_module_function(@namespace, @name)
16
- end
17
-
18
- def test_register
19
- assert !LibXSLT::XSLT.registered_module_function?(@namespace, @name)
20
- assert LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
21
- assert LibXSLT::XSLT.registered_module_function?(@namespace, @name)
22
- end
23
-
24
- def test_register_no_block
25
- assert_raises(ArgumentError, 'no block given') {
26
- LibXSLT::XSLT.register_module_function(@namespace, @name)
27
- }
28
- end
29
-
30
- def test_register_repeated
31
- assert_equal @func, LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
32
- assert_equal @func, LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
33
- assert_not_equal @func, LibXSLT::XSLT.register_module_function(@namespace, @name) { |*| }
34
- end
35
-
36
- def test_unregister
37
- test_register # need to register before we can unregister
38
- assert LibXSLT::XSLT.unregister_module_function(@namespace, @name)
39
- assert !LibXSLT::XSLT.registered_module_function?(@namespace, @name)
40
- end
41
-
42
- def test_unregister_no_register
43
- assert !LibXSLT::XSLT.registered_module_function?(@namespace, @name)
44
- assert !LibXSLT::XSLT.unregister_module_function(@namespace, @name)
45
- end
46
-
47
- def test_unregister_repeated
48
- test_register # need to register before we can unregister
49
- assert_equal @func, LibXSLT::XSLT.unregister_module_function(@namespace, @name)
50
- assert_nil LibXSLT::XSLT.unregister_module_function(@namespace, @name)
51
- end
52
-
53
- def test_callback
54
- doc = XML::Document.file(File.join(File.dirname(__FILE__), 'files/fuzface.xml'))
55
- xpath = '/commentary/meta/author/*'
56
- stylesheet = XSLT::Stylesheet.new(XML::Document.string(<<-EOT))
57
- <?xml version="1.0" ?>
58
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="#{@namespace}">
59
- <xsl:template match="/">
60
- <xsl:element name="root">
61
- <xsl:value-of select="ext:#{@name}(#{xpath})" />
62
- </xsl:element>
63
- </xsl:template>
64
- </xsl:stylesheet>
65
- EOT
66
-
67
- assert LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
68
- assert_equal @func[doc.find(xpath)], stylesheet.apply(doc).root.content
69
- end
70
- end
1
+ # encoding: UTF-8
2
+ require_relative './test_helper'
3
+
4
+ class TestExslt < Minitest::Test
5
+ def setup
6
+ @namespace = 'http://test.ext'
7
+ @name = 'ext-func'
8
+ @func = lambda { |xp| xp.to_a.join('|') }
9
+ end
10
+
11
+ def teardown
12
+ LibXSLT::XSLT.instance_variable_get(:@module_function_registry).clear
13
+ # or
14
+ #LibXSLT::XSLT.unregister_module_function(@namespace, @name)
15
+ end
16
+
17
+ def test_register
18
+ assert !LibXSLT::XSLT.registered_module_function?(@namespace, @name)
19
+ assert LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
20
+ assert LibXSLT::XSLT.registered_module_function?(@namespace, @name)
21
+ end
22
+
23
+ def test_register_no_block
24
+ assert_raises(ArgumentError, 'no block given') {
25
+ LibXSLT::XSLT.register_module_function(@namespace, @name)
26
+ }
27
+ end
28
+
29
+ def test_register_repeated
30
+ assert_equal @func, LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
31
+ assert_equal @func, LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
32
+ refute_equal @func, LibXSLT::XSLT.register_module_function(@namespace, @name) { |*| }
33
+ end
34
+
35
+ def test_unregister
36
+ test_register # need to register before we can unregister
37
+ assert LibXSLT::XSLT.unregister_module_function(@namespace, @name)
38
+ assert !LibXSLT::XSLT.registered_module_function?(@namespace, @name)
39
+ end
40
+
41
+ def test_unregister_no_register
42
+ assert !LibXSLT::XSLT.registered_module_function?(@namespace, @name)
43
+ assert !LibXSLT::XSLT.unregister_module_function(@namespace, @name)
44
+ end
45
+
46
+ def test_unregister_repeated
47
+ test_register # need to register before we can unregister
48
+ assert_equal @func, LibXSLT::XSLT.unregister_module_function(@namespace, @name)
49
+ assert_nil LibXSLT::XSLT.unregister_module_function(@namespace, @name)
50
+ end
51
+
52
+ def test_callback
53
+ doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'files/fuzface.xml'))
54
+ xpath = '/commentary/meta/author/*'
55
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(LibXML::XML::Document.string(<<-EOT))
56
+ <?xml version="1.0" ?>
57
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="#{@namespace}">
58
+ <xsl:template match="/">
59
+ <xsl:element name="root">
60
+ <xsl:value-of select="ext:#{@name}(#{xpath})" />
61
+ </xsl:element>
62
+ </xsl:template>
63
+ </xsl:stylesheet>
64
+ EOT
65
+
66
+ assert LibXSLT::XSLT.register_module_function(@namespace, @name, &@func)
67
+ assert_equal @func[doc.find(xpath)], stylesheet.apply(doc).root.content
68
+ end
69
+ end
@@ -1,15 +1,5 @@
1
- # encoding: UTF-8
2
- # To make testing/debugging easier, test within this source tree versus an installed gem
3
-
4
- dir = File.dirname(__FILE__)
5
- root = File.expand_path(File.join(dir, '..'))
6
- lib = File.expand_path(File.join(root, 'lib'))
7
-
8
- $LOAD_PATH << lib
9
-
10
- begin
11
- require 'xslt'
12
- rescue LoadError
13
- require 'rubygems'
14
- require 'xslt'
15
- end
1
+ # encoding: UTF-8
2
+
3
+ require 'bundler/setup'
4
+ require 'minitest/autorun'
5
+ require 'libxslt-ruby'
@@ -1,22 +1,20 @@
1
- # encoding: UTF-8
2
- require 'test/unit'
3
- require 'test_helper'
4
-
5
- class TextLibXslt < Test::Unit::TestCase
6
- def test_constants
7
- assert_instance_of(Fixnum, XSLT::MAX_DEPTH)
8
- assert_instance_of(Fixnum, XSLT::MAX_SORT)
9
- assert_instance_of(String, XSLT::ENGINE_VERSION)
10
- assert_instance_of(Fixnum, XSLT::LIBXSLT_VERSION)
11
- assert_instance_of(Fixnum, XSLT::LIBXML_VERSION)
12
- assert_instance_of(String, XSLT::XSLT_NAMESPACE)
13
- assert_instance_of(String, XSLT::DEFAULT_URL)
14
- assert_instance_of(String, XSLT::DEFAULT_VENDOR)
15
- assert_instance_of(String, XSLT::DEFAULT_VERSION)
16
- assert_instance_of(String, XSLT::NAMESPACE_LIBXSLT)
17
- assert_instance_of(String, XSLT::NAMESPACE_SAXON)
18
- assert_instance_of(String, XSLT::NAMESPACE_XT)
19
- assert_instance_of(String, XSLT::NAMESPACE_XALAN)
20
- assert_instance_of(String, XSLT::NAMESPACE_NORM_SAXON)
21
- end
22
- end
1
+ # encoding: UTF-8
2
+ require_relative './test_helper'
3
+
4
+ class TextLibXslt < Minitest::Test
5
+ def test_constants
6
+ assert_instance_of(Fixnum, LibXSLT::XSLT::MAX_DEPTH)
7
+ assert_instance_of(Fixnum, LibXSLT::XSLT::MAX_SORT)
8
+ assert_instance_of(String, LibXSLT::XSLT::ENGINE_VERSION)
9
+ assert_instance_of(Fixnum, LibXSLT::XSLT::LIBXSLT_VERSION)
10
+ assert_instance_of(Fixnum, LibXSLT::XSLT::LIBXML_VERSION)
11
+ assert_instance_of(String, LibXSLT::XSLT::XSLT_NAMESPACE)
12
+ assert_instance_of(String, LibXSLT::XSLT::DEFAULT_URL)
13
+ assert_instance_of(String, LibXSLT::XSLT::DEFAULT_VENDOR)
14
+ assert_instance_of(String, LibXSLT::XSLT::DEFAULT_VERSION)
15
+ assert_instance_of(String, LibXSLT::XSLT::NAMESPACE_LIBXSLT)
16
+ assert_instance_of(String, LibXSLT::XSLT::NAMESPACE_SAXON)
17
+ assert_instance_of(String, LibXSLT::XSLT::NAMESPACE_XT)
18
+ assert_instance_of(String, LibXSLT::XSLT::NAMESPACE_XALAN)
19
+ end
20
+ end
@@ -1,214 +1,213 @@
1
- # encoding: UTF-8
2
- require 'test/unit'
3
- require 'test_helper'
4
-
5
- class TestStylesheet < Test::Unit::TestCase
6
- def setup
7
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
8
- doc = XML::Document.file(filename)
9
- @stylesheet = XSLT::Stylesheet.new(doc)
10
- end
11
-
12
- def tear_down
13
- @stylesheet = nil
14
- end
15
-
16
- def doc
17
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xml')
18
- XML::Document.file(filename)
19
- end
20
-
21
- def test_class
22
- assert_instance_of(XSLT::Stylesheet, @stylesheet)
23
- end
24
-
25
- def test_apply
26
- result = @stylesheet.apply(doc)
27
- assert_instance_of(XML::Document, result)
28
-
29
- paragraphs = result.find('//p')
30
- assert_equal(11, paragraphs.length)
31
- end
32
-
33
- def test_apply_multiple
34
- 10.times do
35
- test_apply
36
- end
37
- end
38
-
39
- def test_params
40
- filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
41
- sdoc = XML::Document.file(filename)
42
-
43
- filename = File.join(File.dirname(__FILE__), 'files/params.xml')
44
- stylesheet = XSLT::Stylesheet.new(sdoc)
45
- doc = XML::Document.file(filename)
46
-
47
- # Start with no params
48
- result = stylesheet.apply(doc)
49
- assert_equal('<article>failure</article>', result.root.to_s)
50
-
51
- # Now try with params as hash. /doc is evaluated
52
- # as an xpath expression
53
- result = stylesheet.apply(doc, 'bar' => "/doc")
54
- assert_equal('<article>abc</article>', result.root.to_s)
55
-
56
- # Now try with params as hash. Note the double quote
57
- # on success - we want to pass a literal string and
58
- # not an xpath expression.
59
- result = stylesheet.apply(doc, 'bar' => "'success'")
60
- assert_equal('<article>success</article>', result.root.to_s)
61
-
62
- # Now try with params as an array.
63
- result = stylesheet.apply(doc, ['bar', "'success'"])
64
- assert_equal('<article>success</article>', result.root.to_s)
65
-
66
- # Now try with invalid array.
67
- result = stylesheet.apply(doc, ['bar'])
68
- assert_equal('<article>failure</article>', result.root.to_s)
69
- end
70
-
71
- # -- Memory Tests ----
72
- def test_doc_ownership
73
- 10.times do
74
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
75
- sdoc = XML::Document.file(filename)
76
- GC.start
77
- assert_equal(173, sdoc.to_s.length)
78
- end
79
- end
80
-
81
- def test_stylesheet_ownership
82
- 10.times do
83
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
84
- sdoc = XML::Document.file(filename)
85
- stylesheet = XSLT::Stylesheet.new(sdoc)
86
-
87
- sdoc = nil
88
- GC.start
89
-
90
- rdoc = stylesheet.apply(doc)
91
- assert_equal(5963, rdoc.to_s.length)
92
- end
93
- end
94
-
95
- def test_result_ownership
96
- 10.times do
97
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
98
- sdoc = XML::Document.file(filename)
99
- stylesheet = XSLT::Stylesheet.new(sdoc)
100
-
101
- rdoc = stylesheet.apply(doc)
102
- rdoc = nil
103
- GC.start
104
- end
105
- end
106
-
107
- #RAF#
108
- def test_stylesheet_string
109
- filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
110
- style = File.open(filename).readline(nil)
111
- stylesheet = XSLT::Stylesheet.string(style)
112
- assert_instance_of(XSLT::Stylesheet, stylesheet)
113
- end
114
-
115
- def test_stylesheet_file
116
- filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
117
- stylesheet = XSLT::Stylesheet.file(filename)
118
- assert_instance_of(XSLT::Stylesheet, stylesheet)
119
- end
120
-
121
- def test_stylesheet_io
122
- filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
123
- stylesheet = XSLT::Stylesheet.io(File.open(filename))
124
- assert_instance_of(XSLT::Stylesheet, stylesheet)
125
- end
126
-
127
- def test_output
128
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
129
- sdoc = XML::Document.file(filename)
130
- stylesheet = XSLT::Stylesheet.new(sdoc)
131
-
132
- rdoc = stylesheet.apply(doc)
133
-
134
- xml = stylesheet.output(rdoc)
135
-
136
- # output method is html -> no xml decl, empty tags not closed...
137
- assert xml =~ /^<html>/
138
- assert xml =~ /<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8">\n<title>/
139
- end
140
-
141
- def test_transform
142
- filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
143
- sdoc = XML::Document.file(filename)
144
- stylesheet = XSLT::Stylesheet.new(sdoc)
145
-
146
- xml = stylesheet.transform(doc)
147
-
148
- assert xml =~ /<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8">\n<title>/
149
- end
150
-
151
- def test_entities
152
- style = <<EOF
153
- <!DOCTYPE xsl:stylesheet [
154
- <!ENTITY foo 'bar'>
155
- ]>
156
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
157
- <xsl:template match="a">
158
- <out><xsl:text>&foo;</xsl:text>
159
- <xsl:apply-templates/></out>
160
- </xsl:template>
161
- </xsl:stylesheet>
162
- EOF
163
-
164
- styledoc = LibXML::XML::Parser.string(style, :options => XSLT::Stylesheet::PARSE_OPTIONS).parse
165
- stylesheet = XSLT::Stylesheet.new(styledoc)
166
-
167
- xml = "<!DOCTYPE a [<!ENTITY bla 'fasel'>]><a>&bla;</a>"
168
- doc = XML::Parser.string(xml, :options => XSLT::Stylesheet::PARSE_OPTIONS).parse
169
-
170
- out = stylesheet.apply( doc )
171
- dump = stylesheet.output( out )
172
- assert_match( /<out>barfasel<\/out>/, dump)
173
-
174
- # no entity replacement in document
175
- doc = XML::Parser.string(xml, :options => 0).parse
176
- out = stylesheet.apply( doc )
177
- dump = stylesheet.output( out )
178
-
179
- assert_match(/<out>bar<\/out>/, dump) # entity content is missing
180
-
181
- # note: having entities in your stylesheet that are not replaced during
182
- # parse, will crash libxslt (segfault)
183
- # seems to be a libxslt problem; you should not do that anyway
184
- # styledoc = LibXML::XML::Parser.string(style, : options => 0).parse
185
- # stylesheet = XSLT::Stylesheet.new(styledoc)
186
- end
187
-
188
- def test_cdatasection
189
- doc = XML::Parser.string("<a/>").parse
190
-
191
- style = <<EOF
192
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
193
- <xsl:template match="a">
194
- <out><xsl:text disable-output-escaping="yes"><![CDATA[<>]]></xsl:text></out>
195
- </xsl:template>
196
- </xsl:stylesheet>
197
- EOF
198
-
199
- styledoc = LibXML::XML::Parser.string(style, :options => XSLT::Stylesheet::PARSE_OPTIONS).parse
200
- stylesheet = XSLT::Stylesheet.new(styledoc)
201
-
202
- out = stylesheet.apply( doc )
203
- dump = stylesheet.output( out )
204
- assert_match( /<out><><\/out>/, dump)
205
-
206
- # without propper parse options (result is wrong from an xml/xslt point of view)
207
- styledoc = LibXML::XML::Parser.string(style).parse
208
- stylesheet = XSLT::Stylesheet.new(styledoc)
209
-
210
- out = stylesheet.apply( doc )
211
- dump = stylesheet.output( out )
212
- assert_match( /<out>&lt;&gt;<\/out>/, dump)
213
- end
214
- end
1
+ # encoding: UTF-8
2
+ require_relative './test_helper'
3
+
4
+ class TestStylesheet < Minitest::Test
5
+ def setup
6
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
7
+ doc = LibXML::XML::Document.file(filename)
8
+ @stylesheet = LibXSLT::XSLT::Stylesheet.new(doc)
9
+ end
10
+
11
+ def tear_down
12
+ @stylesheet = nil
13
+ end
14
+
15
+ def doc
16
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xml')
17
+ LibXML::XML::Document.file(filename)
18
+ end
19
+
20
+ def test_class
21
+ assert_instance_of(LibXSLT::XSLT::Stylesheet, @stylesheet)
22
+ end
23
+
24
+ def test_apply
25
+ result = @stylesheet.apply(doc)
26
+ assert_instance_of(LibXML::XML::Document, result)
27
+
28
+ paragraphs = result.find('//p')
29
+ assert_equal(11, paragraphs.length)
30
+ end
31
+
32
+ def test_apply_multiple
33
+ 10.times do
34
+ test_apply
35
+ end
36
+ end
37
+
38
+ def test_params
39
+ filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
40
+ sdoc = LibXML::XML::Document.file(filename)
41
+
42
+ filename = File.join(File.dirname(__FILE__), 'files/params.xml')
43
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(sdoc)
44
+ doc = LibXML::XML::Document.file(filename)
45
+
46
+ # Start with no params
47
+ result = stylesheet.apply(doc)
48
+ assert_equal('<article>failure</article>', result.root.to_s)
49
+
50
+ # Now try with params as hash. /doc is evaluated
51
+ # as an xpath expression
52
+ result = stylesheet.apply(doc, 'bar' => "/doc")
53
+ assert_equal('<article>abc</article>', result.root.to_s)
54
+
55
+ # Now try with params as hash. Note the double quote
56
+ # on success - we want to pass a literal string and
57
+ # not an xpath expression.
58
+ result = stylesheet.apply(doc, 'bar' => "'success'")
59
+ assert_equal('<article>success</article>', result.root.to_s)
60
+
61
+ # Now try with params as an array.
62
+ result = stylesheet.apply(doc, ['bar', "'success'"])
63
+ assert_equal('<article>success</article>', result.root.to_s)
64
+
65
+ # Now try with invalid array.
66
+ result = stylesheet.apply(doc, ['bar'])
67
+ assert_equal('<article>failure</article>', result.root.to_s)
68
+ end
69
+
70
+ # -- Memory Tests ----
71
+ def test_doc_ownership
72
+ 10.times do
73
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
74
+ sdoc = LibXML::XML::Document.file(filename)
75
+ GC.start
76
+ assert_equal(173, sdoc.to_s.length)
77
+ end
78
+ end
79
+
80
+ def test_stylesheet_ownership
81
+ 10.times do
82
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
83
+ sdoc = LibXML::XML::Document.file(filename)
84
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(sdoc)
85
+
86
+ sdoc = nil
87
+ GC.start
88
+
89
+ rdoc = stylesheet.apply(doc)
90
+ assert_equal(5963, rdoc.to_s.length)
91
+ end
92
+ end
93
+
94
+ def test_result_ownership
95
+ 10.times do
96
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
97
+ sdoc = LibXML::XML::Document.file(filename)
98
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(sdoc)
99
+
100
+ rdoc = stylesheet.apply(doc)
101
+ rdoc = nil
102
+ GC.start
103
+ end
104
+ end
105
+
106
+ #RAF#
107
+ def test_stylesheet_string
108
+ filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
109
+ style = File.open(filename).readline(nil)
110
+ stylesheet = LibXSLT::XSLT::Stylesheet.string(style)
111
+ assert_instance_of(LibXSLT::XSLT::Stylesheet, stylesheet)
112
+ end
113
+
114
+ def test_stylesheet_file
115
+ filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
116
+ stylesheet = LibXSLT::XSLT::Stylesheet.file(filename)
117
+ assert_instance_of(LibXSLT::XSLT::Stylesheet, stylesheet)
118
+ end
119
+
120
+ def test_stylesheet_io
121
+ filename = File.join(File.dirname(__FILE__), 'files/params.xsl')
122
+ stylesheet = LibXSLT::XSLT::Stylesheet.io(File.open(filename))
123
+ assert_instance_of(LibXSLT::XSLT::Stylesheet, stylesheet)
124
+ end
125
+
126
+ def test_output
127
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
128
+ sdoc = LibXML::XML::Document.file(filename)
129
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(sdoc)
130
+
131
+ rdoc = stylesheet.apply(doc)
132
+
133
+ xml = stylesheet.output(rdoc)
134
+
135
+ # output method is html -> no xml decl, empty tags not closed...
136
+ assert xml =~ /^<html>/
137
+ assert xml =~ /<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8">\n<title>/
138
+ end
139
+
140
+ def test_transform
141
+ filename = File.join(File.dirname(__FILE__), 'files/fuzface.xsl')
142
+ sdoc = LibXML::XML::Document.file(filename)
143
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(sdoc)
144
+
145
+ xml = stylesheet.transform(doc)
146
+
147
+ assert xml =~ /<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8">\n<title>/
148
+ end
149
+
150
+ def test_entities
151
+ style = <<EOF
152
+ <!DOCTYPE xsl:stylesheet [
153
+ <!ENTITY foo 'bar'>
154
+ ]>
155
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
156
+ <xsl:template match="a">
157
+ <out><xsl:text>&foo;</xsl:text>
158
+ <xsl:apply-templates/></out>
159
+ </xsl:template>
160
+ </xsl:stylesheet>
161
+ EOF
162
+
163
+ styledoc = LibXML::XML::Parser.string(style, :options => LibXSLT::XSLT::Stylesheet::PARSE_OPTIONS).parse
164
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(styledoc)
165
+
166
+ xml = "<!DOCTYPE a [<!ENTITY bla 'fasel'>]><a>&bla;</a>"
167
+ doc = LibXML::XML::Parser.string(xml, :options => LibXSLT::XSLT::Stylesheet::PARSE_OPTIONS).parse
168
+
169
+ out = stylesheet.apply( doc )
170
+ dump = stylesheet.output( out )
171
+ assert_match( /<out>barfasel<\/out>/, dump)
172
+
173
+ # no entity replacement in document
174
+ doc = LibXML::XML::Parser.string(xml, :options => 0).parse
175
+ out = stylesheet.apply( doc )
176
+ dump = stylesheet.output( out )
177
+
178
+ assert_match(/<out>bar<\/out>/, dump) # entity content is missing
179
+
180
+ # note: having entities in your stylesheet that are not replaced during
181
+ # parse, will crash libxslt (segfault)
182
+ # seems to be a libxslt problem; you should not do that anyway
183
+ # styledoc = LibXML::XML::Parser.string(style, : options => 0).parse
184
+ # stylesheet = LibXSLT::XSLT::Stylesheet.new(styledoc)
185
+ end
186
+
187
+ def test_cdatasection
188
+ doc = LibXML::XML::Parser.string("<a/>").parse
189
+
190
+ style = <<EOF
191
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
192
+ <xsl:template match="a">
193
+ <out><xsl:text disable-output-escaping="yes"><![CDATA[<>]]></xsl:text></out>
194
+ </xsl:template>
195
+ </xsl:stylesheet>
196
+ EOF
197
+
198
+ styledoc = LibXML::XML::Parser.string(style, :options => LibXSLT::XSLT::Stylesheet::PARSE_OPTIONS).parse
199
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(styledoc)
200
+
201
+ out = stylesheet.apply( doc )
202
+ dump = stylesheet.output( out )
203
+ assert_match( /<out><><\/out>/, dump)
204
+
205
+ # without propper parse options (result is wrong from an xml/xslt point of view)
206
+ styledoc = LibXML::XML::Parser.string(style).parse
207
+ stylesheet = LibXSLT::XSLT::Stylesheet.new(styledoc)
208
+
209
+ out = stylesheet.apply( doc )
210
+ dump = stylesheet.output( out )
211
+ assert_match( /<out>&lt;&gt;<\/out>/, dump)
212
+ end
213
+ end