rss-nokogiri 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +19 -0
- data/.gitmodules +3 -0
- data/BSDL +22 -0
- data/COPYING +56 -0
- data/COPYING.ja +51 -0
- data/Gemfile +4 -0
- data/LEGAL +8 -0
- data/README.markdown +51 -0
- data/Rakefile +12 -0
- data/lib/rss/nokogiri.rb +92 -0
- data/rss-nokogiri.gemspec +24 -0
- data/test/regression/dot.png +0 -0
- data/test/regression/rss-assertions.rb +2090 -0
- data/test/regression/rss-testcase.rb +478 -0
- data/test/regression/test_1.0.rb +295 -0
- data/test/regression/test_2.0.rb +409 -0
- data/test/regression/test_accessor.rb +103 -0
- data/test/regression/test_atom.rb +681 -0
- data/test/regression/test_content.rb +104 -0
- data/test/regression/test_dublincore.rb +279 -0
- data/test/regression/test_image.rb +214 -0
- data/test/regression/test_inherit.rb +40 -0
- data/test/regression/test_itunes.rb +347 -0
- data/test/regression/test_maker_0.9.rb +474 -0
- data/test/regression/test_maker_1.0.rb +516 -0
- data/test/regression/test_maker_2.0.rb +757 -0
- data/test/regression/test_maker_atom_entry.rb +393 -0
- data/test/regression/test_maker_atom_feed.rb +454 -0
- data/test/regression/test_maker_content.rb +47 -0
- data/test/regression/test_maker_dc.rb +149 -0
- data/test/regression/test_maker_image.rb +62 -0
- data/test/regression/test_maker_itunes.rb +471 -0
- data/test/regression/test_maker_slash.rb +37 -0
- data/test/regression/test_maker_sy.rb +44 -0
- data/test/regression/test_maker_taxo.rb +81 -0
- data/test/regression/test_maker_trackback.rb +41 -0
- data/test/regression/test_maker_xml-stylesheet.rb +83 -0
- data/test/regression/test_parser.rb +62 -0
- data/test/regression/test_parser_1.0.rb +528 -0
- data/test/regression/test_parser_2.0.rb +122 -0
- data/test/regression/test_parser_atom_entry.rb +163 -0
- data/test/regression/test_parser_atom_feed.rb +276 -0
- data/test/regression/test_setup_maker_0.9.rb +246 -0
- data/test/regression/test_setup_maker_1.0.rb +550 -0
- data/test/regression/test_setup_maker_2.0.rb +308 -0
- data/test/regression/test_setup_maker_atom_entry.rb +409 -0
- data/test/regression/test_setup_maker_atom_feed.rb +445 -0
- data/test/regression/test_setup_maker_itunes.rb +144 -0
- data/test/regression/test_setup_maker_slash.rb +38 -0
- data/test/regression/test_slash.rb +64 -0
- data/test/regression/test_syndication.rb +125 -0
- data/test/regression/test_taxonomy.rb +172 -0
- data/test/regression/test_to_s.rb +670 -0
- data/test/regression/test_trackback.rb +135 -0
- data/test/regression/test_version.rb +9 -0
- data/test/regression/test_xml-stylesheet.rb +108 -0
- metadata +220 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
require "rss-testcase"
|
2
|
+
|
3
|
+
require "rss/1.0"
|
4
|
+
require "rss/2.0"
|
5
|
+
require "rss/syndication"
|
6
|
+
require "rss/image"
|
7
|
+
|
8
|
+
module RSS
|
9
|
+
class TestAccessor < TestCase
|
10
|
+
def test_date
|
11
|
+
channel = Rss::Channel.new
|
12
|
+
channel.pubDate = nil
|
13
|
+
assert_nil(channel.pubDate)
|
14
|
+
|
15
|
+
time = Time.now
|
16
|
+
channel.pubDate = time
|
17
|
+
assert_equal(time, channel.pubDate)
|
18
|
+
|
19
|
+
time = Time.parse(Time.now.rfc822)
|
20
|
+
channel.pubDate = time.rfc822
|
21
|
+
assert_equal(time, channel.pubDate)
|
22
|
+
|
23
|
+
time = Time.parse(Time.now.iso8601)
|
24
|
+
value = time.iso8601
|
25
|
+
assert_not_available_value("pubDate", value) do
|
26
|
+
channel.pubDate = value
|
27
|
+
end
|
28
|
+
|
29
|
+
channel.do_validate = false
|
30
|
+
time = Time.parse(Time.now.iso8601)
|
31
|
+
value = time.iso8601
|
32
|
+
channel.pubDate = value
|
33
|
+
assert_equal(time, channel.pubDate)
|
34
|
+
|
35
|
+
channel.pubDate = nil
|
36
|
+
assert_nil(channel.pubDate)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_integer
|
40
|
+
image_item = RDF::Item::ImageItem.new
|
41
|
+
|
42
|
+
image_item.width = nil
|
43
|
+
assert_nil(image_item.width)
|
44
|
+
|
45
|
+
width = 10
|
46
|
+
image_item.width = width
|
47
|
+
assert_equal(width, image_item.width)
|
48
|
+
|
49
|
+
width = 10.0
|
50
|
+
image_item.width = width
|
51
|
+
assert_equal(width, image_item.width)
|
52
|
+
|
53
|
+
width = "10"
|
54
|
+
image_item.width = width
|
55
|
+
assert_equal(width.to_i, image_item.width)
|
56
|
+
|
57
|
+
width = "10.0"
|
58
|
+
assert_not_available_value("image:width", width) do
|
59
|
+
image_item.width = width
|
60
|
+
end
|
61
|
+
|
62
|
+
image_item.do_validate = false
|
63
|
+
width = "10.0"
|
64
|
+
image_item.width = width
|
65
|
+
assert_equal(width.to_i, image_item.width)
|
66
|
+
|
67
|
+
image_item.width = nil
|
68
|
+
assert_nil(image_item.width)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_positive_integer
|
72
|
+
channel = RDF::Channel.new
|
73
|
+
|
74
|
+
channel.sy_updateFrequency = nil
|
75
|
+
assert_nil(channel.sy_updateFrequency)
|
76
|
+
|
77
|
+
freq = 10
|
78
|
+
channel.sy_updateFrequency = freq
|
79
|
+
assert_equal(freq, channel.sy_updateFrequency)
|
80
|
+
|
81
|
+
freq = 10.0
|
82
|
+
channel.sy_updateFrequency = freq
|
83
|
+
assert_equal(freq, channel.sy_updateFrequency)
|
84
|
+
|
85
|
+
freq = "10"
|
86
|
+
channel.sy_updateFrequency = freq
|
87
|
+
assert_equal(freq.to_i, channel.sy_updateFrequency)
|
88
|
+
|
89
|
+
freq = "10.0"
|
90
|
+
assert_not_available_value("sy:updateFrequency", freq) do
|
91
|
+
channel.sy_updateFrequency = freq
|
92
|
+
end
|
93
|
+
|
94
|
+
channel.do_validate = false
|
95
|
+
freq = "10.0"
|
96
|
+
channel.sy_updateFrequency = freq
|
97
|
+
assert_equal(freq.to_i, channel.sy_updateFrequency)
|
98
|
+
|
99
|
+
channel.sy_updateFrequency = nil
|
100
|
+
assert_nil(channel.sy_updateFrequency)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,681 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
|
3
|
+
require "rss-testcase"
|
4
|
+
|
5
|
+
require "rss/atom"
|
6
|
+
|
7
|
+
module RSS
|
8
|
+
class TestAtomCore < TestCase
|
9
|
+
def setup
|
10
|
+
@uri = "http://www.w3.org/2005/Atom"
|
11
|
+
@xhtml_uri = "http://www.w3.org/1999/xhtml"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_feed
|
15
|
+
version = "1.0"
|
16
|
+
encoding = "UTF-8"
|
17
|
+
standalone = false
|
18
|
+
|
19
|
+
feed = Atom::Feed.new(version, encoding, standalone)
|
20
|
+
assert_equal("", feed.to_s)
|
21
|
+
|
22
|
+
author = feed.class::Author.new
|
23
|
+
name = feed.class::Author::Name.new
|
24
|
+
name.content = "an author"
|
25
|
+
author.name = name
|
26
|
+
assert_not_equal("", author.to_s)
|
27
|
+
feed.authors << author
|
28
|
+
assert_equal("", feed.to_s)
|
29
|
+
|
30
|
+
id = feed.class::Id.new
|
31
|
+
id.content = "http://example.com/atom.xml"
|
32
|
+
assert_not_equal("", id.to_s)
|
33
|
+
feed.id = id
|
34
|
+
assert_equal("", feed.to_s)
|
35
|
+
|
36
|
+
title = feed.class::Title.new
|
37
|
+
title.content = "a title"
|
38
|
+
assert_not_equal("", title.to_s)
|
39
|
+
feed.title = title
|
40
|
+
assert_equal("", feed.to_s)
|
41
|
+
|
42
|
+
updated = feed.class::Updated.new
|
43
|
+
updated.content = Time.now
|
44
|
+
assert_not_equal("", updated.to_s)
|
45
|
+
feed.updated = updated
|
46
|
+
assert_not_equal("", feed.to_s)
|
47
|
+
|
48
|
+
|
49
|
+
feed.authors.clear
|
50
|
+
assert_equal("", feed.to_s)
|
51
|
+
entry = Atom::Feed::Entry.new
|
52
|
+
setup_entry(entry)
|
53
|
+
assert_not_equal("", entry.to_s)
|
54
|
+
|
55
|
+
author = entry.authors.first
|
56
|
+
entry.authors.clear
|
57
|
+
assert_equal("", entry.to_s)
|
58
|
+
entry.parent = feed
|
59
|
+
assert_equal("", entry.to_s)
|
60
|
+
feed.authors << author
|
61
|
+
assert_not_equal("", entry.to_s)
|
62
|
+
feed.authors.clear
|
63
|
+
feed.entries << entry
|
64
|
+
assert_equal("", feed.to_s)
|
65
|
+
entry.authors << author
|
66
|
+
assert_not_equal("", entry.to_s)
|
67
|
+
assert_not_equal("", feed.to_s)
|
68
|
+
|
69
|
+
doc = REXML::Document.new(feed.to_s)
|
70
|
+
xmldecl = doc.xml_decl
|
71
|
+
|
72
|
+
assert_equal(version, xmldecl.version)
|
73
|
+
assert_equal(encoding, xmldecl.encoding.to_s)
|
74
|
+
assert_equal(standalone, !xmldecl.standalone.nil?)
|
75
|
+
|
76
|
+
assert_equal(@uri, doc.root.namespace)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_entry
|
80
|
+
version = "1.0"
|
81
|
+
encoding = "UTF-8"
|
82
|
+
standalone = false
|
83
|
+
|
84
|
+
entry = Atom::Entry.new(version, encoding, standalone)
|
85
|
+
setup_entry(entry)
|
86
|
+
|
87
|
+
author = entry.authors.first
|
88
|
+
entry.authors.clear
|
89
|
+
assert_equal("", entry.to_s)
|
90
|
+
source = Atom::Entry::Source.new
|
91
|
+
source.authors << author
|
92
|
+
entry.source = source
|
93
|
+
assert_not_equal("", entry.to_s)
|
94
|
+
|
95
|
+
doc = REXML::Document.new(entry.to_s)
|
96
|
+
xmldecl = doc.xml_decl
|
97
|
+
|
98
|
+
assert_equal(version, xmldecl.version)
|
99
|
+
assert_equal(encoding, xmldecl.encoding.to_s)
|
100
|
+
assert_equal(standalone, !xmldecl.standalone.nil?)
|
101
|
+
|
102
|
+
assert_equal(@uri, doc.root.namespace)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_not_displayed_xml_stylesheets
|
106
|
+
feed = Atom::Feed.new
|
107
|
+
plain_feed = feed.to_s
|
108
|
+
3.times do
|
109
|
+
feed.xml_stylesheets.push(XMLStyleSheet.new)
|
110
|
+
assert_equal(plain_feed, feed.to_s)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_atom_author
|
115
|
+
assert_atom_person_to_s(Atom::Feed::Author)
|
116
|
+
assert_atom_person_to_s(Atom::Feed::Entry::Author)
|
117
|
+
assert_atom_person_to_s(Atom::Entry::Author)
|
118
|
+
assert_atom_person_to_s(Atom::Feed::Entry::Source::Author)
|
119
|
+
assert_atom_person_to_s(Atom::Entry::Source::Author)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_atom_category
|
123
|
+
assert_atom_category_to_s(Atom::Feed::Category)
|
124
|
+
assert_atom_category_to_s(Atom::Feed::Entry::Category)
|
125
|
+
assert_atom_category_to_s(Atom::Entry::Category)
|
126
|
+
assert_atom_category_to_s(Atom::Feed::Entry::Source::Category)
|
127
|
+
assert_atom_category_to_s(Atom::Entry::Source::Category)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_atom_contributor
|
131
|
+
assert_atom_person_to_s(Atom::Feed::Contributor)
|
132
|
+
assert_atom_person_to_s(Atom::Feed::Entry::Contributor)
|
133
|
+
assert_atom_person_to_s(Atom::Entry::Contributor)
|
134
|
+
assert_atom_person_to_s(Atom::Feed::Entry::Source::Contributor)
|
135
|
+
assert_atom_person_to_s(Atom::Entry::Source::Contributor)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_atom_generator
|
139
|
+
assert_atom_generator_to_s(Atom::Feed::Generator)
|
140
|
+
assert_atom_generator_to_s(Atom::Feed::Entry::Source::Generator)
|
141
|
+
assert_atom_generator_to_s(Atom::Entry::Source::Generator)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_atom_icon
|
145
|
+
assert_atom_icon_to_s(Atom::Feed::Icon)
|
146
|
+
assert_atom_icon_to_s(Atom::Feed::Entry::Source::Icon)
|
147
|
+
assert_atom_icon_to_s(Atom::Entry::Source::Icon)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_atom_id
|
151
|
+
assert_atom_id_to_s(Atom::Feed::Id)
|
152
|
+
assert_atom_id_to_s(Atom::Feed::Entry::Id)
|
153
|
+
assert_atom_id_to_s(Atom::Entry::Id)
|
154
|
+
assert_atom_id_to_s(Atom::Feed::Entry::Source::Id)
|
155
|
+
assert_atom_id_to_s(Atom::Entry::Source::Id)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_atom_link
|
159
|
+
assert_atom_link_to_s(Atom::Feed::Link)
|
160
|
+
assert_atom_link_to_s(Atom::Feed::Entry::Link)
|
161
|
+
assert_atom_link_to_s(Atom::Entry::Link)
|
162
|
+
assert_atom_link_to_s(Atom::Feed::Entry::Source::Link)
|
163
|
+
assert_atom_link_to_s(Atom::Entry::Source::Link)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_atom_logo
|
167
|
+
assert_atom_logo_to_s(Atom::Feed::Logo)
|
168
|
+
assert_atom_logo_to_s(Atom::Feed::Entry::Source::Logo)
|
169
|
+
assert_atom_logo_to_s(Atom::Entry::Source::Logo)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_atom_rights
|
173
|
+
assert_atom_text_construct_to_s(Atom::Feed::Rights)
|
174
|
+
assert_atom_text_construct_to_s(Atom::Feed::Entry::Rights)
|
175
|
+
assert_atom_text_construct_to_s(Atom::Entry::Rights)
|
176
|
+
assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Rights)
|
177
|
+
assert_atom_text_construct_to_s(Atom::Entry::Source::Rights)
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_atom_subtitle
|
181
|
+
assert_atom_text_construct_to_s(Atom::Feed::Subtitle)
|
182
|
+
assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Subtitle)
|
183
|
+
assert_atom_text_construct_to_s(Atom::Entry::Source::Subtitle)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_atom_title
|
187
|
+
assert_atom_text_construct_to_s(Atom::Feed::Title)
|
188
|
+
assert_atom_text_construct_to_s(Atom::Feed::Entry::Title)
|
189
|
+
assert_atom_text_construct_to_s(Atom::Entry::Title)
|
190
|
+
assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Title)
|
191
|
+
assert_atom_text_construct_to_s(Atom::Entry::Source::Title)
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_atom_updated
|
195
|
+
assert_atom_date_construct_to_s(Atom::Feed::Updated)
|
196
|
+
assert_atom_date_construct_to_s(Atom::Feed::Entry::Updated)
|
197
|
+
assert_atom_date_construct_to_s(Atom::Entry::Updated)
|
198
|
+
assert_atom_date_construct_to_s(Atom::Feed::Entry::Source::Updated)
|
199
|
+
assert_atom_date_construct_to_s(Atom::Entry::Source::Updated)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_atom_content
|
203
|
+
assert_atom_content_to_s(Atom::Feed::Entry::Content)
|
204
|
+
assert_atom_content_to_s(Atom::Entry::Content)
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_atom_published
|
208
|
+
assert_atom_date_construct_to_s(Atom::Feed::Entry::Published)
|
209
|
+
assert_atom_date_construct_to_s(Atom::Entry::Published)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_atom_summary
|
213
|
+
assert_atom_text_construct_to_s(Atom::Feed::Entry::Summary)
|
214
|
+
assert_atom_text_construct_to_s(Atom::Entry::Summary)
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
def test_to_xml(with_convenience_way=true)
|
219
|
+
atom = RSS::Parser.parse(make_feed)
|
220
|
+
assert_equal(atom.to_s, atom.to_xml)
|
221
|
+
assert_equal(atom.to_s, atom.to_xml("atom"))
|
222
|
+
assert_equal(atom.to_s, atom.to_xml("atom1.0"))
|
223
|
+
assert_equal(atom.to_s, atom.to_xml("atom1.0:feed"))
|
224
|
+
assert_equal(atom.to_s, atom.to_xml("atom:feed"))
|
225
|
+
|
226
|
+
rss09_xml = atom.to_xml("0.91") do |maker|
|
227
|
+
maker.channel.language = "en-us"
|
228
|
+
maker.channel.link = "http://example.com/"
|
229
|
+
if with_convenience_way
|
230
|
+
maker.channel.description = atom.title.content
|
231
|
+
else
|
232
|
+
maker.channel.description {|d| d.content = atom.title.content}
|
233
|
+
end
|
234
|
+
|
235
|
+
maker.image.url = "http://example.com/logo.png"
|
236
|
+
maker.image.title = "Logo"
|
237
|
+
end
|
238
|
+
rss09 = RSS::Parser.parse(rss09_xml)
|
239
|
+
assert_equal(["rss", "0.91", nil], rss09.feed_info)
|
240
|
+
|
241
|
+
rss20_xml = atom.to_xml("2.0") do |maker|
|
242
|
+
maker.channel.link = "http://example.com/"
|
243
|
+
if with_convenience_way
|
244
|
+
maker.channel.description = atom.title.content
|
245
|
+
else
|
246
|
+
maker.channel.description {|d| d.content = atom.title.content}
|
247
|
+
end
|
248
|
+
end
|
249
|
+
rss20 = RSS::Parser.parse(rss20_xml)
|
250
|
+
assert_equal("2.0", rss20.rss_version)
|
251
|
+
assert_equal(["rss", "2.0", nil], rss20.feed_info)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_to_xml_with_new_api_since_018
|
255
|
+
test_to_xml(false)
|
256
|
+
end
|
257
|
+
|
258
|
+
private
|
259
|
+
def setup_entry(entry)
|
260
|
+
_wrap_assertion do
|
261
|
+
assert_equal("", entry.to_s)
|
262
|
+
|
263
|
+
author = entry.class::Author.new
|
264
|
+
name = entry.class::Author::Name.new
|
265
|
+
name.content = "an author"
|
266
|
+
author.name = name
|
267
|
+
assert_not_equal("", author.to_s)
|
268
|
+
entry.authors << author
|
269
|
+
assert_equal("", entry.to_s)
|
270
|
+
|
271
|
+
id = entry.class::Id.new
|
272
|
+
id.content = "http://example.com/atom.xml"
|
273
|
+
assert_not_equal("", id.to_s)
|
274
|
+
entry.id = id
|
275
|
+
assert_equal("", entry.to_s)
|
276
|
+
|
277
|
+
title = entry.class::Title.new
|
278
|
+
title.content = "a title"
|
279
|
+
assert_not_equal("", title.to_s)
|
280
|
+
entry.title = title
|
281
|
+
assert_equal("", entry.to_s)
|
282
|
+
|
283
|
+
updated = entry.class::Updated.new
|
284
|
+
updated.content = Time.now
|
285
|
+
assert_not_equal("", updated.to_s)
|
286
|
+
entry.updated = updated
|
287
|
+
assert_not_equal("", entry.to_s)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
def assert_atom_person_to_s(target_class)
|
293
|
+
_wrap_assertion do
|
294
|
+
name = "A person"
|
295
|
+
uri = "http://example.com/person/"
|
296
|
+
email = "person@example.com"
|
297
|
+
|
298
|
+
target = target_class.new
|
299
|
+
assert_equal("", target.to_s)
|
300
|
+
|
301
|
+
target = target_class.new
|
302
|
+
person_name = target_class::Name.new
|
303
|
+
person_name.content = name
|
304
|
+
target.name = person_name
|
305
|
+
xml_target = REXML::Document.new(target.to_s).root
|
306
|
+
assert_equal(["name"], xml_target.elements.collect {|e| e.name})
|
307
|
+
assert_equal([name], xml_target.elements.collect {|e| e.text})
|
308
|
+
|
309
|
+
person_uri = target_class::Uri.new
|
310
|
+
person_uri.content = uri
|
311
|
+
target.uri = person_uri
|
312
|
+
xml_target = REXML::Document.new(target.to_s).root
|
313
|
+
assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
|
314
|
+
assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
|
315
|
+
|
316
|
+
person_email = target_class::Email.new
|
317
|
+
person_email.content = email
|
318
|
+
target.email = person_email
|
319
|
+
xml_target = REXML::Document.new(target.to_s).root
|
320
|
+
assert_equal(["name", "uri", "email"],
|
321
|
+
xml_target.elements.collect {|e| e.name})
|
322
|
+
assert_equal([name, uri, email],
|
323
|
+
xml_target.elements.collect {|e| e.text})
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def assert_atom_category_to_s(target_class)
|
328
|
+
_wrap_assertion do
|
329
|
+
term = "music"
|
330
|
+
scheme = "http://example.com/music"
|
331
|
+
label = "Music"
|
332
|
+
|
333
|
+
category = target_class.new
|
334
|
+
assert_equal("", category.to_s)
|
335
|
+
|
336
|
+
category = target_class.new
|
337
|
+
category.scheme = scheme
|
338
|
+
assert_equal("", category.to_s)
|
339
|
+
|
340
|
+
category = target_class.new
|
341
|
+
category.label = label
|
342
|
+
assert_equal("", category.to_s)
|
343
|
+
|
344
|
+
category = target_class.new
|
345
|
+
category.scheme = scheme
|
346
|
+
category.label = label
|
347
|
+
assert_equal("", category.to_s)
|
348
|
+
|
349
|
+
category = target_class.new
|
350
|
+
category.term = term
|
351
|
+
xml = REXML::Document.new(category.to_s).root
|
352
|
+
assert_rexml_element([], {"term" => term}, nil, xml)
|
353
|
+
|
354
|
+
category = target_class.new
|
355
|
+
category.term = term
|
356
|
+
category.scheme = scheme
|
357
|
+
xml = REXML::Document.new(category.to_s).root
|
358
|
+
assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
|
359
|
+
|
360
|
+
category = target_class.new
|
361
|
+
category.term = term
|
362
|
+
category.label = label
|
363
|
+
xml = REXML::Document.new(category.to_s).root
|
364
|
+
assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
|
365
|
+
|
366
|
+
category = target_class.new
|
367
|
+
category.term = term
|
368
|
+
category.scheme = scheme
|
369
|
+
category.label = label
|
370
|
+
xml = REXML::Document.new(category.to_s).root
|
371
|
+
attrs = {"term" => term, "scheme" => scheme, "label" => label}
|
372
|
+
assert_rexml_element([], attrs, nil, xml)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def assert_atom_generator_to_s(target_class)
|
377
|
+
_wrap_assertion do
|
378
|
+
content = "Feed generator"
|
379
|
+
uri = "http://example.com/generator"
|
380
|
+
version = "0.0.1"
|
381
|
+
|
382
|
+
generator = target_class.new
|
383
|
+
assert_equal("", generator.to_s)
|
384
|
+
|
385
|
+
generator = target_class.new
|
386
|
+
generator.uri = uri
|
387
|
+
assert_equal("", generator.to_s)
|
388
|
+
|
389
|
+
generator = target_class.new
|
390
|
+
generator.version = version
|
391
|
+
assert_equal("", generator.to_s)
|
392
|
+
|
393
|
+
generator = target_class.new
|
394
|
+
generator.uri = uri
|
395
|
+
generator.version = version
|
396
|
+
assert_equal("", generator.to_s)
|
397
|
+
|
398
|
+
generator = target_class.new
|
399
|
+
generator.content = content
|
400
|
+
xml = REXML::Document.new(generator.to_s).root
|
401
|
+
assert_rexml_element([], {}, content, xml)
|
402
|
+
|
403
|
+
generator = target_class.new
|
404
|
+
generator.content = content
|
405
|
+
generator.uri = uri
|
406
|
+
xml = REXML::Document.new(generator.to_s).root
|
407
|
+
assert_rexml_element([], {"uri" => uri}, content, xml)
|
408
|
+
|
409
|
+
generator = target_class.new
|
410
|
+
generator.content = content
|
411
|
+
generator.version = version
|
412
|
+
xml = REXML::Document.new(generator.to_s).root
|
413
|
+
assert_rexml_element([], {"version" => version}, content, xml)
|
414
|
+
|
415
|
+
generator = target_class.new
|
416
|
+
generator.content = content
|
417
|
+
generator.uri = uri
|
418
|
+
generator.version = version
|
419
|
+
xml = REXML::Document.new(generator.to_s).root
|
420
|
+
assert_rexml_element([], {"uri" => uri, "version" => version},
|
421
|
+
content, xml)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
def assert_atom_icon_to_s(target_class)
|
426
|
+
_wrap_assertion do
|
427
|
+
content = "http://example.com/icon.png"
|
428
|
+
|
429
|
+
icon = target_class.new
|
430
|
+
assert_equal("", icon.to_s)
|
431
|
+
|
432
|
+
icon = target_class.new
|
433
|
+
icon.content = content
|
434
|
+
xml = REXML::Document.new(icon.to_s).root
|
435
|
+
assert_rexml_element([], {}, content, xml)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
def assert_atom_id_to_s(target_class)
|
440
|
+
_wrap_assertion do
|
441
|
+
content = "http://example.com/1"
|
442
|
+
|
443
|
+
id = target_class.new
|
444
|
+
assert_equal("", id.to_s)
|
445
|
+
|
446
|
+
id = target_class.new
|
447
|
+
id.content = content
|
448
|
+
xml = REXML::Document.new(id.to_s).root
|
449
|
+
assert_rexml_element([], {}, content, xml)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
def assert_atom_link_to_s(target_class)
|
454
|
+
_wrap_assertion do
|
455
|
+
href = "http://example.com/atom.xml"
|
456
|
+
rel = "self"
|
457
|
+
type = "application/atom+xml"
|
458
|
+
hreflang = "ja"
|
459
|
+
title = "Atom Feed"
|
460
|
+
length = "801"
|
461
|
+
|
462
|
+
link = target_class.new
|
463
|
+
assert_equal("", link.to_s)
|
464
|
+
|
465
|
+
link = target_class.new
|
466
|
+
link.href = href
|
467
|
+
xml = REXML::Document.new(link.to_s).root
|
468
|
+
assert_rexml_element([], {"href" => href}, nil, xml)
|
469
|
+
|
470
|
+
optional_arguments = %w(rel type hreflang title length)
|
471
|
+
optional_arguments.each do |name|
|
472
|
+
rest = optional_arguments.reject {|x| x == name}
|
473
|
+
|
474
|
+
link = target_class.new
|
475
|
+
link.__send__("#{name}=", eval(name))
|
476
|
+
assert_equal("", link.to_s)
|
477
|
+
|
478
|
+
rest.each do |n|
|
479
|
+
link.__send__("#{n}=", eval(n))
|
480
|
+
assert_equal("", link.to_s)
|
481
|
+
end
|
482
|
+
|
483
|
+
link = target_class.new
|
484
|
+
link.href = href
|
485
|
+
link.__send__("#{name}=", eval(name))
|
486
|
+
attrs = [["href", href], [name, eval(name)]]
|
487
|
+
xml = REXML::Document.new(link.to_s).root
|
488
|
+
assert_rexml_element([], attrs, nil, xml)
|
489
|
+
|
490
|
+
rest.each do |n|
|
491
|
+
link.__send__("#{n}=", eval(n))
|
492
|
+
attrs << [n, eval(n)]
|
493
|
+
xml = REXML::Document.new(link.to_s).root
|
494
|
+
assert_rexml_element([], attrs, nil, xml)
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
def assert_atom_logo_to_s(target_class)
|
501
|
+
_wrap_assertion do
|
502
|
+
content = "http://example.com/logo.png"
|
503
|
+
|
504
|
+
logo = target_class.new
|
505
|
+
assert_equal("", logo.to_s)
|
506
|
+
|
507
|
+
logo = target_class.new
|
508
|
+
logo.content = content
|
509
|
+
xml = REXML::Document.new(logo.to_s).root
|
510
|
+
assert_rexml_element([], {}, content, xml)
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
def assert_atom_text_construct_to_s(target_class)
|
515
|
+
_wrap_assertion do
|
516
|
+
text_content = "plain text"
|
517
|
+
html_content = "<em>#{text_content}</em>"
|
518
|
+
xhtml_uri = "http://www.w3.org/1999/xhtml"
|
519
|
+
xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
|
520
|
+
xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
|
521
|
+
{"xmlns" => xhtml_uri},
|
522
|
+
[xhtml_em])
|
523
|
+
|
524
|
+
text = target_class.new
|
525
|
+
assert_equal("", text.to_s)
|
526
|
+
|
527
|
+
text = target_class.new
|
528
|
+
text.type = "text"
|
529
|
+
assert_equal("", text.to_s)
|
530
|
+
|
531
|
+
text = target_class.new
|
532
|
+
text.content = text_content
|
533
|
+
xml = REXML::Document.new(text.to_s).root
|
534
|
+
assert_rexml_element([], {}, text_content, xml)
|
535
|
+
|
536
|
+
text = target_class.new
|
537
|
+
text.type = "text"
|
538
|
+
text.content = text_content
|
539
|
+
xml = REXML::Document.new(text.to_s).root
|
540
|
+
assert_rexml_element([], {"type" => "text"}, text_content, xml)
|
541
|
+
|
542
|
+
text = target_class.new
|
543
|
+
text.type = "html"
|
544
|
+
text.content = html_content
|
545
|
+
xml = REXML::Document.new(text.to_s).root
|
546
|
+
assert_rexml_element([], {"type" => "html"}, html_content, xml)
|
547
|
+
|
548
|
+
text = target_class.new
|
549
|
+
text.type = "xhtml"
|
550
|
+
text.content = xhtml_content
|
551
|
+
assert_equal("", text.to_s)
|
552
|
+
|
553
|
+
text = target_class.new
|
554
|
+
text.type = "xhtml"
|
555
|
+
text.__send__(target_class.xml_setter, xhtml_content)
|
556
|
+
xml = REXML::Document.new(text.to_s).root
|
557
|
+
assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
|
558
|
+
nil, xml)
|
559
|
+
assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
|
560
|
+
assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
|
561
|
+
|
562
|
+
text = target_class.new
|
563
|
+
text.type = "xhtml"
|
564
|
+
text.__send__(target_class.xml_setter, xhtml_em)
|
565
|
+
xml = REXML::Document.new(text.to_s).root
|
566
|
+
assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
|
567
|
+
nil, xml)
|
568
|
+
assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
|
569
|
+
assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
def assert_atom_date_construct_to_s(target_class)
|
574
|
+
_wrap_assertion do
|
575
|
+
date = target_class.new
|
576
|
+
assert_equal("", date.to_s)
|
577
|
+
|
578
|
+
[
|
579
|
+
"2003-12-13T18:30:02Z",
|
580
|
+
"2003-12-13T18:30:02.25Z",
|
581
|
+
"2003-12-13T18:30:02+01:00",
|
582
|
+
"2003-12-13T18:30:02.25+01:00",
|
583
|
+
].each do |content|
|
584
|
+
date = target_class.new
|
585
|
+
date.content = content
|
586
|
+
xml = REXML::Document.new(date.to_s).root
|
587
|
+
assert_rexml_element([], {}, content, xml, :time)
|
588
|
+
|
589
|
+
date = target_class.new
|
590
|
+
date.content = Time.parse(content)
|
591
|
+
xml = REXML::Document.new(date.to_s).root
|
592
|
+
assert_rexml_element([], {}, content, xml, :time)
|
593
|
+
end
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
def assert_atom_content_to_s(target_class)
|
598
|
+
_wrap_assertion do
|
599
|
+
assert_atom_text_construct_to_s(target_class)
|
600
|
+
assert_atom_content_inline_other_xml_to_s(target_class)
|
601
|
+
assert_atom_content_inline_other_text_to_s(target_class)
|
602
|
+
assert_atom_content_inline_other_base64_to_s(target_class)
|
603
|
+
assert_atom_content_out_of_line_to_s(target_class)
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
def assert_atom_content_inline_other_xml_to_s(target_class)
|
608
|
+
_wrap_assertion do
|
609
|
+
content = target_class.new
|
610
|
+
content.type = "text/xml"
|
611
|
+
assert_equal("", content.to_s)
|
612
|
+
|
613
|
+
content = target_class.new
|
614
|
+
content.type = "text/xml"
|
615
|
+
content.xml = RSS::XML::Element.new("em")
|
616
|
+
xml = REXML::Document.new(content.to_s).root
|
617
|
+
assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
def assert_atom_content_inline_other_text_to_s(target_class)
|
622
|
+
_wrap_assertion do
|
623
|
+
content = target_class.new
|
624
|
+
content.type = "text/plain"
|
625
|
+
assert_equal("", content.to_s)
|
626
|
+
|
627
|
+
content = target_class.new
|
628
|
+
content.type = "text/plain"
|
629
|
+
content.xml = RSS::XML::Element.new("em")
|
630
|
+
assert_equal("", content.to_s)
|
631
|
+
|
632
|
+
content = target_class.new
|
633
|
+
content.type = "text/plain"
|
634
|
+
content.content = "content"
|
635
|
+
xml = REXML::Document.new(content.to_s).root
|
636
|
+
assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
def assert_atom_content_inline_other_base64_to_s(target_class)
|
641
|
+
_wrap_assertion do
|
642
|
+
type = "image/png"
|
643
|
+
png_file = File.join(File.dirname(__FILE__), "dot.png")
|
644
|
+
original_content = File.open(png_file, "rb") do |file|
|
645
|
+
file.read.force_encoding("binary")
|
646
|
+
end
|
647
|
+
|
648
|
+
content = target_class.new
|
649
|
+
content.type = type
|
650
|
+
content.content = original_content
|
651
|
+
xml = REXML::Document.new(content.to_s).root
|
652
|
+
assert_rexml_element([], {"type" => type},
|
653
|
+
[original_content].pack("m").delete("\n"),
|
654
|
+
xml)
|
655
|
+
end
|
656
|
+
end
|
657
|
+
|
658
|
+
def assert_atom_content_out_of_line_to_s(target_class)
|
659
|
+
_wrap_assertion do
|
660
|
+
type = "application/zip"
|
661
|
+
src = "http://example.com/xxx.zip"
|
662
|
+
|
663
|
+
content = target_class.new
|
664
|
+
assert(!content.out_of_line?)
|
665
|
+
content.src = src
|
666
|
+
assert(content.out_of_line?)
|
667
|
+
xml = REXML::Document.new(content.to_s).root
|
668
|
+
assert_rexml_element([], {"src" => src}, nil, xml)
|
669
|
+
|
670
|
+
content = target_class.new
|
671
|
+
assert(!content.out_of_line?)
|
672
|
+
content.type = type
|
673
|
+
assert(!content.out_of_line?)
|
674
|
+
content.src = src
|
675
|
+
assert(content.out_of_line?)
|
676
|
+
xml = REXML::Document.new(content.to_s).root
|
677
|
+
assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
|
678
|
+
end
|
679
|
+
end
|
680
|
+
end
|
681
|
+
end
|