1
require "rexml/document"
9
require "rss/dublincore"
10
require "rss/syndication"
11
require "rss/trackback"
14
class TestToS < TestCase
17
@image_url = "http://example.com/foo.png"
18
@textinput_link = "http://example.com/search.cgi"
20
"http://example.com/1",
21
"http://example.com/2",
24
setup_xml_declaration_info
25
setup_xml_stylesheet_infos
31
setup_dublin_core_info
32
setup_syndication_info
38
rss = RSS::Maker.make("1.0") do |maker|
42
assert_xml_declaration(@version, @encoding, @standalone, rss)
43
assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
44
assert_channel10(@channel_info, rss.channel)
45
assert_items10(@item_infos, rss.items)
46
rss.items.each do |item|
47
assert_trackback(@trackback_info, item)
49
assert_image10(@image_info, rss.image)
50
assert_textinput10(@textinput_info, rss.textinput)
52
rss = RSS::Parser.parse(rss.to_s)
54
assert_xml_declaration(@version, @encoding, @standalone, rss)
55
assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
56
assert_channel10(@channel_info, rss.channel)
57
assert_items10(@item_infos, rss.items)
58
assert_image10(@image_info, rss.image)
59
assert_textinput10(@textinput_info, rss.textinput)
63
rss = RSS::Maker.make("0.91") do |maker|
67
assert_xml_declaration(@version, @encoding, @standalone, rss)
68
assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
69
assert_channel09(@channel_info, rss.channel)
70
assert_items09(@item_infos, rss.items)
71
assert_image09(@image_info, rss.image)
72
assert_textinput09(@textinput_info, rss.textinput)
74
rss = RSS::Parser.parse(rss.to_s)
76
assert_xml_declaration(@version, @encoding, @standalone, rss)
77
assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
78
assert_channel09(@channel_info, rss.channel)
79
assert_items09(@item_infos, rss.items)
80
assert_image09(@image_info, rss.image)
81
assert_textinput09(@textinput_info, rss.textinput)
85
rss = RSS::Maker.make("2.0") do |maker|
89
assert_xml_declaration(@version, @encoding, @standalone, rss)
90
assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
91
assert_channel20(@channel_info, rss.channel)
92
assert_items20(@item_infos, rss.items)
93
assert_image20(@image_info, rss.image)
94
assert_textinput20(@textinput_info, rss.textinput)
96
rss = RSS::Parser.parse(rss.to_s)
98
assert_xml_declaration(@version, @encoding, @standalone, rss)
99
assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
100
assert_channel20(@channel_info, rss.channel)
101
assert_items20(@item_infos, rss.items)
102
assert_image20(@image_info, rss.image)
103
assert_textinput20(@textinput_info, rss.textinput)
107
def setup_xml_declaration_info
113
def setup_xml_stylesheet_infos
117
"type" => "text/xsl",
124
"type" => "text/css",
132
def setup_channel_info
134
"about" => "http://example.com/index.rdf",
135
"title" => "Sample RSS",
136
"link" => "http://example.com/",
137
"description" => "Sample\n\n\n\n\nSite",
139
"copyright" => "FDL",
140
"managingEditor" => "foo@example.com",
141
"webMaster" => "webmaster@example.com",
142
"rating" => '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))',
143
"docs" => "http://backend.userland.com/rss091",
153
"lastBuildDate" => Time.now - 3600,
154
"generator" => "RSS Maker",
157
"domain" => "rpc.sys.com",
160
"registerProcedure" => "myCloud.rssPleaseNotify",
161
"protocol" => "xml-rpc",
164
"domain" => "http://example.com/misc/",
169
"resource" => @image_url,
173
"resource" => @textinput_link,
176
"items" => @item_links.collect{|link| {"resource" => link}},
183
"title" => "Sample item1",
184
"link" => @item_links[0],
185
"description" => "Sample description1",
186
"date" => Time.now - 3600,
187
"author" => "foo@example.com",
188
"comments" => "http://example.com/1/comments",
190
"isPermaLink" => "true",
191
"content" => "http://example.com/1",
194
"url" => "http://example.com/1.mp3",
196
"type" => "audio/mpeg",
199
"url" => "http:/example.com/",
200
"content" => "Sample site",
203
"domain" => "http://example.com/misc/",
209
"title" => "Sample item2",
210
"link" => @item_links[1],
211
"description" => "Sample description2",
212
"date" => Time.now - 7200,
213
"author" => "foo@example.com",
214
"comments" => "http://example.com/2/comments",
216
"isPermaLink" => "false",
217
"content" => "http://example.com/2",
220
"url" => "http://example.com/2.mp3",
222
"type" => "audio/mpeg",
225
"url" => "http:/example.com/",
226
"content" => "Sample site",
229
"domain" => "http://example.com/misc/",
238
"title" => "Sample image",
242
"description" => "Sample",
246
def setup_textinput_info
248
"title" => "Sample textinput",
249
"description" => "Search",
251
"link" => @textinput_link,
255
def setup_dublin_core_info
257
"title" => "DC title",
258
"description" => "DC desc",
259
"creator" => "DC creator",
260
"subject" => "DC subject",
261
"publisher" => "DC publisher",
262
"contributor" => "DC contributor",
264
"format" => "DC format",
265
"identifier" => "DC identifier",
266
"source" => "DC source",
268
"relation" => "DC relation",
269
"coverage" => "DC coverage",
270
"rights" => "DC rights",
271
"date" => Time.now - 60,
275
def setup_syndication_info
277
"updatePeriod" => "hourly",
278
"updateFrequency" => "2",
279
"updateBase" => Time.now - 3600,
283
def setup_content_info
285
"encoded" => "<p>p</p>",
289
def setup_trackback_info
291
"ping" => "http://example.com/tb.cgi?tb_id=XXX",
293
"http://example.net/tb.cgi?tb_id=YYY",
294
"http://example.org/tb.cgi?tb_id=ZZZ",
300
def setup_full(maker)
301
setup_xml_declaration(maker)
302
setup_xml_stylesheets(maker)
306
setup_textinput(maker)
309
def setup_xml_declaration(maker)
310
%w(version encoding standalone).each do |name|
311
maker.__send__("#{name}=", instance_eval("@#{name}"))
315
def setup_xml_stylesheets(maker)
316
@xs_infos.each do |info|
317
xs = maker.xml_stylesheets.new_xml_stylesheet
318
info.each do |name, value|
319
xs.__send__("#{name}=", value)
324
def setup_channel(maker)
325
channel = maker.channel
328
%w(about title link description language copyright
329
managingEditor webMaster rating docs date
330
lastBuildDate generator ttl).each do |name|
331
channel.__send__("#{name}=", info[name])
334
skipDays = channel.skipDays
335
info["skipDays"].each do |day|
336
new_day = skipDays.new_day
337
new_day.content = day
340
skipHours = channel.skipHours
341
info["skipHours"].each do |hour|
342
new_hour = skipHours.new_hour
343
new_hour.content = hour
346
cloud = channel.cloud
347
%w(domain port path registerProcedure protocol).each do |name|
348
cloud.__send__("#{name}=", info["cloud"][name])
351
category = channel.categories.new_category
352
%w(domain content).each do |name|
353
category.__send__("#{name}=", info["category"][name])
357
def setup_image(maker)
361
%w(title url width height description).each do |name|
362
image.__send__("#{name}=", info[name])
366
def setup_items(maker)
369
@item_infos.each do |info|
370
item = items.new_item
371
%w(title link description date author comments).each do |name|
372
item.__send__("#{name}=", info[name])
376
%w(isPermaLink content).each do |name|
377
guid.__send__("#{name}=", info["guid"][name])
380
enclosure = item.enclosure
381
%w(url length type).each do |name|
382
enclosure.__send__("#{name}=", info["enclosure"][name])
386
%w(url content).each do |name|
387
source.__send__("#{name}=", info["source"][name])
390
category = item.categories.new_category
391
%w(domain content).each do |name|
392
category.__send__("#{name}=", info["category"][name])
395
setup_trackback(item)
399
def setup_textinput(maker)
400
textinput = maker.textinput
401
info = @textinput_info
403
%w(title description name link).each do |name|
404
textinput.__send__("#{name}=", info[name])
408
def setup_content(target)
410
%w(encoded).each do |name|
411
target.__send__("#{prefix}_#{name}=", @content_info[name])
415
def setup_dublin_core(target)
417
%w(title description creator subject publisher
418
contributor type format identifier source language
419
relation coverage rights).each do |name|
420
target.__send__("#{prefix}_#{name}=", @dc_info[name])
424
def setup_syndicate(target)
426
%w(updatePeriod updateFrequency updateBase).each do |name|
427
target.__send__("#{prefix}_#{name}=", @sy_info[name])
431
def setup_trackback(target)
432
target.trackback_ping = @trackback_info["ping"]
433
@trackback_info["abouts"].each do |about|
434
new_about = target.trackback_abouts.new_about
435
new_about.value = about