summaryrefslogtreecommitdiff
path: root/test/rss/test_maker_atom_feed.rb
blob: e5bf0e23b27e14472d293ec7bcc9f98b881d978b (plain)
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
require "rss-testcase"

require "rss/maker"

module RSS
  class TestMakerAtomFeed < TestCase
    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
  end
end