rss 0.2.9 → 0.3.0

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