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
|
require_relative "rss-testcase"
require "rss/maker"
module RSS
class TestMakerAtomEntry < TestCase
def test_supported?
assert(RSS::Maker.supported?("atom:entry"))
assert(RSS::Maker.supported?("atom1.0:entry"))
assert(!RSS::Maker.supported?("atom2.0:entry"))
end
def test_find_class
assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom:entry"])
assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom1.0:entry"])
end
def test_root_element
entry = Maker.make("atom:entry") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_equal(["atom", "1.0", "entry"], entry.feed_info)
entry = Maker.make("atom:entry") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.encoding = "EUC-JP"
end
assert_equal(["atom", "1.0", "entry"], entry.feed_info)
assert_equal("EUC-JP", entry.encoding)
entry = Maker.make("atom:entry") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.standalone = "yes"
end
assert_equal(["atom", "1.0", "entry"], entry.feed_info)
assert_equal("yes", entry.standalone)
entry = Maker.make("atom:entry") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.encoding = "EUC-JP"
maker.standalone = "yes"
end
assert_equal(["atom", "1.0", "entry"], entry.feed_info)
assert_equal("EUC-JP", entry.encoding)
assert_equal("yes", entry.standalone)
end
def test_invalid_feed
assert_not_set_error("maker.item", %w(id title author updated)) do
Maker.make("atom:entry") do |maker|
end
end
assert_not_set_error("maker.item", %w(id title updated)) do
Maker.make("atom:entry") do |maker|
maker.channel.author = "foo"
end
end
assert_not_set_error("maker.item", %w(title updated)) do
Maker.make("atom:entry") do |maker|
maker.channel.author = "foo"
maker.channel.id = "http://example.com"
end
end
assert_not_set_error("maker.item", %w(updated)) do
Maker.make("atom:entry") do |maker|
maker.channel.author = "foo"
maker.channel.id = "http://example.com"
maker.channel.title = "Atom Feed"
end
end
assert_not_set_error("maker.item", %w(author)) do
Maker.make("atom:entry") do |maker|
maker.channel.id = "http://example.com"
maker.channel.title = "Atom Feed"
maker.channel.updated = Time.now
end
end
entry = Maker.make("atom:entry") 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(entry)
end
def test_author
assert_maker_atom_persons("entry",
["channel", "authors"],
["authors"],
"maker.channel.author") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_persons("entry",
["items", "first", "authors"],
["authors"],
"maker.item.author",
"maker.item", ["author"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.authors.clear
maker.items.first.authors.clear
end
assert_maker_atom_persons("entry",
["items", "first", "source", "authors"],
["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("entry",
["channel", "categories"],
["categories"],
"maker.channel.category") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_categories("entry",
["items", "first", "categories"],
["categories"],
"maker.item.category") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_categories("entry",
["items", "first", "source", "categories"],
["source", "categories"],
"maker.item.source.category") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_content
assert_maker_atom_content("entry",
["items", "first", "content"],
["content"],
"maker.item.content") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_contributor
assert_maker_atom_persons("entry",
["channel", "contributors"],
["contributors"],
"maker.channel.contributor") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_persons("entry",
["items", "first", "contributors"],
["contributors"],
"maker.item.contributor") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_persons("entry",
["items", "first", "source", "contributors"],
["source", "contributors"],
"maker.item.source.contributor") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_link
assert_maker_atom_links("entry",
["channel", "links"],
["links"],
"maker.channel.link") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.links.clear
maker.items.first.links.clear
end
assert_maker_atom_links("entry",
["items", "first", "links"],
["links"],
"maker.item.link") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.links.clear
maker.items.first.links.clear
end
assert_maker_atom_links("entry",
["items", "first", "source", "links"],
["source", "links"],
"maker.item.source.link", true) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_published
assert_maker_atom_date_construct("entry",
["items", "first", "published"],
["published"]
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_rights
assert_maker_atom_text_construct("entry",
["channel", "copyright"],
["rights"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_text_construct("entry",
["items", "first", "rights"],
["rights"],
nil, nil, "maker.item.rights"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
assert_maker_atom_text_construct("entry",
["items", "first", "source", "rights"],
["source", "rights"],
nil, nil, "maker.item.source.rights"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_source_generator
assert_maker_atom_generator("entry",
["items", "first", "source", "generator"],
["source", "generator"],
"maker.item.source.generator") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_source_icon
assert_maker_atom_icon("entry",
["items", "first", "source", "icon"],
["source", "icon"],
nil, "maker.item.source.icon") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_source_id
assert_maker_atom_id("entry",
["items", "first", "source"],
["source"],
"maker.item.source") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_source_logo
assert_maker_atom_logo("entry",
["items", "first", "source", "logo"],
["source", "logo"],
nil,
"maker.item.source.logo") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_source_subtitle
assert_maker_atom_text_construct("entry",
["items", "first", "source", "subtitle"],
["source", "subtitle"],
nil, nil,
"maker.item.source.subtitle") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_summary
assert_maker_atom_text_construct("entry",
["items", "first", "description"],
["summary"],
nil, nil, "maker.item.description"
) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_title
assert_maker_atom_text_construct("entry",
["channel", "title"], ["title"],
"maker.item", ["title"],
"maker.channel.title") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.title = nil
maker.items.first.title = nil
end
assert_maker_atom_text_construct("entry",
["items", "first", "title"],
["title"],
"maker.item", ["title"],
"maker.item.title") do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.title = nil
maker.items.first.title = nil
end
assert_maker_atom_text_construct("entry",
["items", "first", "source", "title"],
["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("entry",
["channel", "updated"], ["updated"],
"maker.item", ["updated"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.updated = nil
maker.items.first.updated = nil
end
assert_maker_atom_date_construct("entry",
["items", "first", "updated"],
["updated"],
"maker.item", ["updated"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
maker.channel.updated = nil
maker.items.first.updated = nil
end
assert_maker_atom_date_construct("entry",
["items", "first", "source", "updated"],
["source", "updated"]) do |maker|
setup_dummy_channel_atom(maker)
setup_dummy_item_atom(maker)
end
end
def test_date
date = Time.parse("2004/11/1 10:10")
feed = Maker.make("atom:entry") do |maker|
setup_dummy_channel_atom(maker)
maker.channel.date = nil
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
end
end
|