hatemile 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +9 -0
- data/LICENSE +202 -0
- data/Rakefile +64 -0
- data/hatemile.gemspec +37 -0
- data/lib/hatemile/accessible_association.rb +62 -0
- data/lib/hatemile/accessible_css.rb +43 -0
- data/lib/hatemile/accessible_display.rb +178 -0
- data/lib/hatemile/accessible_event.rb +95 -0
- data/lib/hatemile/accessible_form.rb +101 -0
- data/lib/hatemile/accessible_navigation.rb +82 -0
- data/lib/hatemile/helper.rb +58 -0
- data/lib/hatemile/implementation/accessible_association_implementation.rb +346 -0
- data/lib/hatemile/implementation/accessible_css_implementation.rb +772 -0
- data/lib/hatemile/implementation/accessible_display_implementation.rb +1362 -0
- data/lib/hatemile/implementation/accessible_event_implementation.rb +278 -0
- data/lib/hatemile/implementation/accessible_form_implementation.rb +386 -0
- data/lib/hatemile/implementation/accessible_navigation_implementation.rb +561 -0
- data/lib/hatemile/util/common_functions.rb +106 -0
- data/lib/hatemile/util/configure.rb +92 -0
- data/lib/hatemile/util/css/rcp/rcp_declaration.rb +77 -0
- data/lib/hatemile/util/css/rcp/rcp_parser.rb +115 -0
- data/lib/hatemile/util/css/rcp/rcp_rule.rb +86 -0
- data/lib/hatemile/util/css/style_sheet_declaration.rb +59 -0
- data/lib/hatemile/util/css/style_sheet_parser.rb +43 -0
- data/lib/hatemile/util/css/style_sheet_rule.rb +73 -0
- data/lib/hatemile/util/html/html_dom_element.rb +234 -0
- data/lib/hatemile/util/html/html_dom_node.rb +131 -0
- data/lib/hatemile/util/html/html_dom_parser.rb +150 -0
- data/lib/hatemile/util/html/html_dom_text_node.rb +43 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_element.rb +302 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_node.rb +112 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_parser.rb +208 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_text_node.rb +83 -0
- data/lib/hatemile/util/id_generator.rb +53 -0
- data/lib/js/common.js +98 -0
- data/lib/js/eventlistener.js +36 -0
- data/lib/js/include.js +292 -0
- data/lib/js/scriptlist_validation_fields.js +13 -0
- data/lib/js/validation.js +205 -0
- data/lib/locale/en-US.yml +388 -0
- data/lib/locale/pt-BR.yml +389 -0
- data/lib/skippers.xml +6 -0
- data/lib/symbols.xml +40 -0
- data/test/locale/en-US.yml +5 -0
- data/test/locale/pt-BR.yml +4 -0
- data/test/test_accessible_association_implementation.rb +258 -0
- data/test/test_accessible_css_implementation.rb +518 -0
- data/test/test_accessible_display_implementation.rb +873 -0
- data/test/test_accessible_form_implementation.rb +283 -0
- data/test/test_accessible_navigation_implementation.rb +228 -0
- data/test/test_common_functions.rb +128 -0
- data/test/test_configure.rb +73 -0
- data/test/test_nokogiri_html_dom_element.rb +586 -0
- data/test/test_nokogiri_html_dom_parser.rb +363 -0
- data/test/test_nokogiri_html_dom_text_node.rb +225 -0
- data/test/test_rcp_declaration.rb +103 -0
- data/test/test_rcp_parser.rb +86 -0
- data/test/test_rcp_rule.rb +89 -0
- metadata +199 -0
@@ -0,0 +1,363 @@
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
# you may not use this file except in compliance with the License.
|
3
|
+
# You may obtain a copy of the License at
|
4
|
+
#
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
#
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
# See the License for the specific language governing permissions and
|
11
|
+
# limitations under the License.
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
require File.join(
|
18
|
+
File.dirname(File.dirname(__FILE__)),
|
19
|
+
'lib',
|
20
|
+
'hatemile',
|
21
|
+
'util',
|
22
|
+
'html',
|
23
|
+
'nokogiri',
|
24
|
+
'nokogiri_html_dom_element'
|
25
|
+
)
|
26
|
+
require File.join(
|
27
|
+
File.dirname(File.dirname(__FILE__)),
|
28
|
+
'lib',
|
29
|
+
'hatemile',
|
30
|
+
'util',
|
31
|
+
'html',
|
32
|
+
'nokogiri',
|
33
|
+
'nokogiri_html_dom_parser'
|
34
|
+
)
|
35
|
+
|
36
|
+
##
|
37
|
+
# Test methods of Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMParser
|
38
|
+
# class.
|
39
|
+
class TestNokogiriHTMLDOMParser < Test::Unit::TestCase
|
40
|
+
##
|
41
|
+
# The meta element added by Nokogiri.
|
42
|
+
META_HTTP =
|
43
|
+
'<meta http-equiv="Content-Type" '\
|
44
|
+
'content="text/html; charset=UTF-8" />'.freeze
|
45
|
+
|
46
|
+
##
|
47
|
+
# Initialize common attributes used by test methods.
|
48
|
+
def setup
|
49
|
+
@html_code = "<!DOCTYPE html>
|
50
|
+
<html>
|
51
|
+
<head>
|
52
|
+
#{META_HTTP}
|
53
|
+
<title>HaTeMiLe Tests</title>
|
54
|
+
<meta charset=\"UTF-8\" />
|
55
|
+
</head>
|
56
|
+
<body>
|
57
|
+
<section>
|
58
|
+
<header></header>
|
59
|
+
<article>
|
60
|
+
\n
|
61
|
+
</article>
|
62
|
+
<footer><!-- Footer --></footer>
|
63
|
+
</section>
|
64
|
+
<span attribute=\"value\" data-attribute=\"custom_value\">
|
65
|
+
<!-- Comment -->
|
66
|
+
Text node
|
67
|
+
<strong>Strong text</strong>
|
68
|
+
<hr />
|
69
|
+
</span>
|
70
|
+
<div></div>
|
71
|
+
<p>
|
72
|
+
<del>Deleted text</del>
|
73
|
+
</p>
|
74
|
+
<table>
|
75
|
+
<thead><tr>
|
76
|
+
<th>Table header</th>
|
77
|
+
</tr></thead>
|
78
|
+
<tbody class=\"table-body\">
|
79
|
+
<tr>
|
80
|
+
<td>Table <ins>cell</ins></td>
|
81
|
+
</tr>
|
82
|
+
</tbody>
|
83
|
+
<tfoot><!-- Table footer --></tfoot>
|
84
|
+
</table>
|
85
|
+
<ul>
|
86
|
+
<li id=\"li-1\">1</li>
|
87
|
+
<li id=\"li-3\">3</li>
|
88
|
+
</ul>
|
89
|
+
<ol>
|
90
|
+
<li>1</li>
|
91
|
+
<li>2</li>
|
92
|
+
<li>3</li>
|
93
|
+
<li>4</li>
|
94
|
+
<li>5</li>
|
95
|
+
</ol>
|
96
|
+
<form>
|
97
|
+
<label>
|
98
|
+
Text:
|
99
|
+
<input type=\"text\" name=\"number\" />
|
100
|
+
</label>
|
101
|
+
</form>
|
102
|
+
<div>
|
103
|
+
<h1><span>Heading 1</span></h1>
|
104
|
+
<h2><span>Heading 1.2.1</span></h2>
|
105
|
+
<div>
|
106
|
+
<span></span>
|
107
|
+
<div><h2><span>Heading 1.2.2</span></h2></div>
|
108
|
+
<span></span>
|
109
|
+
</div>
|
110
|
+
<h3><span>Heading 1.2.2.3.1</span></h3>
|
111
|
+
<h4><span>Heading 1.2.2.3.1.4.1</span></h4>
|
112
|
+
<h2><span>Heading 1.2.3</span></h2>
|
113
|
+
<h3><span>Heading 1.2.3.3.1</span></h3>
|
114
|
+
</div>
|
115
|
+
</body>
|
116
|
+
</html>"
|
117
|
+
@html_parser = Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMParser.new(
|
118
|
+
@html_code
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Test find method.
|
124
|
+
def test_find
|
125
|
+
body = @html_parser.find('body').first_result
|
126
|
+
section = @html_parser.find('section').first_result
|
127
|
+
same_section = @html_parser.find(section).first_result
|
128
|
+
input = @html_parser.find('[type="text"]').first_result
|
129
|
+
li1 = @html_parser.find('#li-1').first_result
|
130
|
+
li3 = @html_parser.find('ul li').last_result
|
131
|
+
ins = @html_parser.find('table tbody.table-body tr td ins').first_result
|
132
|
+
inputs = @html_parser.find('input[type="text"]').list_results
|
133
|
+
lis = @html_parser.find('ol li').list_results
|
134
|
+
img_nil = @html_parser.find('img').first_result
|
135
|
+
imgs_empty = @html_parser.find('img').list_results
|
136
|
+
|
137
|
+
heading_selectors = []
|
138
|
+
@html_parser.find('h1, h2, h3, h4').list_results.each do |heading|
|
139
|
+
heading_selectors.push(heading.get_text_content)
|
140
|
+
end
|
141
|
+
|
142
|
+
assert_equal(section, body.get_first_element_child)
|
143
|
+
assert_equal(section, same_section)
|
144
|
+
assert_equal('INPUT', input.get_tag_name)
|
145
|
+
assert_equal('1', li1.get_text_content)
|
146
|
+
assert_equal('3', li3.get_text_content)
|
147
|
+
assert_equal('cell', ins.get_text_content)
|
148
|
+
assert_equal([input], inputs)
|
149
|
+
lis.each_with_index do |li, index|
|
150
|
+
assert_equal('LI', li.get_tag_name)
|
151
|
+
assert_equal((index + 1).to_s, li.get_text_content)
|
152
|
+
end
|
153
|
+
assert_nil(img_nil)
|
154
|
+
assert_equal(0, imgs_empty.length)
|
155
|
+
assert_equal(
|
156
|
+
[
|
157
|
+
'Heading 1',
|
158
|
+
'Heading 1.2.1',
|
159
|
+
'Heading 1.2.2',
|
160
|
+
'Heading 1.2.2.3.1',
|
161
|
+
'Heading 1.2.2.3.1.4.1',
|
162
|
+
'Heading 1.2.3',
|
163
|
+
'Heading 1.2.3.3.1'
|
164
|
+
],
|
165
|
+
heading_selectors
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
# Test find_children method.
|
171
|
+
def test_find_children
|
172
|
+
section = @html_parser.find('body').find_children('section').last_result
|
173
|
+
lis = @html_parser.find('ol').find_children('li').list_results
|
174
|
+
tbody_nil = @html_parser.find('body').find_children(
|
175
|
+
'.table-body'
|
176
|
+
).first_result
|
177
|
+
tbody_not_nil = @html_parser.find('table').find_children(
|
178
|
+
'.table-body'
|
179
|
+
).first_result
|
180
|
+
input = @html_parser.find('form label').find_children(
|
181
|
+
'input[type="text"]'
|
182
|
+
).first_result
|
183
|
+
li1 = @html_parser.find('ul').find_children('#li-1').first_result
|
184
|
+
|
185
|
+
expected_result_headings = [
|
186
|
+
'Heading 1',
|
187
|
+
'Heading 1.2.1',
|
188
|
+
'Heading 1.2.2',
|
189
|
+
'Heading 1.2.2.3.1',
|
190
|
+
'Heading 1.2.2.3.1.4.1',
|
191
|
+
'Heading 1.2.3',
|
192
|
+
'Heading 1.2.3.3.1'
|
193
|
+
]
|
194
|
+
heading_selectors = []
|
195
|
+
heading_find_only_elements = []
|
196
|
+
heading_find_both_elements = []
|
197
|
+
heading_elements = @html_parser.find('h1, h2, h3, h4').list_results
|
198
|
+
span_elements = @html_parser.find('span').list_results
|
199
|
+
@html_parser.find('h1, h2, h3, h4').find_children(
|
200
|
+
'span'
|
201
|
+
).list_results.each do |heading|
|
202
|
+
heading_selectors.push(heading.get_text_content)
|
203
|
+
end
|
204
|
+
@html_parser.find(
|
205
|
+
heading_elements
|
206
|
+
).find_children('span').list_results.each do |heading|
|
207
|
+
heading_find_only_elements.push(heading.get_text_content)
|
208
|
+
end
|
209
|
+
@html_parser.find(
|
210
|
+
heading_elements
|
211
|
+
).find_children(span_elements).list_results.each do |heading|
|
212
|
+
heading_find_both_elements.push(heading.get_text_content)
|
213
|
+
end
|
214
|
+
|
215
|
+
assert_equal('SECTION', section.get_tag_name)
|
216
|
+
lis.each_with_index do |li, index|
|
217
|
+
assert_equal('LI', li.get_tag_name)
|
218
|
+
assert_equal((index + 1).to_s, li.get_text_content)
|
219
|
+
end
|
220
|
+
assert_nil(tbody_nil)
|
221
|
+
assert_not_nil(tbody_not_nil)
|
222
|
+
assert_equal('INPUT', input.get_tag_name)
|
223
|
+
assert_equal('1', li1.get_text_content)
|
224
|
+
assert_equal(expected_result_headings, heading_selectors)
|
225
|
+
assert_equal(expected_result_headings, heading_find_only_elements)
|
226
|
+
assert_equal(expected_result_headings, heading_find_both_elements)
|
227
|
+
end
|
228
|
+
|
229
|
+
##
|
230
|
+
# Test find_descendants method.
|
231
|
+
def test_find_descendants
|
232
|
+
section = @html_parser.find('body').find_descendants('section').last_result
|
233
|
+
lis = @html_parser.find('ol').find_descendants('li').list_results
|
234
|
+
tbody1 = @html_parser.find('body').find_descendants(
|
235
|
+
'.table-body'
|
236
|
+
).first_result
|
237
|
+
tbody2 = @html_parser.find('table').find_descendants(
|
238
|
+
'.table-body'
|
239
|
+
).first_result
|
240
|
+
input = @html_parser.find('form').find_descendants(
|
241
|
+
'input[type="text"]'
|
242
|
+
).first_result
|
243
|
+
li1 = @html_parser.find('body').find_descendants('#li-1').first_result
|
244
|
+
|
245
|
+
expected_result_headings = [
|
246
|
+
'Heading 1',
|
247
|
+
'Heading 1.2.1',
|
248
|
+
'Heading 1.2.2',
|
249
|
+
'Heading 1.2.2.3.1',
|
250
|
+
'Heading 1.2.2.3.1.4.1',
|
251
|
+
'Heading 1.2.3',
|
252
|
+
'Heading 1.2.3.3.1'
|
253
|
+
]
|
254
|
+
heading_selectors = []
|
255
|
+
heading_find_only_elements = []
|
256
|
+
heading_find_both_elements = []
|
257
|
+
heading_elements = @html_parser.find('h1, h2, h3, h4').list_results
|
258
|
+
span_elements = @html_parser.find('span').list_results
|
259
|
+
@html_parser.find('h1, h2, h3, h4').find_descendants(
|
260
|
+
'span'
|
261
|
+
).list_results.each do |heading|
|
262
|
+
heading_selectors.push(heading.get_text_content)
|
263
|
+
end
|
264
|
+
@html_parser.find(
|
265
|
+
heading_elements
|
266
|
+
).find_descendants('span').list_results.each do |heading|
|
267
|
+
heading_find_only_elements.push(heading.get_text_content)
|
268
|
+
end
|
269
|
+
@html_parser.find(
|
270
|
+
heading_elements
|
271
|
+
).find_descendants(span_elements).list_results.each do |heading|
|
272
|
+
heading_find_both_elements.push(heading.get_text_content)
|
273
|
+
end
|
274
|
+
|
275
|
+
assert_equal('SECTION', section.get_tag_name)
|
276
|
+
lis.each_with_index do |li, index|
|
277
|
+
assert_equal('LI', li.get_tag_name)
|
278
|
+
assert_equal((index + 1).to_s, li.get_text_content)
|
279
|
+
end
|
280
|
+
assert_equal('TBODY', tbody1.get_tag_name)
|
281
|
+
assert_equal(tbody1, tbody2)
|
282
|
+
assert_equal('INPUT', input.get_tag_name)
|
283
|
+
assert_equal('1', li1.get_text_content)
|
284
|
+
assert_equal(expected_result_headings, heading_selectors)
|
285
|
+
assert_equal(expected_result_headings, heading_find_only_elements)
|
286
|
+
assert_equal(expected_result_headings, heading_find_both_elements)
|
287
|
+
end
|
288
|
+
|
289
|
+
##
|
290
|
+
# Test find_ancestors method.
|
291
|
+
def test_find_ancestors
|
292
|
+
body = @html_parser.find('section').find_ancestors('body').last_result
|
293
|
+
tbody1 = @html_parser.find('ins').find_ancestors('.table-body').first_result
|
294
|
+
tbody2 = @html_parser.find('td').find_ancestors('.table-body').first_result
|
295
|
+
input = @html_parser.find('strong').find_ancestors(
|
296
|
+
'[attribute="value"]'
|
297
|
+
).first_result
|
298
|
+
|
299
|
+
expected_result_headings = [
|
300
|
+
'Heading 1',
|
301
|
+
'Heading 1.2.1',
|
302
|
+
'Heading 1.2.2',
|
303
|
+
'Heading 1.2.2.3.1',
|
304
|
+
'Heading 1.2.2.3.1.4.1',
|
305
|
+
'Heading 1.2.3',
|
306
|
+
'Heading 1.2.3.3.1'
|
307
|
+
]
|
308
|
+
heading_selectors = []
|
309
|
+
heading_find_only_elements = []
|
310
|
+
heading_find_both_elements = []
|
311
|
+
heading_elements = @html_parser.find('h1, h2, h3, h4').list_results
|
312
|
+
span_elements = @html_parser.find('span').list_results
|
313
|
+
@html_parser.find('span').find_ancestors(
|
314
|
+
'h1, h2, h3, h4'
|
315
|
+
).list_results.each do |heading|
|
316
|
+
heading_selectors.push(heading.get_text_content)
|
317
|
+
end
|
318
|
+
@html_parser.find(span_elements).find_ancestors(
|
319
|
+
'h1, h2, h3, h4'
|
320
|
+
).list_results.each do |heading|
|
321
|
+
heading_find_only_elements.push(heading.get_text_content)
|
322
|
+
end
|
323
|
+
@html_parser.find(span_elements).find_ancestors(
|
324
|
+
heading_elements
|
325
|
+
).list_results.each do |heading|
|
326
|
+
heading_find_both_elements.push(heading.get_text_content)
|
327
|
+
end
|
328
|
+
|
329
|
+
assert_equal('BODY', body.get_tag_name)
|
330
|
+
assert_equal('TBODY', tbody1.get_tag_name)
|
331
|
+
assert_equal(tbody1, tbody2)
|
332
|
+
assert_equal('SPAN', input.get_tag_name)
|
333
|
+
assert_equal(expected_result_headings, heading_selectors)
|
334
|
+
assert_equal(expected_result_headings, heading_find_only_elements)
|
335
|
+
assert_equal(expected_result_headings, heading_find_both_elements)
|
336
|
+
end
|
337
|
+
|
338
|
+
##
|
339
|
+
# Test create_element method.
|
340
|
+
def test_create_element
|
341
|
+
img = @html_parser.create_element('img')
|
342
|
+
img.set_attribute('src', 'http://www.example.com/image.png')
|
343
|
+
img.set_attribute('alt', 'Example')
|
344
|
+
@html_parser.find('body').first_result.append_element(img)
|
345
|
+
same_img = @html_parser.find('img').first_result
|
346
|
+
|
347
|
+
assert_equal('IMG', img.get_tag_name)
|
348
|
+
assert_instance_of(
|
349
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMElement,
|
350
|
+
img
|
351
|
+
)
|
352
|
+
assert_equal(img, same_img)
|
353
|
+
end
|
354
|
+
|
355
|
+
##
|
356
|
+
# Test get_html method.
|
357
|
+
def test_get_html
|
358
|
+
assert_equal(
|
359
|
+
@html_code.freeze.gsub(/\s+/, ''),
|
360
|
+
@html_parser.get_html.gsub(/\s+/, '')
|
361
|
+
)
|
362
|
+
end
|
363
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
# you may not use this file except in compliance with the License.
|
3
|
+
# You may obtain a copy of the License at
|
4
|
+
#
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
#
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
# See the License for the specific language governing permissions and
|
11
|
+
# limitations under the License.
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
require File.join(
|
18
|
+
File.dirname(File.dirname(__FILE__)),
|
19
|
+
'lib',
|
20
|
+
'hatemile',
|
21
|
+
'util',
|
22
|
+
'html',
|
23
|
+
'nokogiri',
|
24
|
+
'nokogiri_html_dom_parser'
|
25
|
+
)
|
26
|
+
|
27
|
+
##
|
28
|
+
# Test methods of Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode
|
29
|
+
# class.
|
30
|
+
class TestNokogiriHTMLDOMTextNode < Test::Unit::TestCase
|
31
|
+
##
|
32
|
+
# Initialize common attributes used by test methods.
|
33
|
+
def setup
|
34
|
+
@html_parser = Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMParser.new(
|
35
|
+
"<!DOCTYPE html>
|
36
|
+
<html>
|
37
|
+
<head>
|
38
|
+
<title>HaTeMiLe Tests</title>
|
39
|
+
<meta charset=\"UTF-8\" />
|
40
|
+
</head>
|
41
|
+
<body>
|
42
|
+
<section>
|
43
|
+
<header></header>
|
44
|
+
<article>
|
45
|
+
\n
|
46
|
+
</article>
|
47
|
+
<footer><!-- Footer --></footer>
|
48
|
+
</section>
|
49
|
+
<span attribute=\"value\" data-attribute=\"custom_value\">
|
50
|
+
<!-- Comment -->
|
51
|
+
Text node
|
52
|
+
<strong>Strong text</strong>
|
53
|
+
<hr />
|
54
|
+
</span>
|
55
|
+
<div></div>
|
56
|
+
<p>
|
57
|
+
<del>Deleted text</del>
|
58
|
+
</p>
|
59
|
+
<table>
|
60
|
+
<thead><tr>
|
61
|
+
<th>Table header</th>
|
62
|
+
</tr></thead>
|
63
|
+
<tbody class=\"table-body\">
|
64
|
+
<tr>
|
65
|
+
<td>Table <ins>cell</ins></td>
|
66
|
+
</tr>
|
67
|
+
</tbody>
|
68
|
+
<tfoot><!-- Table footer --></tfoot>
|
69
|
+
</table>
|
70
|
+
<ul>
|
71
|
+
<li id=\"li-1\">1</li>
|
72
|
+
<li id=\"li-3\">3</li>
|
73
|
+
</ul>
|
74
|
+
<ol>
|
75
|
+
<li>1</li>
|
76
|
+
<li>2</li>
|
77
|
+
<li>3</li>
|
78
|
+
<li>4</li>
|
79
|
+
<li>5</li>
|
80
|
+
</ol>
|
81
|
+
<form>
|
82
|
+
<label>
|
83
|
+
Text:
|
84
|
+
<input type=\"text\" name=\"number\" />
|
85
|
+
</label>
|
86
|
+
</form>
|
87
|
+
<h1></h1>
|
88
|
+
<h2></h2>
|
89
|
+
</body>
|
90
|
+
</html>"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Test get_text_content method.
|
96
|
+
def test_get_text_content
|
97
|
+
@html_parser.find('ol li').list_results.each_with_index do |li, index|
|
98
|
+
child = li.get_first_node_child
|
99
|
+
assert_instance_of(
|
100
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
101
|
+
child
|
102
|
+
)
|
103
|
+
assert_equal((index + 1).to_s, child.get_text_content)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Test set_text_content method.
|
109
|
+
def test_set_text_content
|
110
|
+
child = @html_parser.find('ins').first_result.get_first_node_child
|
111
|
+
child.set_text_content('Changed')
|
112
|
+
|
113
|
+
assert_instance_of(
|
114
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
115
|
+
child
|
116
|
+
)
|
117
|
+
assert_equal('Changed', child.get_text_content)
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Test append_text method.
|
122
|
+
def test_append_text
|
123
|
+
child = @html_parser.find('ins').first_result.get_first_node_child
|
124
|
+
child.append_text(' and value')
|
125
|
+
|
126
|
+
assert_instance_of(
|
127
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
128
|
+
child
|
129
|
+
)
|
130
|
+
assert_equal('cell and value', child.get_text_content)
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Test prepend_text method.
|
135
|
+
def test_prepend_text
|
136
|
+
child = @html_parser.find('ins').first_result.get_first_node_child
|
137
|
+
child.prepend_text('table and ')
|
138
|
+
|
139
|
+
assert_instance_of(
|
140
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
141
|
+
child
|
142
|
+
)
|
143
|
+
assert_equal('table and cell', child.get_text_content)
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Test insert_before method.
|
148
|
+
def test_insert_before
|
149
|
+
link = @html_parser.create_element('a')
|
150
|
+
link.append_text('table and ')
|
151
|
+
ins = @html_parser.find('ins').first_result
|
152
|
+
ins.get_first_node_child.insert_before(link)
|
153
|
+
|
154
|
+
assert_equal(link, ins.get_first_node_child)
|
155
|
+
assert_instance_of(
|
156
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
157
|
+
ins.get_last_node_child
|
158
|
+
)
|
159
|
+
assert_equal('table and cell', ins.get_text_content)
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Test insert_after method.
|
164
|
+
def test_insert_after
|
165
|
+
link = @html_parser.create_element('a')
|
166
|
+
link.append_text(' and value')
|
167
|
+
ins = @html_parser.find('ins').first_result
|
168
|
+
child = ins.get_first_node_child
|
169
|
+
child.insert_after(link)
|
170
|
+
|
171
|
+
assert_instance_of(
|
172
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
173
|
+
child
|
174
|
+
)
|
175
|
+
assert_equal(link, ins.get_last_node_child)
|
176
|
+
assert_equal('cell and value', ins.get_text_content)
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Test remove_node method.
|
181
|
+
def test_remove_node
|
182
|
+
ins = @html_parser.find('ins').first_result
|
183
|
+
ins.get_first_node_child.remove_node
|
184
|
+
|
185
|
+
assert(!ins.has_children?)
|
186
|
+
end
|
187
|
+
|
188
|
+
##
|
189
|
+
# Test replace_node method.
|
190
|
+
def test_replace_node
|
191
|
+
ins = @html_parser.find('ins').first_result
|
192
|
+
strong = @html_parser.find('strong').first_result
|
193
|
+
ins.get_first_node_child.replace_node(strong.get_first_node_child)
|
194
|
+
|
195
|
+
assert_equal('Strong text', ins.get_text_content)
|
196
|
+
assert_equal('', strong.get_text_content)
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Test get_parent_element method.
|
201
|
+
def test_get_parent_element
|
202
|
+
ins = @html_parser.find('ins').first_result
|
203
|
+
child = ins.get_first_node_child
|
204
|
+
|
205
|
+
assert_instance_of(
|
206
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
207
|
+
child
|
208
|
+
)
|
209
|
+
assert_equal(ins, child.get_parent_element)
|
210
|
+
end
|
211
|
+
|
212
|
+
##
|
213
|
+
# Test get_data and set_data methods.
|
214
|
+
def test_get_set_data
|
215
|
+
ins = @html_parser.find('ins').first_result
|
216
|
+
strong = @html_parser.find('strong').first_result
|
217
|
+
text_node = ins.get_first_node_child
|
218
|
+
text_node.set_data(strong.get_first_node_child.get_data)
|
219
|
+
text_node.append_text('!!!')
|
220
|
+
|
221
|
+
assert_equal('Strong text!!!', text_node.get_text_content)
|
222
|
+
assert_equal('Strong text!!!', strong.get_text_content)
|
223
|
+
assert_equal('cell', ins.get_text_content)
|
224
|
+
end
|
225
|
+
end
|