feedtools 0.2.22 → 0.2.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,17 @@ class AtomTest < Test::Unit::TestCase
14
14
  File.expand_path(File.dirname(__FILE__)) + '/../feeds')
15
15
  end
16
16
 
17
+ def test_iri_feed
18
+ if FeedTools::UriHelper.idn_enabled?
19
+ with_feed(:from_url =>
20
+ 'http://www.詹姆斯.com/atomtests/iri/everything.atom') { |feed|
21
+ assert_equal(
22
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/everything.atom",
23
+ feed.url)
24
+ }
25
+ end
26
+ end
27
+
17
28
  def test_feed_title
18
29
  with_feed(:from_file => 'wellformed/atom/atom_namespace_1.xml') { |feed|
19
30
  assert_equal("Example Atom", feed.title)
@@ -31,11 +42,13 @@ class AtomTest < Test::Unit::TestCase
31
42
  assert_equal("Example Atom", feed.title)
32
43
  }
33
44
  with_feed(:from_file => 'wellformed/atom/feed_title_base64.xml') { |feed|
34
- assert_equal("Example <b>Atom</b>", feed.title)
45
+ assert_equal("Example &lt;b&gt;Atom&lt;/b&gt;", feed.title)
35
46
  }
36
47
  with_feed(:from_file =>
37
48
  'wellformed/atom/feed_title_base64_2.xml') { |feed|
38
- assert_equal("<p>History of the &lt;blink&gt; tag</p>", feed.title)
49
+ assert_equal(
50
+ "&lt;p&gt;History of the &amp;lt;blink&amp;gt; tag&lt;/p&gt;",
51
+ feed.title)
39
52
  }
40
53
  end
41
54
 
@@ -94,16 +107,38 @@ class AtomTest < Test::Unit::TestCase
94
107
  assert_equal("http://www.example.com/something.jpeg",
95
108
  feed.images[0].url)
96
109
  }
110
+ with_feed(:from_data => <<-FEED
111
+ <feed>
112
+ <entry xml:base="http://example.com/articles/">
113
+ <title>Pain And Suffering</title>
114
+ <link href="1.html" type="text/plain" />
115
+ <link href="./2.html" type="application/xml" rel="alternate" />
116
+ <link href="../3.html" type="text/html" rel="alternate" />
117
+ <link href="../4.html" />
118
+ <link href="./5.html" type="application/xhtml+xml" />
119
+ <link href="6.css" type="text/css" rel="stylesheet" />
120
+ <content type="text">
121
+ What does your parser come up with for the main link?
122
+ What's the right value?
123
+ </content>
124
+ </entry>
125
+ </feed>
126
+ FEED
127
+ ) { |feed|
128
+ assert_equal("http://example.com/3.html", feed.entries[0].link)
129
+ }
97
130
  end
98
131
 
99
132
  def test_feed_copyright
100
133
  with_feed(:from_file =>
101
134
  'wellformed/atom/feed_copyright_base64.xml') { |feed|
102
- assert_equal("Example <b>Atom</b>", feed.copyright)
135
+ assert_equal("Example &lt;b&gt;Atom&lt;/b&gt;", feed.copyright)
103
136
  }
104
137
  with_feed(:from_file =>
105
138
  'wellformed/atom/feed_copyright_base64_2.xml') { |feed|
106
- assert_equal("<p>History of the &lt;blink&gt; tag</p>", feed.copyright)
139
+ assert_equal(
140
+ "&lt;p&gt;History of the &amp;lt;blink&amp;gt; tag&lt;/p&gt;",
141
+ feed.copyright)
107
142
  }
108
143
  end
109
144
 
@@ -136,5 +171,203 @@ class AtomTest < Test::Unit::TestCase
136
171
  assert_equal(nil, feed.link)
137
172
  }
138
173
  end
139
- end
140
-
174
+
175
+ def test_feed_item_summary_plus_content
176
+ with_feed(:from_data => <<-FEED
177
+ <?xml version="1.0" encoding="iso-8859-1"?>
178
+ <prefix:feed version="1.0" xmlns:prefix="http://www.w3.org/2005/Atom">
179
+ <prefix:entry>
180
+ <prefix:summary>Excerpt</prefix:summary>
181
+ <prefix:content>Full Content</prefix:content>
182
+ </prefix:entry>
183
+ </prefix:feed>
184
+ FEED
185
+ ) { |feed|
186
+ assert_equal(1, feed.items.size)
187
+ assert_equal("Excerpt", feed.items[0].summary)
188
+ assert_equal("Full Content", feed.items[0].content)
189
+ }
190
+ end
191
+
192
+ # Make sure it knows a title from a hole in the ground
193
+ def test_all_feed_titles
194
+ with_feed(:from_data => <<-FEED
195
+ <?xml version="1.0" encoding="iso-8859-1"?>
196
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
197
+ <title><![CDATA[&lt;title>]]></title>
198
+ <entry>
199
+ <title><![CDATA[&lt;title>]]></title>
200
+ </entry>
201
+ </feed>
202
+ FEED
203
+ ) { |feed|
204
+ assert_equal("&amp;lt;title&gt;",
205
+ feed.title, "Text CDATA failed")
206
+ assert_equal(1, feed.items.size)
207
+ assert_equal("&amp;lt;title&gt;",
208
+ feed.items[0].title, "Text CDATA failed")
209
+ }
210
+ with_feed(:from_data => <<-FEED
211
+ <?xml version="1.0" encoding="iso-8859-1"?>
212
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
213
+ <title type="html"><![CDATA[&lt;title>]]></title>
214
+ <entry>
215
+ <title type="html"><![CDATA[&lt;title>]]></title>
216
+ </entry>
217
+ </feed>
218
+ FEED
219
+ ) { |feed|
220
+ assert_equal("&lt;title&gt;",
221
+ feed.title, "HTML CDATA failed")
222
+ assert_equal(1, feed.items.size)
223
+ assert_equal("&lt;title&gt;",
224
+ feed.items[0].title, "HTML CDATA failed")
225
+ }
226
+ with_feed(:from_data => <<-FEED
227
+ <?xml version="1.0" encoding="iso-8859-1"?>
228
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
229
+ <title type="html">&amp;lt;title></title>
230
+ <entry>
231
+ <title type="html">&amp;lt;title></title>
232
+ </entry>
233
+ </feed>
234
+ FEED
235
+ ) { |feed|
236
+ assert_equal("&lt;title>",
237
+ feed.title, "HTML entity failed")
238
+ assert_equal(1, feed.items.size)
239
+ assert_equal("&lt;title>",
240
+ feed.items[0].title, "HTML entity failed")
241
+ }
242
+ with_feed(:from_data => <<-FEED
243
+ <?xml version="1.0" encoding="iso-8859-1"?>
244
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
245
+ <title type="html">&#38;lt;title></title>
246
+ <entry>
247
+ <title type="html">&#38;lt;title></title>
248
+ </entry>
249
+ </feed>
250
+ FEED
251
+ ) { |feed|
252
+ assert_equal("&lt;title>",
253
+ feed.title, "HTML NCR failed")
254
+ assert_equal(1, feed.items.size)
255
+ assert_equal("&lt;title>",
256
+ feed.items[0].title, "HTML NCR failed")
257
+ }
258
+ with_feed(:from_data => <<-FEED
259
+ <?xml version="1.0" encoding="iso-8859-1"?>
260
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
261
+ <title type="text"><![CDATA[<title>]]></title>
262
+ <entry>
263
+ <title type="text"><![CDATA[<title>]]></title>
264
+ </entry>
265
+ </feed>
266
+ FEED
267
+ ) { |feed|
268
+ assert_equal("&lt;title&gt;",
269
+ feed.title, "Text CDATA failed")
270
+ assert_equal(1, feed.items.size)
271
+ assert_equal("&lt;title&gt;",
272
+ feed.items[0].title, "Text CDATA failed")
273
+ }
274
+ with_feed(:from_data => <<-FEED
275
+ <?xml version="1.0" encoding="iso-8859-1"?>
276
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
277
+ <title type="text">&lt;title></title>
278
+ <entry>
279
+ <title type="text">&lt;title></title>
280
+ </entry>
281
+ </feed>
282
+ FEED
283
+ ) { |feed|
284
+ assert_equal("&lt;title&gt;",
285
+ feed.title, "Text entity failed")
286
+ assert_equal(1, feed.items.size)
287
+ assert_equal("&lt;title&gt;",
288
+ feed.items[0].title, "Text entity failed")
289
+ }
290
+ with_feed(:from_data => <<-FEED
291
+ <?xml version="1.0" encoding="iso-8859-1"?>
292
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
293
+ <title type="text">&#60;title></title>
294
+ <entry>
295
+ <title type="text">&#60;title></title>
296
+ </entry>
297
+ </feed>
298
+ FEED
299
+ ) { |feed|
300
+ assert_equal("&lt;title&gt;",
301
+ feed.title, "Text NCR failed")
302
+ assert_equal(1, feed.items.size)
303
+ assert_equal("&lt;title&gt;",
304
+ feed.items[0].title, "Text NCR failed")
305
+ }
306
+ with_feed(:from_data => <<-FEED
307
+ <?xml version="1.0" encoding="iso-8859-1"?>
308
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
309
+ <title type="xhtml">
310
+ <div xmlns="http://www.w3.org/1999/xhtml">&lt;title></div>
311
+ </title>
312
+ <entry>
313
+ <title type="xhtml">
314
+ <div xmlns="http://www.w3.org/1999/xhtml">&lt;title></div>
315
+ </title>
316
+ </entry>
317
+ </feed>
318
+ FEED
319
+ ) { |feed|
320
+ assert_equal(
321
+ '&lt;title&gt;',
322
+ feed.title, "XHTML entity failed")
323
+ assert_equal(1, feed.items.size)
324
+ assert_equal(
325
+ '&lt;title&gt;',
326
+ feed.items[0].title, "XHTML entity failed")
327
+ }
328
+ with_feed(:from_data => <<-FEED
329
+ <?xml version="1.0" encoding="iso-8859-1"?>
330
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
331
+ <title type="xhtml">
332
+ <div xmlns="http://www.w3.org/1999/xhtml">&#60;title></div>
333
+ </title>
334
+ <entry>
335
+ <title type="xhtml">
336
+ <div xmlns="http://www.w3.org/1999/xhtml">&#60;title></div>
337
+ </title>
338
+ </entry>
339
+ </feed>
340
+ FEED
341
+ ) { |feed|
342
+ assert_equal(
343
+ '&#60;title&gt;',
344
+ feed.title, "XHTML NCR failed")
345
+ assert_equal(1, feed.items.size)
346
+ assert_equal(
347
+ '&#60;title&gt;',
348
+ feed.items[0].title, "XHTML NCR failed")
349
+ }
350
+ with_feed(:from_data => <<-FEED
351
+ <?xml version="1.0" encoding="iso-8859-1"?>
352
+ <feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
353
+ <title type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
354
+ <xhtml:div>&lt;title></xhtml:div>
355
+ </title>
356
+ <entry>
357
+ <title type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
358
+ <xhtml:div>&lt;title></xhtml:div>
359
+ </title>
360
+ </entry>
361
+ </feed>
362
+ FEED
363
+ ) { |feed|
364
+ assert_equal(
365
+ '&lt;title&gt;',
366
+ feed.title, "XHTML NCR failed")
367
+ assert_equal(1, feed.items.size)
368
+ assert_equal(
369
+ '&lt;title&gt;',
370
+ feed.items[0].title, "XHTML NCR failed")
371
+ }
372
+ end
373
+ end
@@ -64,7 +64,7 @@ class CacheTest < Test::Unit::TestCase
64
64
  assert_equal(false, slashdot_feed.url.blank?)
65
65
  FeedTools::Feed.open(slashdot_feed.url)
66
66
 
67
- entries = FeedTools::DatabaseFeedCache.find_all_by_url(slashdot_feed.url)
67
+ entries = FeedTools::DatabaseFeedCache.find_all_by_href(slashdot_feed.url)
68
68
  assert_equal(1, entries.size)
69
69
  rescue FeedTools::FeedAccessError
70
70
  end
@@ -38,7 +38,7 @@ class EncodingTest < Test::Unit::TestCase
38
38
  </rss>
39
39
  FEED
40
40
  ) { |feed|
41
- assert_equal("utf-8", feed.encoding_from_xml_data)
41
+ assert_equal("utf-8", feed.encoding_from_feed_data)
42
42
  assert_equal("utf-8", feed.encoding)
43
43
  }
44
44
 
@@ -48,7 +48,7 @@ class EncodingTest < Test::Unit::TestCase
48
48
  </rss>
49
49
  FEED
50
50
  ) { |feed|
51
- assert_equal("us-ascii", feed.encoding_from_xml_data)
51
+ assert_equal("us-ascii", feed.encoding_from_feed_data)
52
52
  assert_equal("us-ascii", feed.encoding)
53
53
  }
54
54
 
@@ -58,7 +58,7 @@ class EncodingTest < Test::Unit::TestCase
58
58
  </rss>
59
59
  FEED
60
60
  ) { |feed|
61
- assert_equal("us-ascii", feed.encoding_from_xml_data)
61
+ assert_equal("us-ascii", feed.encoding_from_feed_data)
62
62
  assert_equal("us-ascii", feed.encoding)
63
63
  }
64
64
 
@@ -68,7 +68,7 @@ class EncodingTest < Test::Unit::TestCase
68
68
  </rss>
69
69
  FEED
70
70
  ) { |feed|
71
- assert_equal("big5", feed.encoding_from_xml_data)
71
+ assert_equal("big5", feed.encoding_from_feed_data)
72
72
  assert_equal("big5", feed.encoding)
73
73
  }
74
74
 
@@ -78,7 +78,7 @@ class EncodingTest < Test::Unit::TestCase
78
78
  </rss>
79
79
  FEED
80
80
  ) { |feed|
81
- assert_equal("mac", feed.encoding_from_xml_data)
81
+ assert_equal("mac", feed.encoding_from_feed_data)
82
82
  assert_equal("mac", feed.encoding)
83
83
  }
84
84
  end
@@ -17,9 +17,10 @@ class GenerationTest < Test::Unit::TestCase
17
17
  3.times do |i|
18
18
  item = FeedTools::FeedItem.new
19
19
  item.content = "This is item number #{i}"
20
+ item.summary = "This is the excerpt for item number #{i}"
20
21
  item.link = "http://example.com/item#{i}/"
21
22
  feed.items << item
22
- sleep(0.5)
23
+ sleep(1.0)
23
24
  end
24
25
  output_xml = feed.build_xml('rss', 2.0)
25
26
 
@@ -34,10 +35,16 @@ class GenerationTest < Test::Unit::TestCase
34
35
 
35
36
  # Note reverse chronological order
36
37
  assert_equal('This is item number 2', parsed_feed.items[0].content)
38
+ assert_equal('This is the excerpt for item number 2',
39
+ parsed_feed.items[0].summary)
37
40
  assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
38
41
  assert_equal('This is item number 1', parsed_feed.items[1].content)
42
+ assert_equal('This is the excerpt for item number 1',
43
+ parsed_feed.items[1].summary)
39
44
  assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
40
45
  assert_equal('This is item number 0', parsed_feed.items[2].content)
46
+ assert_equal('This is the excerpt for item number 0',
47
+ parsed_feed.items[2].summary)
41
48
  assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
42
49
 
43
50
  # Check feed information
@@ -55,6 +62,7 @@ class GenerationTest < Test::Unit::TestCase
55
62
  3.times do |i|
56
63
  item = FeedTools::FeedItem.new
57
64
  item.content = "This is item number #{i}"
65
+ item.summary = "This is the excerpt for item number #{i}"
58
66
  item.link = "http://example.com/item#{i}/"
59
67
  feed.items << item
60
68
  sleep(0.5)
@@ -72,10 +80,16 @@ class GenerationTest < Test::Unit::TestCase
72
80
 
73
81
  # Note reverse chronological order
74
82
  assert_equal('This is item number 2', parsed_feed.items[0].content)
83
+ assert_equal('This is the excerpt for item number 2',
84
+ parsed_feed.items[0].summary)
75
85
  assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
76
86
  assert_equal('This is item number 1', parsed_feed.items[1].content)
87
+ assert_equal('This is the excerpt for item number 1',
88
+ parsed_feed.items[1].summary)
77
89
  assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
78
90
  assert_equal('This is item number 0', parsed_feed.items[2].content)
91
+ assert_equal('This is the excerpt for item number 0',
92
+ parsed_feed.items[2].summary)
79
93
  assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
80
94
 
81
95
  # Check feed information
@@ -93,6 +107,7 @@ class GenerationTest < Test::Unit::TestCase
93
107
  3.times do |i|
94
108
  item = FeedTools::FeedItem.new
95
109
  item.content = "This is item number #{i}"
110
+ item.summary = "This is the excerpt for item number #{i}"
96
111
  item.link = "http://example.com/item#{i}/"
97
112
  feed.items << item
98
113
  sleep(0.5)
@@ -110,10 +125,16 @@ class GenerationTest < Test::Unit::TestCase
110
125
 
111
126
  # Note reverse chronological order
112
127
  assert_equal('This is item number 2', parsed_feed.items[0].content)
128
+ assert_equal('This is the excerpt for item number 2',
129
+ parsed_feed.items[0].summary)
113
130
  assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
114
131
  assert_equal('This is item number 1', parsed_feed.items[1].content)
132
+ assert_equal('This is the excerpt for item number 1',
133
+ parsed_feed.items[1].summary)
115
134
  assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
116
135
  assert_equal('This is item number 0', parsed_feed.items[2].content)
136
+ assert_equal('This is the excerpt for item number 0',
137
+ parsed_feed.items[2].summary)
117
138
  assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
118
139
 
119
140
  # Check feed information
@@ -130,6 +151,7 @@ class GenerationTest < Test::Unit::TestCase
130
151
  3.times do |i|
131
152
  item = FeedTools::FeedItem.new
132
153
  item.content = nil
154
+ item.summary = nil
133
155
  item.link = "http://example.com/item#{i}/"
134
156
  feed.items << item
135
157
  sleep(0.5)
@@ -147,10 +169,13 @@ class GenerationTest < Test::Unit::TestCase
147
169
 
148
170
  # Note reverse chronological order
149
171
  assert_equal(nil, parsed_feed.items[0].content)
172
+ assert_equal(nil, parsed_feed.items[0].summary)
150
173
  assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
151
174
  assert_equal(nil, parsed_feed.items[1].content)
175
+ assert_equal(nil, parsed_feed.items[1].summary)
152
176
  assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
153
177
  assert_equal(nil, parsed_feed.items[2].content)
178
+ assert_equal(nil, parsed_feed.items[2].summary)
154
179
  assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
155
180
 
156
181
  # Check feed information
@@ -167,6 +192,7 @@ class GenerationTest < Test::Unit::TestCase
167
192
  3.times do |i|
168
193
  item = FeedTools::FeedItem.new
169
194
  item.content = nil
195
+ item.summary = nil
170
196
  item.link = "http://example.com/item#{i}/"
171
197
  feed.items << item
172
198
  sleep(0.5)
@@ -184,10 +210,13 @@ class GenerationTest < Test::Unit::TestCase
184
210
 
185
211
  # Note reverse chronological order
186
212
  assert_equal(nil, parsed_feed.items[0].content)
213
+ assert_equal(nil, parsed_feed.items[0].summary)
187
214
  assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
188
215
  assert_equal(nil, parsed_feed.items[1].content)
216
+ assert_equal(nil, parsed_feed.items[1].summary)
189
217
  assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
190
218
  assert_equal(nil, parsed_feed.items[2].content)
219
+ assert_equal(nil, parsed_feed.items[2].summary)
191
220
  assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
192
221
 
193
222
  # Check feed information
@@ -204,6 +233,7 @@ class GenerationTest < Test::Unit::TestCase
204
233
  3.times do |i|
205
234
  item = FeedTools::FeedItem.new
206
235
  item.content = nil
236
+ item.summary = nil
207
237
  item.link = "http://example.com/item#{i}/"
208
238
  feed.items << item
209
239
  sleep(0.5)
@@ -221,10 +251,13 @@ class GenerationTest < Test::Unit::TestCase
221
251
 
222
252
  # Note reverse chronological order
223
253
  assert_equal(nil, parsed_feed.items[0].content)
254
+ assert_equal(nil, parsed_feed.items[0].summary)
224
255
  assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
225
256
  assert_equal(nil, parsed_feed.items[1].content)
257
+ assert_equal(nil, parsed_feed.items[1].summary)
226
258
  assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
227
259
  assert_equal(nil, parsed_feed.items[2].content)
260
+ assert_equal(nil, parsed_feed.items[2].summary)
228
261
  assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
229
262
 
230
263
  # Check feed information