wiki-api 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +64 -33
- data/lib/wiki/api/connect.rb +21 -7
- data/lib/wiki/api/page.rb +23 -50
- data/lib/wiki/api/page_block.rb +6 -4
- data/lib/wiki/api/page_headline.rb +97 -2
- data/lib/wiki/api/page_link.rb +9 -4
- data/lib/wiki/api/page_list_item.rb +4 -2
- data/lib/wiki/api/util.rb +12 -1
- data/lib/wiki/api/version.rb +1 -1
- data/test/unit/files/Wiktionary_program.html +4232 -0
- data/test/unit/wiki_page_offline.rb +262 -0
- data/wiki-api.gemspec +2 -2
- metadata +8 -8
- data/test/unit/wiki_page_config.rb +0 -45
- data/test/unit/wiki_page_object.rb +0 -229
@@ -0,0 +1,262 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/wiki/api")
|
6
|
+
|
7
|
+
#
|
8
|
+
# Testing the parsing of URI (with a predownloaded HTML file):
|
9
|
+
# /files/Wiktionary_Welcome,_newcomers.html (2013-03-27)
|
10
|
+
#
|
11
|
+
# Online equivalent:
|
12
|
+
# https://en.wiktionary.org/wiki/Wiktionary:Welcome,_newcomers
|
13
|
+
#
|
14
|
+
|
15
|
+
class WikiPageOfflinePage < Test::Unit::TestCase
|
16
|
+
|
17
|
+
# this global is required to resolve URIs (MediaWiki uses relative paths in their links)
|
18
|
+
URI_CONFIG = { uri: "http://en.wiktionary.org" }
|
19
|
+
# use local file for test loading
|
20
|
+
PAGE_CONFIG = { file: File.expand_path(File.dirname(__FILE__) + "/files/Wiktionary_program.html") }
|
21
|
+
|
22
|
+
def setup
|
23
|
+
# NOTE: comment Page.config, to use the online MediaWiki instance
|
24
|
+
Wiki::Api::Connect.config = URI_CONFIG
|
25
|
+
Wiki::Api::Connect.config.merge! PAGE_CONFIG
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
end
|
30
|
+
|
31
|
+
# test simple page invocation
|
32
|
+
def test_headlines_nested
|
33
|
+
|
34
|
+
# load page
|
35
|
+
page = Wiki::Api::Page.new name: "program"
|
36
|
+
assert page.is_a?(Wiki::Api::Page), "expected Page object"
|
37
|
+
headline = page.root_headline
|
38
|
+
assert headline.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
39
|
+
assert headline.name == "program", "expected developer headline"
|
40
|
+
|
41
|
+
# search nested headline: english
|
42
|
+
english = headline.headline("english").first
|
43
|
+
assert english.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
44
|
+
|
45
|
+
# search nested headline: noun
|
46
|
+
noun = english.headline("noun").first
|
47
|
+
assert noun.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
48
|
+
|
49
|
+
# get block
|
50
|
+
block = noun.block
|
51
|
+
assert block.is_a?(Wiki::Api::PageBlock), "expected PageBlock object"
|
52
|
+
|
53
|
+
# list items
|
54
|
+
block.list_items.each do |list_item|
|
55
|
+
assert list_item.is_a?(Wiki::Api::PageListItem), "expected PageListItem object"
|
56
|
+
# links
|
57
|
+
list_item.links.each do |link|
|
58
|
+
assert link.is_a?(Wiki::Api::PageLink), "expected PageListItem object"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# links
|
63
|
+
block.links.each do |link|
|
64
|
+
assert link.is_a?(Wiki::Api::PageLink), "expected PageListItem object"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# def test_headlines_verify_tree_objects
|
70
|
+
# page = Wiki::Api::Page.new name: "program"
|
71
|
+
# assert page.is_a?(Wiki::Api::Page), "expected Page object"
|
72
|
+
|
73
|
+
# # get root headline
|
74
|
+
# headline = page.root_headline
|
75
|
+
# assert headline.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
76
|
+
# assert headline.name == "program", "expected program headline"
|
77
|
+
|
78
|
+
# # search in depth on headline noun
|
79
|
+
# nouns = headline.headline_by_name "noun", 1
|
80
|
+
|
81
|
+
# nouns.each do |noun|
|
82
|
+
# assert noun.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
83
|
+
|
84
|
+
# # get block
|
85
|
+
# block = noun.block
|
86
|
+
# assert block.is_a?(Wiki::Api::PageBlock), "expected PageBlock object"
|
87
|
+
|
88
|
+
# # list items
|
89
|
+
# block.list_items.each do |list_item|
|
90
|
+
# assert list_item.is_a?(Wiki::Api::PageListItem), "expected PageListItem object"
|
91
|
+
# # links
|
92
|
+
# list_item.links.each do |link|
|
93
|
+
# assert link.is_a?(Wiki::Api::PageLink), "expected PageListItem object"
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
|
97
|
+
# # links
|
98
|
+
# block.links.each do |link|
|
99
|
+
# assert link.is_a?(Wiki::Api::PageLink), "expected PageListItem object"
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
# end
|
103
|
+
|
104
|
+
|
105
|
+
def test_headlines_verify_tree_data
|
106
|
+
page = Wiki::Api::Page.new name: "program"
|
107
|
+
headline = page.root_headline
|
108
|
+
# get root
|
109
|
+
assert headline.name == "program", "expected program name"
|
110
|
+
|
111
|
+
# iterate one deep and verify headline index names
|
112
|
+
headline.headlines.each do |name, headline|
|
113
|
+
assert headline.name == name
|
114
|
+
end
|
115
|
+
headlines = headline.headlines.values
|
116
|
+
|
117
|
+
# English
|
118
|
+
english_headlines = headlines[0]
|
119
|
+
assert english_headlines.name == "English"
|
120
|
+
english_headlines = english_headlines.headlines.values
|
121
|
+
assert english_headlines[0].name == "Alternative_forms"
|
122
|
+
assert english_headlines[1].name == "Etymology"
|
123
|
+
assert english_headlines[2].name == "Pronunciation"
|
124
|
+
assert english_headlines[3].name == "Noun"
|
125
|
+
noun_english_headlines = english_headlines[3].headlines.values
|
126
|
+
assert noun_english_headlines[0].name == "Usage_notes"
|
127
|
+
assert noun_english_headlines[1].name == "Synonyms"
|
128
|
+
assert noun_english_headlines[2].name == "Translations"
|
129
|
+
assert english_headlines[4].name == "Verb"
|
130
|
+
verb_english_headlines = english_headlines[4].headlines.values
|
131
|
+
assert verb_english_headlines[0].name == "Related_terms"
|
132
|
+
assert verb_english_headlines[1].name == "Translations_2"
|
133
|
+
assert english_headlines[5].name == "External_links"
|
134
|
+
|
135
|
+
# Czech
|
136
|
+
czech_headlines = headlines[1]
|
137
|
+
assert czech_headlines.name == "Czech"
|
138
|
+
czech_headlines = czech_headlines.headlines.values
|
139
|
+
assert czech_headlines[0].name == "Pronunciation_2"
|
140
|
+
assert czech_headlines[1].name == "Noun_2"
|
141
|
+
|
142
|
+
# Hungarian
|
143
|
+
hungarian_headlines = headlines[2]
|
144
|
+
assert hungarian_headlines.name == "Hungarian"
|
145
|
+
hungarian_headlines = hungarian_headlines.headlines.values
|
146
|
+
assert hungarian_headlines[0].name == "Pronunciation_3"
|
147
|
+
assert hungarian_headlines[1].name == "Noun_3"
|
148
|
+
noun_hungarian_headlines = hungarian_headlines[1].headlines.values
|
149
|
+
assert noun_hungarian_headlines[0].name == "Declension"
|
150
|
+
assert noun_hungarian_headlines[1].name == "Derived_terms"
|
151
|
+
|
152
|
+
# Norwegian
|
153
|
+
norwegian_headlines = headlines[3]
|
154
|
+
assert norwegian_headlines.name == "Norwegian_Bokm.C3.A5l"
|
155
|
+
norwegian_headlines = norwegian_headlines.headlines.values
|
156
|
+
assert norwegian_headlines[0].name == "Noun_4"
|
157
|
+
|
158
|
+
# Romanian
|
159
|
+
romanian_headlines = headlines[4]
|
160
|
+
assert romanian_headlines.name == "Romanian"
|
161
|
+
romanian_headlines = romanian_headlines.headlines.values
|
162
|
+
assert romanian_headlines[0].name == "Etymology_2"
|
163
|
+
assert romanian_headlines[1].name == "Noun_5"
|
164
|
+
noun_romanian_headlines = romanian_headlines[1].headlines.values
|
165
|
+
assert noun_romanian_headlines[0].name == "Declension_2"
|
166
|
+
assert noun_romanian_headlines[1].name == "Related_terms_2"
|
167
|
+
|
168
|
+
# Serbo-Croatian
|
169
|
+
serb_croatian_headlines = headlines[5]
|
170
|
+
assert serb_croatian_headlines.name == "Serbo-Croatian"
|
171
|
+
serb_croatian_headlines = serb_croatian_headlines.headlines.values
|
172
|
+
assert serb_croatian_headlines[0].name == "Noun_6"
|
173
|
+
noun_serb_croatian_headlines = serb_croatian_headlines[0].headlines.values
|
174
|
+
assert noun_serb_croatian_headlines[0].name == "Declension_3"
|
175
|
+
|
176
|
+
# Slovak
|
177
|
+
slovak_headlines = headlines[6]
|
178
|
+
assert slovak_headlines.name == "Slovak"
|
179
|
+
slovak_headlines = slovak_headlines.headlines.values
|
180
|
+
assert slovak_headlines[0].name == "Noun_7"
|
181
|
+
|
182
|
+
# Swedish
|
183
|
+
swedish_headlines = headlines[7]
|
184
|
+
assert swedish_headlines.name == "Swedish"
|
185
|
+
swedish_headlines = swedish_headlines.headlines.values
|
186
|
+
assert swedish_headlines[0].name == "Etymology_3"
|
187
|
+
assert swedish_headlines[1].name == "Noun_8"
|
188
|
+
noun_swedish_headlines = swedish_headlines[1].headlines.values
|
189
|
+
assert noun_swedish_headlines[0].name == "Declension_4"
|
190
|
+
|
191
|
+
# Turkish
|
192
|
+
turkish_headlines = headlines[8]
|
193
|
+
assert turkish_headlines.name == "Turkish"
|
194
|
+
turkish_headlines = turkish_headlines.headlines.values
|
195
|
+
assert turkish_headlines[0].name == "Etymology_4"
|
196
|
+
assert turkish_headlines[1].name == "Noun_9"
|
197
|
+
noun_turkish_headlines = turkish_headlines[1].headlines.values
|
198
|
+
assert noun_turkish_headlines[0].name == "Declension_5"
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
def test_headlines_search
|
204
|
+
page = Wiki::Api::Page.new name: "program"
|
205
|
+
headline = page.root_headline
|
206
|
+
# get root
|
207
|
+
assert headline.name == "program", "expected program name"
|
208
|
+
|
209
|
+
headlines = headline.headline "english"
|
210
|
+
assert !headlines.empty?, "expected a headline"
|
211
|
+
|
212
|
+
# iterate english
|
213
|
+
headlines.each do |headline|
|
214
|
+
assert headline.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
215
|
+
assert headline.name == "English", "expected English"
|
216
|
+
noun_headlines = headline.headline "noun"
|
217
|
+
assert !noun_headlines.empty?, "exptected a headline"
|
218
|
+
# iterate nouns
|
219
|
+
noun_headlines.each do |noun_headline|
|
220
|
+
assert noun_headline.is_a?(Wiki::Api::PageHeadline), "expected PageHeadline object"
|
221
|
+
assert noun_headline.name == "Noun", "expected Noun"
|
222
|
+
|
223
|
+
#list_item.links.each do |link|
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_headlines_has_headline
|
229
|
+
# load page
|
230
|
+
page = Wiki::Api::Page.new name: "program"
|
231
|
+
|
232
|
+
# get root
|
233
|
+
root_headline = page.root_headline
|
234
|
+
assert root_headline.name == "program", "expected program name"
|
235
|
+
headline = root_headline.headline("english").first
|
236
|
+
|
237
|
+
# verify existence english headlines
|
238
|
+
assert headline.has_headline?("alternative forms")
|
239
|
+
assert headline.has_headline?("etymology")
|
240
|
+
assert headline.has_headline?("pronunciation")
|
241
|
+
assert headline.has_headline?("noun")
|
242
|
+
assert headline.has_headline?("verb")
|
243
|
+
assert headline.has_headline?("external links")
|
244
|
+
assert !headline.has_headline?("alternative12 forms")
|
245
|
+
assert !headline.has_headline?("etymolfaogy")
|
246
|
+
assert !headline.has_headline?("pronunciafaation")
|
247
|
+
assert !headline.has_headline?("nounia")
|
248
|
+
assert !headline.has_headline?("verbaf")
|
249
|
+
assert !headline.has_headline?("externalaf links")
|
250
|
+
|
251
|
+
# verify existence czech headlines
|
252
|
+
headline = root_headline.headline("czech").first
|
253
|
+
assert headline.has_headline?("pronunciation")
|
254
|
+
assert headline.has_headline?("noun")
|
255
|
+
assert !headline.has_headline?("pronunciation82")
|
256
|
+
assert !headline.has_headline?("nouan")
|
257
|
+
|
258
|
+
#TODO: add other headlines here as well!
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
data/wiki-api.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Wiki::Api::VERSION
|
9
9
|
spec.authors = ["Dennis Blommesteijn"]
|
10
10
|
spec.email = ["dennis@blommesteijn.com"]
|
11
|
-
spec.description = %q{MediaWiki API and Page content parser for Headlines
|
12
|
-
spec.summary = %q{MediaWiki API and Page content parser for Headlines
|
11
|
+
spec.description = %q{MediaWiki API and Page content parser for Headlines (nested), TextBlocks, ListItems, and Links.}
|
12
|
+
spec.summary = %q{MediaWiki API and Page content parser for Headlines (nested), TextBlocks, ListItems, and Links.}
|
13
13
|
spec.homepage = "https://github.com/dblommesteijn/wiki-api"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiki-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Blommesteijn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
version: 2.0.0
|
81
81
|
prerelease: false
|
82
82
|
type: :development
|
83
|
-
description: MediaWiki API and Page content parser for Headlines
|
83
|
+
description: MediaWiki API and Page content parser for Headlines (nested), TextBlocks, ListItems, and Links.
|
84
84
|
email:
|
85
85
|
- dennis@blommesteijn.com
|
86
86
|
executables: []
|
@@ -103,9 +103,9 @@ files:
|
|
103
103
|
- lib/wiki/api/version.rb
|
104
104
|
- test/test_helper.rb
|
105
105
|
- test/unit/files/Wiktionary_Welcome,_newcomers.html
|
106
|
+
- test/unit/files/Wiktionary_program.html
|
106
107
|
- test/unit/wiki_connect.rb
|
107
|
-
- test/unit/
|
108
|
-
- test/unit/wiki_page_object.rb
|
108
|
+
- test/unit/wiki_page_offline.rb
|
109
109
|
- wiki-api.gemspec
|
110
110
|
homepage: https://github.com/dblommesteijn/wiki-api
|
111
111
|
licenses:
|
@@ -130,10 +130,10 @@ rubyforge_project:
|
|
130
130
|
rubygems_version: 2.0.3
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
|
-
summary: MediaWiki API and Page content parser for Headlines
|
133
|
+
summary: MediaWiki API and Page content parser for Headlines (nested), TextBlocks, ListItems, and Links.
|
134
134
|
test_files:
|
135
135
|
- test/test_helper.rb
|
136
136
|
- test/unit/files/Wiktionary_Welcome,_newcomers.html
|
137
|
+
- test/unit/files/Wiktionary_program.html
|
137
138
|
- test/unit/wiki_connect.rb
|
138
|
-
- test/unit/
|
139
|
-
- test/unit/wiki_page_object.rb
|
139
|
+
- test/unit/wiki_page_offline.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'test/unit'
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../lib/wiki/api")
|
6
|
-
|
7
|
-
#
|
8
|
-
# Testing the parsing of URI by passing a uri variable to Page:
|
9
|
-
# https://en.wiktionary.org/wiki/Wiktionary:Welcome,_newcomers
|
10
|
-
#
|
11
|
-
|
12
|
-
class WikiPageConfig < Test::Unit::TestCase
|
13
|
-
|
14
|
-
def setup
|
15
|
-
# NOTE: comment Page.config, to use the online MediaWiki instance
|
16
|
-
# Wiki::Api::Page.config = PAGE_CONFIG
|
17
|
-
# Wiki::Api::Connect.config = GLB_CONFIG
|
18
|
-
# @page_name = "Wiktionary:Welcome,_newcomers"
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
end
|
23
|
-
|
24
|
-
# test simple page invocation
|
25
|
-
def test_page_invocation_with_uri
|
26
|
-
page = Wiki::Api::Page.new name: "Wiktionary:Welcome,_newcomers", uri: "http://en.wiktionary.org"
|
27
|
-
headlines = page.headlines
|
28
|
-
assert !headlines.empty?, "expected headlines"
|
29
|
-
assert headlines.size < 1, "expected more than one headline"
|
30
|
-
headlines.each do |headline|
|
31
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_wrong_page_invocation_with_uri
|
36
|
-
begin
|
37
|
-
page = Wiki::Api::Page.new name: "A_Wrong_Page_Name", uri: "http://en.wiktionary.org"
|
38
|
-
assert false, "expected a failiure"
|
39
|
-
rescue Exception => e
|
40
|
-
assert true, "expected a failiure"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
@@ -1,229 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'test/unit'
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../lib/wiki/api")
|
6
|
-
|
7
|
-
#
|
8
|
-
# Testing the parsing of URI (with a predownloaded HTML file):
|
9
|
-
# /files/Wiktionary_Welcome,_newcomers.html (2013-03-27)
|
10
|
-
#
|
11
|
-
# Online equivalent:
|
12
|
-
# https://en.wiktionary.org/wiki/Wiktionary:Welcome,_newcomers
|
13
|
-
#
|
14
|
-
|
15
|
-
class WikiPageObject < Test::Unit::TestCase
|
16
|
-
|
17
|
-
# this global is required to resolve URIs (MediaWiki uses relative paths in their links)
|
18
|
-
GLB_CONFIG = { uri: "http://en.wiktionary.org" }
|
19
|
-
|
20
|
-
# use local file for test loading
|
21
|
-
PAGE_CONFIG = { file: File.expand_path(File.dirname(__FILE__) + "/files/Wiktionary_Welcome,_newcomers.html") }
|
22
|
-
|
23
|
-
def setup
|
24
|
-
# NOTE: comment Page.config, to use the online MediaWiki instance
|
25
|
-
Wiki::Api::Page.config = PAGE_CONFIG
|
26
|
-
Wiki::Api::Connect.config = GLB_CONFIG
|
27
|
-
@page_name = "Wiktionary:Welcome,_newcomers"
|
28
|
-
end
|
29
|
-
|
30
|
-
def teardown
|
31
|
-
end
|
32
|
-
|
33
|
-
# test simple page invocation
|
34
|
-
def test_page_invocation
|
35
|
-
page = Wiki::Api::Page.new name: @page_name
|
36
|
-
headlines = page.headlines
|
37
|
-
assert !headlines.empty?, "expected headlines"
|
38
|
-
headlines.each do |headline|
|
39
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# test nokogiri elements per headline
|
44
|
-
def test_page_elements
|
45
|
-
page = Wiki::Api::Page.new name: @page_name
|
46
|
-
headlines = page.headlines
|
47
|
-
assert !headlines.empty?, "expected headlines"
|
48
|
-
assert headlines.size > 1, "expected more than one headline"
|
49
|
-
headlines.each do |headline|
|
50
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
51
|
-
elements = headline.elements.flatten
|
52
|
-
assert !elements.empty?, "expected elements"
|
53
|
-
elements.each do |element|
|
54
|
-
assert element.is_a?(Nokogiri::XML::Element) ||
|
55
|
-
element.is_a?(Nokogiri::XML::Text) ||
|
56
|
-
element.is_a?(Nokogiri::XML::Comment), "expected nokogiri internals"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# test pageblocks for each headline
|
62
|
-
def test_page_blocks
|
63
|
-
page = Wiki::Api::Page.new name: @page_name
|
64
|
-
headlines = page.headlines
|
65
|
-
assert !headlines.empty?, "expected headlines"
|
66
|
-
assert headlines.size > 1, "expected more than one headline"
|
67
|
-
headlines.each do |headline|
|
68
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
69
|
-
block = headline.block
|
70
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# test string text from page block
|
75
|
-
def test_page_block_string_text
|
76
|
-
page = Wiki::Api::Page.new name: @page_name
|
77
|
-
headlines = page.headlines
|
78
|
-
assert !headlines.empty?, "expected headlines"
|
79
|
-
assert headlines.size > 1, "expected more than one headline"
|
80
|
-
headlines.each do |headline|
|
81
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
82
|
-
block = headline.block
|
83
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
84
|
-
texts = block.to_texts
|
85
|
-
assert texts.is_a?(Array) && !texts.empty?, "expected array"
|
86
|
-
texts.each do |text|
|
87
|
-
assert text.is_a?(String), "expected string"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# test list items from page blocks
|
93
|
-
def test_page_block_list_items
|
94
|
-
page = Wiki::Api::Page.new name: @page_name
|
95
|
-
headlines = page.headlines
|
96
|
-
assert !headlines.empty?, "expected headlines"
|
97
|
-
assert headlines.size > 1, "expected more than one headline"
|
98
|
-
headlines.each do |headline|
|
99
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
100
|
-
block = headline.block
|
101
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
102
|
-
list_items = block.list_items
|
103
|
-
assert list_items.is_a?(Array), "expected array"
|
104
|
-
list_items.each do |list_item|
|
105
|
-
assert list_item.is_a?(Wiki::Api::PageListItem), "expected list item object"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# test links within page blocks
|
111
|
-
def test_page_block_links
|
112
|
-
page = Wiki::Api::Page.new name: @page_name
|
113
|
-
headlines = page.headlines
|
114
|
-
assert !headlines.empty?, "expected headlines"
|
115
|
-
assert headlines.size > 1, "expected more than one headline"
|
116
|
-
headlines.each do |headline|
|
117
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
118
|
-
block = headline.block
|
119
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
120
|
-
links = block.links
|
121
|
-
assert links.is_a?(Array), "expected array"
|
122
|
-
links.each do |link|
|
123
|
-
assert link.is_a?(Wiki::Api::PageLink), "expected link object"
|
124
|
-
assert link.uri.is_a?(URI), "expected uri object"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# test links within list items
|
130
|
-
def test_page_block_list_inner_links
|
131
|
-
page = Wiki::Api::Page.new name: @page_name
|
132
|
-
headlines = page.headlines
|
133
|
-
assert !headlines.empty?, "expected headlines"
|
134
|
-
assert headlines.size > 1, "expected more than one headline"
|
135
|
-
headlines.each do |headline|
|
136
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
137
|
-
block = headline.block
|
138
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
139
|
-
list_items = block.list_items
|
140
|
-
assert list_items.is_a?(Array), "expected array"
|
141
|
-
list_items.each do |list_item|
|
142
|
-
assert list_item.is_a?(Wiki::Api::PageListItem), "expected list item object"
|
143
|
-
links = list_item.links
|
144
|
-
links.each do |link|
|
145
|
-
assert link.is_a?(Wiki::Api::PageLink), "expected link object"
|
146
|
-
assert link.uri.is_a?(URI), "expected uri object"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# test single headline invocation
|
153
|
-
def test_page_invocation_single
|
154
|
-
page = Wiki::Api::Page.new name: @page_name
|
155
|
-
headlines = page.headlines
|
156
|
-
assert !headlines.empty?, "expected headlines"
|
157
|
-
assert headlines.size > 1, "expected more than one headline"
|
158
|
-
|
159
|
-
# collect headline names
|
160
|
-
hs = []
|
161
|
-
headlines.each do |headline|
|
162
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
163
|
-
hs << headline.name
|
164
|
-
end
|
165
|
-
|
166
|
-
# query every headline manually
|
167
|
-
hs.each do |h|
|
168
|
-
# test headline query
|
169
|
-
headlines = page.headline h
|
170
|
-
# test for at least one (many indicates multiple headlines with the same name)
|
171
|
-
assert !headlines.empty?, "expected a list of headlines"
|
172
|
-
assert headlines.size == 1, "expected one headline"
|
173
|
-
headlines.each do |headline|
|
174
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_page_headline_search_downcase
|
180
|
-
page = Wiki::Api::Page.new name: @page_name
|
181
|
-
|
182
|
-
headlines = page.headline "Editing_Wiktionary"
|
183
|
-
assert !headlines.empty?, "expected headlines"
|
184
|
-
assert headlines.size == 1, "expected one headline"
|
185
|
-
|
186
|
-
|
187
|
-
# iterate headlines
|
188
|
-
headlines.each do |headline|
|
189
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
190
|
-
end
|
191
|
-
|
192
|
-
# search downcase
|
193
|
-
headlines = page.headline "editing_wiktionary"
|
194
|
-
assert !headlines.empty?, "expected headlines"
|
195
|
-
|
196
|
-
# iterate headlines
|
197
|
-
headlines.each do |headline|
|
198
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_page_headline_search_regular
|
204
|
-
page = Wiki::Api::Page.new name: @page_name
|
205
|
-
|
206
|
-
headlines = page.headline "Editing_Wiktionary"
|
207
|
-
assert !headlines.empty?, "expected headlines"
|
208
|
-
assert headlines.size == 1, "expected one headline"
|
209
|
-
|
210
|
-
# iterate headlines
|
211
|
-
headlines.each do |headline|
|
212
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
213
|
-
end
|
214
|
-
|
215
|
-
# search downcase
|
216
|
-
headlines = page.headline "editing_wiktionary"
|
217
|
-
assert headlines.size == 1, "expected one headline"
|
218
|
-
|
219
|
-
# search downcase with spaces
|
220
|
-
headlines = page.headline "editing wiktionary"
|
221
|
-
assert headlines.size == 1, "expected one headline"
|
222
|
-
|
223
|
-
# search idiot case with spaces
|
224
|
-
headlines = page.headline "eDiTinG wiKtiOnarY"
|
225
|
-
assert headlines.size == 1, "expected one headline"
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|