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,128 @@
|
|
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
|
+
require 'test/unit/assertions'
|
17
|
+
|
18
|
+
require File.join(
|
19
|
+
File.dirname(File.dirname(__FILE__)),
|
20
|
+
'lib',
|
21
|
+
'hatemile',
|
22
|
+
'util',
|
23
|
+
'common_functions'
|
24
|
+
)
|
25
|
+
require File.join(
|
26
|
+
File.dirname(File.dirname(__FILE__)),
|
27
|
+
'lib',
|
28
|
+
'hatemile',
|
29
|
+
'util',
|
30
|
+
'html',
|
31
|
+
'nokogiri',
|
32
|
+
'nokogiri_html_dom_parser'
|
33
|
+
)
|
34
|
+
|
35
|
+
##
|
36
|
+
# Test methods of Hatemile::Util::CommonFunctions class.
|
37
|
+
class TestCommonFunctions < Test::Unit::TestCase
|
38
|
+
##
|
39
|
+
# Test increase_in_list method.
|
40
|
+
def test_increase_in_list
|
41
|
+
assert_equal(
|
42
|
+
'item',
|
43
|
+
Hatemile::Util::CommonFunctions.increase_in_list(nil, 'item')
|
44
|
+
)
|
45
|
+
assert_equal(
|
46
|
+
'item',
|
47
|
+
Hatemile::Util::CommonFunctions.increase_in_list('item', nil)
|
48
|
+
)
|
49
|
+
assert_equal(
|
50
|
+
'item',
|
51
|
+
Hatemile::Util::CommonFunctions.increase_in_list('', 'item')
|
52
|
+
)
|
53
|
+
assert_equal(
|
54
|
+
'item',
|
55
|
+
Hatemile::Util::CommonFunctions.increase_in_list('item', '')
|
56
|
+
)
|
57
|
+
assert_equal(
|
58
|
+
'item1 item2 item',
|
59
|
+
Hatemile::Util::CommonFunctions.increase_in_list('item1 item2', 'item')
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Test in_list? method.
|
65
|
+
def test_in_list
|
66
|
+
assert(!Hatemile::Util::CommonFunctions.in_list?(nil, 'item'))
|
67
|
+
assert(!Hatemile::Util::CommonFunctions.in_list?('item', nil))
|
68
|
+
assert(!Hatemile::Util::CommonFunctions.in_list?('', 'item'))
|
69
|
+
assert(!Hatemile::Util::CommonFunctions.in_list?('item', ''))
|
70
|
+
assert(!Hatemile::Util::CommonFunctions.in_list?('item1 item2', 'item'))
|
71
|
+
assert(Hatemile::Util::CommonFunctions.in_list?('item1 item2', 'item1'))
|
72
|
+
assert(Hatemile::Util::CommonFunctions.in_list?('item1 item2', 'item2'))
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Test is_valid_element? method.
|
77
|
+
def test_is_valid_element
|
78
|
+
html_parser = Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMParser.new('
|
79
|
+
<!DOCTYPE html>
|
80
|
+
<html>
|
81
|
+
<head>
|
82
|
+
<title>HaTeMiLe Tests</title>
|
83
|
+
<meta charset=\"UTF-8\" />
|
84
|
+
</head>
|
85
|
+
<body>
|
86
|
+
<table>
|
87
|
+
<thead>
|
88
|
+
<tr>
|
89
|
+
<th>Column</th>
|
90
|
+
</tr>
|
91
|
+
</thead>
|
92
|
+
<tbody data-ignoreaccessibilityfix="true">
|
93
|
+
<tr>
|
94
|
+
<td>Cell</td>
|
95
|
+
</tr>
|
96
|
+
</tbody>
|
97
|
+
</table>
|
98
|
+
</body>
|
99
|
+
</html>
|
100
|
+
')
|
101
|
+
|
102
|
+
assert(
|
103
|
+
Hatemile::Util::CommonFunctions.is_valid_element?(
|
104
|
+
html_parser.find('table').first_result
|
105
|
+
)
|
106
|
+
)
|
107
|
+
assert(
|
108
|
+
Hatemile::Util::CommonFunctions.is_valid_element?(
|
109
|
+
html_parser.find('th').first_result
|
110
|
+
)
|
111
|
+
)
|
112
|
+
assert(
|
113
|
+
!Hatemile::Util::CommonFunctions.is_valid_element?(
|
114
|
+
html_parser.find('tbody').first_result
|
115
|
+
)
|
116
|
+
)
|
117
|
+
assert(
|
118
|
+
!Hatemile::Util::CommonFunctions.is_valid_element?(
|
119
|
+
html_parser.find('tr').last_result
|
120
|
+
)
|
121
|
+
)
|
122
|
+
assert(
|
123
|
+
!Hatemile::Util::CommonFunctions.is_valid_element?(
|
124
|
+
html_parser.find('td').first_result
|
125
|
+
)
|
126
|
+
)
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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
|
+
require 'test/unit/assertions'
|
17
|
+
|
18
|
+
require File.join(
|
19
|
+
File.dirname(File.dirname(__FILE__)),
|
20
|
+
'lib',
|
21
|
+
'hatemile',
|
22
|
+
'util',
|
23
|
+
'configure'
|
24
|
+
)
|
25
|
+
|
26
|
+
##
|
27
|
+
# Test methods of Hatemile::Util::Configure class.
|
28
|
+
class TestConfigure < Test::Unit::TestCase
|
29
|
+
##
|
30
|
+
# Initialize common attributes used by test methods.
|
31
|
+
def setup
|
32
|
+
@configure = Hatemile::Util::Configure.new(
|
33
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'locale', '*.yml')),
|
34
|
+
%i[pt-BR en-US]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Test get_parameters method.
|
40
|
+
def test_get_parameters
|
41
|
+
parameters = @configure.get_parameters
|
42
|
+
|
43
|
+
assert_equal(3, parameters.length)
|
44
|
+
assert_equal('Atalhos:', parameters['text-shortcuts'])
|
45
|
+
assert_equal('ALT', parameters['text-standart-shortcut-prefix'])
|
46
|
+
assert_equal('Summary:', parameters['text-heading'])
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Test has_parameter? method.
|
51
|
+
def test_has_parameter
|
52
|
+
assert(@configure.has_parameter?('text-shortcuts'))
|
53
|
+
assert(@configure.has_parameter?('text-standart-shortcut-prefix'))
|
54
|
+
assert(@configure.has_parameter?('text-heading'))
|
55
|
+
assert(!@configure.has_parameter?('unknown'))
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Test get_parameter method.
|
60
|
+
def test_get_parameter
|
61
|
+
assert_equal('Atalhos:', @configure.get_parameter('text-shortcuts'))
|
62
|
+
assert_equal(
|
63
|
+
'ALT',
|
64
|
+
@configure.get_parameter(
|
65
|
+
'text-standart-shortcut-prefix'
|
66
|
+
)
|
67
|
+
)
|
68
|
+
assert_equal('Summary:', @configure.get_parameter('text-heading'))
|
69
|
+
assert_raise do
|
70
|
+
assert(configure.get_parameter('unknown'))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,586 @@
|
|
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
|
+
require File.join(
|
36
|
+
File.dirname(File.dirname(__FILE__)),
|
37
|
+
'lib',
|
38
|
+
'hatemile',
|
39
|
+
'util',
|
40
|
+
'html',
|
41
|
+
'nokogiri',
|
42
|
+
'nokogiri_html_dom_text_node'
|
43
|
+
)
|
44
|
+
|
45
|
+
##
|
46
|
+
# Test methods of Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMElement
|
47
|
+
# class.
|
48
|
+
class TestNokogiriHTMLDOMElement < Test::Unit::TestCase
|
49
|
+
##
|
50
|
+
# The content of aside element of parser.
|
51
|
+
ASIDE_TEXT = '
|
52
|
+
Exemple of <mark>aside</mark>.
|
53
|
+
<!-- Comment -->
|
54
|
+
'.freeze
|
55
|
+
|
56
|
+
##
|
57
|
+
# The aside element of parser.
|
58
|
+
ASIDE_CONTENT =
|
59
|
+
'<aside class="aside" data-attribute="custom_value">' \
|
60
|
+
"#{ASIDE_TEXT}</aside>".freeze
|
61
|
+
|
62
|
+
##
|
63
|
+
# Initialize common attributes used by test methods.
|
64
|
+
def setup
|
65
|
+
@html_parser = Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMParser.new(
|
66
|
+
"<!DOCTYPE html>
|
67
|
+
<html>
|
68
|
+
<head>
|
69
|
+
<title>HaTeMiLe Tests</title>
|
70
|
+
<meta charset=\"UTF-8\" />
|
71
|
+
</head>
|
72
|
+
<body>
|
73
|
+
<section>
|
74
|
+
<header></header>
|
75
|
+
<article>
|
76
|
+
\n
|
77
|
+
</article>
|
78
|
+
<footer><!-- Footer --></footer>
|
79
|
+
</section>
|
80
|
+
<span attribute=\"value\" data-attribute=\"custom_value\">
|
81
|
+
<!-- Comment -->
|
82
|
+
Text node
|
83
|
+
<strong>Strong text</strong>
|
84
|
+
<hr />
|
85
|
+
</span>
|
86
|
+
<div></div>
|
87
|
+
<p>
|
88
|
+
<del>Deleted text</del>
|
89
|
+
</p>
|
90
|
+
<table>
|
91
|
+
<thead><tr>
|
92
|
+
<th>Table header</th>
|
93
|
+
</tr></thead>
|
94
|
+
<tbody>
|
95
|
+
<tr>
|
96
|
+
<td>Table <ins>cell</ins></td>
|
97
|
+
</tr>
|
98
|
+
</tbody>
|
99
|
+
<tfoot><!-- Table footer --></tfoot>
|
100
|
+
</table>
|
101
|
+
<ul>
|
102
|
+
<li id=\"li-1\">1</li>
|
103
|
+
<li id=\"li-3\">3</li>
|
104
|
+
</ul>
|
105
|
+
<ol>
|
106
|
+
<li>1</li>
|
107
|
+
<li>2</li>
|
108
|
+
<li>3</li>
|
109
|
+
<li>4</li>
|
110
|
+
<li>5</li>
|
111
|
+
</ol>
|
112
|
+
#{ASIDE_CONTENT}
|
113
|
+
<form>
|
114
|
+
<label>
|
115
|
+
Text:
|
116
|
+
<input type=\"text\" name=\"number\" />
|
117
|
+
</label>
|
118
|
+
</form>
|
119
|
+
<h1></h1>
|
120
|
+
<h2></h2>
|
121
|
+
</body>
|
122
|
+
</html>"
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Test == method.
|
128
|
+
def test_equals
|
129
|
+
body = @html_parser.find('body').first_result
|
130
|
+
section = @html_parser.find('section').first_result
|
131
|
+
|
132
|
+
assert_equal(body, @html_parser.find('body').first_result)
|
133
|
+
assert_equal(section, body.get_first_element_child)
|
134
|
+
assert_equal(body, section.get_parent_element)
|
135
|
+
assert_not_equal(body, section)
|
136
|
+
assert_not_equal(body, @html_parser.create_element('body'))
|
137
|
+
assert_not_equal(
|
138
|
+
@html_parser.find('header').first_result,
|
139
|
+
@html_parser.create_element('header')
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Test get_tag_name method.
|
145
|
+
def test_get_tag_name
|
146
|
+
assert_equal('SPAN', @html_parser.find('span').first_result.get_tag_name)
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Test get_attribute method.
|
151
|
+
def test_get_attribute
|
152
|
+
span = @html_parser.find('span').first_result
|
153
|
+
|
154
|
+
assert_equal('value', span.get_attribute('attribute'))
|
155
|
+
assert_equal('custom_value', span.get_attribute('data-attribute'))
|
156
|
+
assert_nil(span.get_attribute('newattribute'))
|
157
|
+
assert_nil(span.get_attribute('data-newattribute'))
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Test set_attribute method.
|
162
|
+
def test_set_attribute
|
163
|
+
span = @html_parser.find('span').first_result
|
164
|
+
|
165
|
+
span.set_attribute('newattribute', 'new_value')
|
166
|
+
span.set_attribute('data-newattribute', 'custom_new_value')
|
167
|
+
span.set_attribute('attribute', 'other_value')
|
168
|
+
span.set_attribute('data-attribute', 'custom_other_value')
|
169
|
+
|
170
|
+
assert_equal('new_value', span.get_attribute('newattribute'))
|
171
|
+
assert_equal('custom_new_value', span.get_attribute('data-newattribute'))
|
172
|
+
assert_equal('other_value', span.get_attribute('attribute'))
|
173
|
+
assert_equal('custom_other_value', span.get_attribute('data-attribute'))
|
174
|
+
assert_nil(span.get_attribute('invalidattribute'))
|
175
|
+
assert_nil(span.get_attribute('data-invalidattribute'))
|
176
|
+
end
|
177
|
+
|
178
|
+
##
|
179
|
+
# Test has_attribute method.
|
180
|
+
def test_has_attribute?
|
181
|
+
span = @html_parser.find('span').first_result
|
182
|
+
|
183
|
+
assert(!span.has_attribute?('newattribute'))
|
184
|
+
assert(!span.has_attribute?('data-newattribute'))
|
185
|
+
assert(span.has_attribute?('attribute'))
|
186
|
+
assert(span.has_attribute?('data-attribute'))
|
187
|
+
|
188
|
+
span.set_attribute('newattribute', 'new_value')
|
189
|
+
span.set_attribute('data-newattribute', 'custom_new_value')
|
190
|
+
span.set_attribute('attribute', 'other_value')
|
191
|
+
span.set_attribute('data-attribute', 'custom_other_value')
|
192
|
+
|
193
|
+
assert(span.has_attribute?('newattribute'))
|
194
|
+
assert(span.has_attribute?('data-newattribute'))
|
195
|
+
assert(span.has_attribute?('attribute'))
|
196
|
+
assert(span.has_attribute?('data-attribute'))
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Test remove_attribute method.
|
201
|
+
def test_remove_attribute
|
202
|
+
span = @html_parser.find('span').first_result
|
203
|
+
|
204
|
+
assert(span.has_attribute?('attribute'))
|
205
|
+
assert(span.has_attribute?('data-attribute'))
|
206
|
+
|
207
|
+
span.remove_attribute('attribute')
|
208
|
+
span.remove_attribute('data-attribute')
|
209
|
+
|
210
|
+
assert(!span.has_attribute?('attribute'))
|
211
|
+
assert(!span.has_attribute?('data-attribute'))
|
212
|
+
end
|
213
|
+
|
214
|
+
##
|
215
|
+
# Test has_attributes? method.
|
216
|
+
def test_has_attributes
|
217
|
+
span = @html_parser.find('span').first_result
|
218
|
+
|
219
|
+
assert(span.has_attributes?)
|
220
|
+
|
221
|
+
span.remove_attribute('attribute')
|
222
|
+
|
223
|
+
assert(span.has_attributes?)
|
224
|
+
|
225
|
+
span.remove_attribute('data-attribute')
|
226
|
+
|
227
|
+
assert(!span.has_attributes?)
|
228
|
+
end
|
229
|
+
|
230
|
+
##
|
231
|
+
# Test get_children_elements method.
|
232
|
+
def test_get_children_elements
|
233
|
+
strong = @html_parser.find('strong').first_result
|
234
|
+
children = @html_parser.find('span').first_result.get_children_elements
|
235
|
+
|
236
|
+
assert_equal(2, children.length)
|
237
|
+
assert_equal(strong, children.first)
|
238
|
+
assert_equal('HR', children.last.get_tag_name)
|
239
|
+
assert_equal([], strong.get_children_elements)
|
240
|
+
end
|
241
|
+
|
242
|
+
##
|
243
|
+
# Test get_children method.
|
244
|
+
def test_get_children
|
245
|
+
children = @html_parser.find('span').first_result.get_children
|
246
|
+
|
247
|
+
assert_equal(6, children.length)
|
248
|
+
assert_instance_of(
|
249
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
250
|
+
children.first
|
251
|
+
)
|
252
|
+
assert_equal(
|
253
|
+
'',
|
254
|
+
children.first.get_text_content.strip.gsub(/[\n\r\t]+/, '')
|
255
|
+
)
|
256
|
+
assert_instance_of(
|
257
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
258
|
+
children[1]
|
259
|
+
)
|
260
|
+
assert_equal(
|
261
|
+
'Text node',
|
262
|
+
children[1].get_text_content.strip.gsub(/[\n\r\t]+/, '')
|
263
|
+
)
|
264
|
+
assert_equal('STRONG', children[2].get_tag_name)
|
265
|
+
assert_instance_of(
|
266
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
267
|
+
children[3]
|
268
|
+
)
|
269
|
+
assert_equal('', children[3].get_text_content.strip.gsub(/[\n\r\t]+/, ''))
|
270
|
+
assert_equal('HR', children[4].get_tag_name)
|
271
|
+
assert_instance_of(
|
272
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
273
|
+
children.last
|
274
|
+
)
|
275
|
+
assert_equal('', children.last.get_text_content.strip.gsub(/[\n\r\t]+/, ''))
|
276
|
+
assert_equal([], @html_parser.find('hr').first_result.get_children)
|
277
|
+
end
|
278
|
+
|
279
|
+
##
|
280
|
+
# Test append_element method.
|
281
|
+
def test_append_element
|
282
|
+
paragraph = @html_parser.find('p').first_result
|
283
|
+
del = @html_parser.find('del').first_result
|
284
|
+
i = @html_parser.create_element('i')
|
285
|
+
|
286
|
+
paragraph.append_element(@html_parser.create_element('em'))
|
287
|
+
|
288
|
+
assert_equal('EM', paragraph.get_children_elements.last.get_tag_name)
|
289
|
+
assert_equal('EM', paragraph.get_children.last.get_tag_name)
|
290
|
+
assert_equal([], del.get_children_elements)
|
291
|
+
|
292
|
+
del.append_element(i)
|
293
|
+
|
294
|
+
assert_equal([i], del.get_children_elements)
|
295
|
+
end
|
296
|
+
|
297
|
+
##
|
298
|
+
# Test prepend_element method.
|
299
|
+
def test_prepend_element
|
300
|
+
paragraph = @html_parser.find('p').first_result
|
301
|
+
mark = @html_parser.create_element('mark')
|
302
|
+
i = @html_parser.create_element('i')
|
303
|
+
paragraph.prepend_element(mark)
|
304
|
+
children_elements = paragraph.get_children_elements
|
305
|
+
|
306
|
+
assert_equal(mark, children_elements.first)
|
307
|
+
assert_equal(mark, paragraph.get_children.first)
|
308
|
+
assert_equal('DEL', children_elements.last.get_tag_name)
|
309
|
+
assert_equal([], mark.get_children_elements)
|
310
|
+
|
311
|
+
mark.append_element(i)
|
312
|
+
|
313
|
+
assert_equal([i], mark.get_children_elements)
|
314
|
+
end
|
315
|
+
|
316
|
+
##
|
317
|
+
# Test normalize method.
|
318
|
+
def test_normalize
|
319
|
+
div = @html_parser.find('div').first_result
|
320
|
+
|
321
|
+
div.append_text('Text 1').append_text('Text 2').append_text('Text 3')
|
322
|
+
div.normalize
|
323
|
+
|
324
|
+
assert_equal(1, div.get_children.length)
|
325
|
+
end
|
326
|
+
|
327
|
+
##
|
328
|
+
# Test has_children_elements? method.
|
329
|
+
def test_has_children_elements
|
330
|
+
assert(@html_parser.find('section').first_result.has_children_elements?)
|
331
|
+
assert(!@html_parser.find('header').first_result.has_children_elements?)
|
332
|
+
assert(!@html_parser.find('article').first_result.has_children_elements?)
|
333
|
+
assert(!@html_parser.find('footer').first_result.has_children_elements?)
|
334
|
+
end
|
335
|
+
|
336
|
+
##
|
337
|
+
# Test has_children? method.
|
338
|
+
def test_has_children
|
339
|
+
assert(@html_parser.find('table').first_result.has_children?)
|
340
|
+
assert(@html_parser.find('thead').first_result.has_children?)
|
341
|
+
assert(@html_parser.find('th').first_result.has_children?)
|
342
|
+
assert(@html_parser.find('td').first_result.has_children?)
|
343
|
+
assert(!@html_parser.find('tfoot').first_result.has_children?)
|
344
|
+
end
|
345
|
+
|
346
|
+
##
|
347
|
+
# Test get_inner_html method.
|
348
|
+
def test_get_inner_html
|
349
|
+
assert_equal(
|
350
|
+
ASIDE_TEXT,
|
351
|
+
@html_parser.find('aside').first_result.get_inner_html
|
352
|
+
)
|
353
|
+
end
|
354
|
+
|
355
|
+
##
|
356
|
+
# Test get_outer_html method.
|
357
|
+
def test_get_outer_html
|
358
|
+
assert_equal(
|
359
|
+
ASIDE_CONTENT,
|
360
|
+
@html_parser.find('aside').first_result.get_outer_html
|
361
|
+
)
|
362
|
+
end
|
363
|
+
|
364
|
+
##
|
365
|
+
# Test get_first_element_child method.
|
366
|
+
def test_get_first_element_child
|
367
|
+
section = @html_parser.find('section').first_result
|
368
|
+
header = @html_parser.find('header').first_result
|
369
|
+
|
370
|
+
assert_equal(header, section.get_first_element_child)
|
371
|
+
assert_nil(header.get_first_element_child)
|
372
|
+
assert_nil(
|
373
|
+
@html_parser.find('article').first_result.get_first_element_child
|
374
|
+
)
|
375
|
+
assert_nil(@html_parser.find('footer').first_result.get_first_element_child)
|
376
|
+
end
|
377
|
+
|
378
|
+
##
|
379
|
+
# Test get_last_element_child method.
|
380
|
+
def test_get_last_element_child
|
381
|
+
section = @html_parser.find('section').first_result
|
382
|
+
footer = @html_parser.find('footer').first_result
|
383
|
+
|
384
|
+
assert_equal(footer, section.get_last_element_child)
|
385
|
+
assert_nil(@html_parser.find('header').first_result.get_last_element_child)
|
386
|
+
assert_nil(@html_parser.find('article').first_result.get_last_element_child)
|
387
|
+
assert_nil(footer.get_last_element_child)
|
388
|
+
end
|
389
|
+
|
390
|
+
##
|
391
|
+
# Test get_first_node_child method.
|
392
|
+
def test_get_first_node_child
|
393
|
+
th_first_child = @html_parser.find('th').first_result.get_first_node_child
|
394
|
+
td_first_child = @html_parser.find('td').first_result.get_first_node_child
|
395
|
+
|
396
|
+
assert_equal(
|
397
|
+
'TR',
|
398
|
+
@html_parser.find('thead').first_result.get_first_node_child.get_tag_name
|
399
|
+
)
|
400
|
+
assert_instance_of(
|
401
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
402
|
+
th_first_child
|
403
|
+
)
|
404
|
+
assert_equal('Table header', th_first_child.get_text_content)
|
405
|
+
assert_instance_of(
|
406
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
407
|
+
td_first_child
|
408
|
+
)
|
409
|
+
assert_equal('Table', td_first_child.get_text_content.strip)
|
410
|
+
assert_nil(@html_parser.find('tfoot').first_result.get_first_node_child)
|
411
|
+
end
|
412
|
+
|
413
|
+
##
|
414
|
+
# Test get_last_node_child method.
|
415
|
+
def test_get_last_node_child
|
416
|
+
th_last_child = @html_parser.find('th').first_result.get_last_node_child
|
417
|
+
td_last_child = @html_parser.find('td').first_result.get_last_node_child
|
418
|
+
|
419
|
+
assert_equal(
|
420
|
+
'TR',
|
421
|
+
@html_parser.find('thead').first_result.get_last_node_child.get_tag_name
|
422
|
+
)
|
423
|
+
assert_instance_of(
|
424
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMTextNode,
|
425
|
+
th_last_child
|
426
|
+
)
|
427
|
+
assert_equal('Table header', th_last_child.get_text_content)
|
428
|
+
assert_instance_of(
|
429
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMElement,
|
430
|
+
td_last_child
|
431
|
+
)
|
432
|
+
assert_equal('INS', td_last_child.get_tag_name)
|
433
|
+
assert_nil(@html_parser.find('tfoot').first_result.get_last_node_child)
|
434
|
+
end
|
435
|
+
|
436
|
+
##
|
437
|
+
# Test clone_element method.
|
438
|
+
def test_clone_element
|
439
|
+
tbody = @html_parser.find('tbody').first_result
|
440
|
+
|
441
|
+
assert_equal(tbody.get_outer_html, tbody.clone_element.get_outer_html)
|
442
|
+
end
|
443
|
+
|
444
|
+
##
|
445
|
+
# Test get_text_content method.
|
446
|
+
def test_get_text_content
|
447
|
+
assert_equal(
|
448
|
+
'Table header',
|
449
|
+
@html_parser.find('th').first_result.get_text_content
|
450
|
+
)
|
451
|
+
assert_equal(
|
452
|
+
'Table cell',
|
453
|
+
@html_parser.find('td').first_result.get_text_content
|
454
|
+
)
|
455
|
+
assert_equal('', @html_parser.find('tfoot').first_result.get_text_content)
|
456
|
+
end
|
457
|
+
|
458
|
+
##
|
459
|
+
# Test insert_before method.
|
460
|
+
def test_insert_before
|
461
|
+
list_element = @html_parser.find('ul').first_result
|
462
|
+
new_item_element = @html_parser.create_element('li')
|
463
|
+
new_item_element.set_attribute('id', 'li-2')
|
464
|
+
new_item_element.append_text('2')
|
465
|
+
@html_parser.find('#li-3').first_result.insert_before(new_item_element)
|
466
|
+
|
467
|
+
assert_equal(
|
468
|
+
'li-1',
|
469
|
+
list_element.get_first_element_child.get_attribute('id')
|
470
|
+
)
|
471
|
+
assert_equal(
|
472
|
+
'li-2',
|
473
|
+
list_element.get_children_elements[1].get_attribute('id')
|
474
|
+
)
|
475
|
+
end
|
476
|
+
|
477
|
+
##
|
478
|
+
# Test insert_after method.
|
479
|
+
def test_insert_after
|
480
|
+
list_element = @html_parser.find('ul').first_result
|
481
|
+
new_item_element = @html_parser.create_element('li')
|
482
|
+
new_item_element.set_attribute('id', 'li-4')
|
483
|
+
new_item_element.append_text('4')
|
484
|
+
@html_parser.find('#li-3').first_result.insert_after(new_item_element)
|
485
|
+
|
486
|
+
assert_equal(
|
487
|
+
'li-1',
|
488
|
+
list_element.get_first_element_child.get_attribute('id')
|
489
|
+
)
|
490
|
+
assert_equal(
|
491
|
+
'li-4',
|
492
|
+
list_element.get_last_element_child.get_attribute('id')
|
493
|
+
)
|
494
|
+
end
|
495
|
+
|
496
|
+
##
|
497
|
+
# Test remove_node method.
|
498
|
+
def test_remove_node
|
499
|
+
list_element = @html_parser.find('ol').first_result
|
500
|
+
|
501
|
+
assert_equal(5, list_element.get_children_elements.length)
|
502
|
+
|
503
|
+
list_element.get_first_element_child.remove_node
|
504
|
+
list_element.get_last_element_child.remove_node
|
505
|
+
|
506
|
+
assert_equal(3, list_element.get_children_elements.length)
|
507
|
+
|
508
|
+
list_element.remove_node
|
509
|
+
|
510
|
+
assert_nil(@html_parser.find('ol').first_result)
|
511
|
+
assert_nil(@html_parser.find('ol li').first_result)
|
512
|
+
end
|
513
|
+
|
514
|
+
##
|
515
|
+
# Test replace_node method.
|
516
|
+
def test_replace_node
|
517
|
+
@html_parser.find('input[name=number]').first_result.replace_node(
|
518
|
+
@html_parser.create_element('textarea')
|
519
|
+
)
|
520
|
+
|
521
|
+
assert_nil(@html_parser.find('input[name=number]').first_result)
|
522
|
+
assert_not_nil(@html_parser.find('textarea').first_result)
|
523
|
+
end
|
524
|
+
|
525
|
+
##
|
526
|
+
# Test append_text method.
|
527
|
+
def test_append_text
|
528
|
+
h1 = @html_parser.find('h1').first_result
|
529
|
+
|
530
|
+
assert_not_nil(h1.append_text('Example'))
|
531
|
+
assert_instance_of(
|
532
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMElement,
|
533
|
+
h1.append_text(' of ')
|
534
|
+
)
|
535
|
+
|
536
|
+
h1.append_text('append ').append_text('text.')
|
537
|
+
|
538
|
+
assert_equal('Example of append text.', h1.get_text_content)
|
539
|
+
end
|
540
|
+
|
541
|
+
##
|
542
|
+
# Test prepend_text method.
|
543
|
+
def test_prepend_text
|
544
|
+
h2 = @html_parser.find('h2').first_result
|
545
|
+
|
546
|
+
assert_not_nil(h2.prepend_text(' text.'))
|
547
|
+
assert_instance_of(
|
548
|
+
Hatemile::Util::Html::NokogiriLib::NokogiriHTMLDOMElement,
|
549
|
+
h2.prepend_text('prepend')
|
550
|
+
)
|
551
|
+
|
552
|
+
h2.prepend_text(' of ').prepend_text('Example')
|
553
|
+
|
554
|
+
assert_equal('Example of prepend text.', h2.get_text_content)
|
555
|
+
end
|
556
|
+
|
557
|
+
##
|
558
|
+
# Test get_parent_element method.
|
559
|
+
def test_get_parent_element
|
560
|
+
section = @html_parser.find('section').first_result
|
561
|
+
|
562
|
+
assert_equal(
|
563
|
+
section,
|
564
|
+
@html_parser.find('header').first_result.get_parent_element
|
565
|
+
)
|
566
|
+
assert_equal(
|
567
|
+
section,
|
568
|
+
@html_parser.find('article').first_result.get_parent_element
|
569
|
+
)
|
570
|
+
assert_equal(
|
571
|
+
@html_parser.find('body').first_result,
|
572
|
+
section.get_parent_element
|
573
|
+
)
|
574
|
+
end
|
575
|
+
|
576
|
+
##
|
577
|
+
# Test get_set_data method.
|
578
|
+
def test_get_set_data
|
579
|
+
body = @html_parser.find('body').first_result
|
580
|
+
section = @html_parser.find('section').first_result
|
581
|
+
|
582
|
+
section.set_data(body.get_data)
|
583
|
+
section.set_attribute('class', 'body')
|
584
|
+
assert_equal('body', body.get_attribute('class'))
|
585
|
+
end
|
586
|
+
end
|