1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
require_relative "rss-testcase"
require "rss/maker"
module RSS
class TestMakerAtomFeed < TestCase
def test_supported?
assert(RSS::Maker.supported?("atom"))
assert(RSS::Maker.supported?("atom:feed"))
assert(RSS::Maker.supported?("atom1.0"))
assert(RSS::Maker.supported?("atom1.0:feed"))
assert(!RSS::Maker.supported?("atom2.0"))
assert(!RSS::Maker.supported?("atom2.0:feed"))
end
def test_find_class
assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom"])
assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom:feed"])
assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0"])
assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0:feed"])
end
def test_root_element
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
end
assert_equal(["atom", "1.0", "feed"], feed.feed_info)
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.encoding = "EUC-JP"
end
assert_equal(["atom", "1.0", "feed"], feed.feed_info)
assert_equal("EUC-JP", feed.encoding)
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.standalone = "yes"
end
assert_equal(["atom", "1.0", "feed"], feed.feed_info)
assert_equal("yes", feed.standalone)
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.encoding = "EUC-JP"
maker.standalone = "yes"
end
assert_equal(["atom", "1.0", "feed"], feed.feed_info)
assert_equal("EUC-JP", feed.encoding)
assert_equal("yes", feed.standalone)
end
def test_invalid_feed
assert_not_set_error("maker.channel", %w(id title author updated)) do
Maker.make("atom") do |maker|
end
end
assert_not_set_error("maker.channel", %w(id title updated)) do
Maker.make("atom") do |maker|
maker.channel.author = "foo"
end
end
assert_not_set_error("maker.channel", %w(title updated)) do
Maker.make("atom") do |maker|
maker.channel.author = "foo"
maker.channel.id = "http://example.com"
end
end
assert_not_set_error("maker.channel", %w(updated)) do
Maker.make("atom") do |maker|
maker.channel.author = "foo"
maker.channel.id = "http://example.com"
maker.channel.title = "Atom Feed"
end
end
assert_not_set_error("maker.channel", %w(author)) do
Maker.make("atom") do |maker|
maker.channel.id = "http://example.com"
maker.channel.title = "Atom Feed"
maker.channel.updated = Time.now
end
end
feed = Maker.make("atom") do |maker|
maker.channel.author = "Foo"
maker.channel.id = "http://example.com"
maker.channel.title = "Atom Feed"
maker.channel.updated = Time.now
end
assert_not_nil(feed)
end
def test_author
assert_maker_atom_persons("feed",
["channel", "authors"],
["authors"],
"maker.channel.author") do |maker|
setup_dummy_channel_atom(maker)
end
assert_not_set_error("maker.channel", %w(author)) do
RSS::Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.authors.clear
end
end
assert_maker_atom_persons("feed",
["items", "first", "authors"],
["entries", "first", "authors"],
"maker.item.author") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_persons("feed",
["items", "first", "source", "authors"],
["entries", "first", "source", "authors"],
"maker.item.source.author") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_category
assert_maker_atom_categories("feed",
["channel", "categories"],
["categories"],
"maker.channel.category") do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_categories("feed",
["items", "first", "categories"],
["entries", "first", "categories"],
"maker.item.category") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_categories("feed",
["items", "first", "source", "categories"],
["entries", "first", "source", "categories"],
"maker.item.source.category") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_contributor
assert_maker_atom_persons("feed",
["channel", "contributors"],
["contributors"],
"maker.channel.contributor") do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_persons("feed",
["items", "first", "contributors"],
["entries", "first", "contributors"],
"maker.item.contributor") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_persons("feed",
["items", "first", "source", "contributors"],
["entries", "first", "source", "contributors"],
"maker.item.source.contributor") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_generator
assert_maker_atom_generator("feed",
["channel", "generator"],
["generator"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_generator("feed",
["items", "first", "source", "generator"],
["entries", "first", "source", "generator"],
"maker.item.source.generator") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_icon
assert_maker_atom_icon("feed", ["channel"], ["icon"], "icon") do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_icon("feed",
["items", "first", "source", "icon"],
["entries", "first", "source", "icon"],
nil, "maker.item.source.icon") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_link
assert_maker_atom_links("feed",
["channel", "links"],
["links"],
"maker.channel.link") do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_links("feed",
["items", "first", "links"],
["entries", "first", "links"],
"maker.item.link") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_links("feed",
["items", "first", "source", "links"],
["entries", "first", "source", "links"],
"maker.item.source.link", true) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_logo
assert_maker_atom_logo("feed", ["channel"], ["logo"], "logo") do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_logo("feed", ["image"], ["logo"], "url") do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_logo("feed",
["items", "first", "source", "logo"],
["entries", "first", "source", "logo"],
nil, "maker.item.source.logo") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_rights
assert_maker_atom_text_construct("feed",
["channel", "copyright"],
["rights"]) do |maker|
setup_dummy_channel_atom(maker)
end
assert_maker_atom_text_construct("feed",
["items", "first", "rights"],
["entries", "first", "rights"],
nil, nil, "maker.item.rights"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_text_construct("feed",
["items", "first", "source", "rights"],
["entries", "first", "source", "rights"],
nil, nil, "maker.item.source.rights"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_subtitle
assert_maker_atom_text_construct("feed",
["channel", "subtitle"],
["subtitle"],
nil, nil,
"maker.channel.description") do |maker|
setup_dummy_channel_atom(maker)
maker.channel.description = nil
end
assert_maker_atom_text_construct("feed",
["channel", "subtitle"],
["subtitle"],
nil, nil,
"maker.channel.description") do |maker|
setup_dummy_channel_atom(maker)
maker.channel.description {|d| d.content = nil}
end
assert_maker_atom_text_construct("feed",
["items", "first", "source", "subtitle"],
["entries", "first",
"source", "subtitle"],
nil, nil,
"maker.item.source.subtitle") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_title
assert_maker_atom_text_construct("feed",
["channel", "title"], ["title"],
"maker.channel", ["title"]) do |maker|
setup_dummy_channel_atom(maker)
maker.channel.title = nil
end
assert_maker_atom_text_construct("feed",
["items", "first", "title"],
["entries", "first", "title"],
"maker.item", ["title"],
"maker.item.title") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.items.first.title = nil
end
assert_maker_atom_text_construct("feed",
["items", "first", "source", "title"],
["entries", "first", "source", "title"],
nil, nil, "maker.item.source.title"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_updated
assert_maker_atom_date_construct("feed",
["channel", "updated"], ["updated"],
"maker.channel", ["updated"]) do |maker|
setup_dummy_channel_atom(maker)
maker.channel.updated = nil
end
assert_maker_atom_date_construct("feed",
["items", "first", "updated"],
["entries", "first", "updated"],
"maker.item", ["updated"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.items.first.updated = nil
end
assert_maker_atom_date_construct("feed",
["items", "first", "source", "updated"],
["entries", "first", "source", "updated"]
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_published
assert_maker_atom_date_construct("feed",
["items", "first", "published"],
["entries", "first", "published"]
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_summary
assert_maker_atom_text_construct("feed",
["items", "first", "description"],
["entries", "first", "summary"],
nil, nil, "maker.item.description"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_content
assert_maker_atom_content("feed",
["items", "first", "content"],
["entries", "first", "content"],
"maker.item.content") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_id
assert_maker_atom_id("feed",
["items", "first", "source"],
["entries", "first", "source"],
"maker.item.source") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_language
language = "ja"
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.channel.language = "ja"
end
assert_equal(language, feed.dc_language)
end
def test_date
date = Time.parse("2004/11/1 10:10")
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.items.new_item do |item|
item.link = "http://example.com/article.html"
item.title = "sample article"
item.date = date
end
end
assert_equal(date, feed.items[0].updated.content)
assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
end
def test_channel_dc_date
date = Time.parse("2004/11/1 10:10")
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.channel.updated = nil
maker.channel.dc_date = date
setup_dummy_item_atom(maker)
end
assert_equal(date, feed.updated.content)
assert_equal([date], feed.dc_dates.collect {|_date| _date.value})
end
def test_item_dc_date
date = Time.parse("2004/11/1 10:10")
feed = Maker.make("atom") do |maker|
setup_dummy_channel_atom(maker)
maker.items.new_item do |item|
item.link = "http://example.com/article.html"
item.title = "sample article"
item.dc_date = date
end
end
assert_equal(date, feed.items[0].updated.content)
assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
end
end
end
|