feedtools 0.2.18 → 0.2.19

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.
@@ -3,12 +3,13 @@ require 'feed_tools'
3
3
  require 'feed_tools/helpers/feed_tools_helper'
4
4
 
5
5
  class AtomTest < Test::Unit::TestCase
6
- include FeedToolsHelper
6
+ include FeedTools::FeedToolsHelper
7
7
 
8
8
  def setup
9
- FeedTools.tidy_enabled = false
10
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
11
- FeedToolsHelper.default_local_path =
9
+ FeedTools.reset_configurations
10
+ FeedTools.configurations[:tidy_enabled] = false
11
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
12
+ FeedTools::FeedToolsHelper.default_local_path =
12
13
  File.expand_path(
13
14
  File.expand_path(File.dirname(__FILE__)) + '/../feeds')
14
15
  end
@@ -37,8 +38,65 @@ class AtomTest < Test::Unit::TestCase
37
38
  assert_equal("<p>History of the &lt;blink&gt; tag</p>", feed.title)
38
39
  }
39
40
  end
41
+
42
+ def test_feed_link
43
+ with_feed(:from_data => <<-FEED
44
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#">
45
+ <link rel="alternate" href="http://www.example.com/" />
46
+ <link rel="alternate" href="http://www.example.com/somewhere/" />
47
+ </feed>
48
+ FEED
49
+ ) { |feed|
50
+ assert_equal("http://www.example.com/", feed.link)
51
+ assert_equal(0, feed.images.size)
52
+ }
53
+ with_feed(:from_data => <<-FEED
54
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#">
55
+ <link type="text/html" href="http://www.example.com/" />
56
+ </feed>
57
+ FEED
58
+ ) { |feed|
59
+ assert_equal("http://www.example.com/", feed.link)
60
+ assert_equal(0, feed.images.size)
61
+ }
62
+ with_feed(:from_data => <<-FEED
63
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#">
64
+ <link type="application/xhtml+xml" href="http://www.example.com/" />
65
+ </feed>
66
+ FEED
67
+ ) { |feed|
68
+ assert_equal("http://www.example.com/", feed.link)
69
+ assert_equal(0, feed.images.size)
70
+ }
71
+ with_feed(:from_data => <<-FEED
72
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#">
73
+ <link href="http://www.example.com/" />
74
+ </feed>
75
+ FEED
76
+ ) { |feed|
77
+ assert_equal("http://www.example.com/", feed.link)
78
+ assert_equal(0, feed.images.size)
79
+ }
80
+ with_feed(:from_data => <<-FEED
81
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#">
82
+ <link rel="alternate" type="image/jpeg"
83
+ href="http://www.example.com/something.jpeg" />
84
+ <link rel="alternate" href="http://www.example.com/" />
85
+ <link rel="alternate" type="text/html"
86
+ href="http://www.example.com/somewhere/" />
87
+ <link rel="alternate" type="application/xhtml+xml"
88
+ href="http://www.example.com/xhtml/somewhere/" />
89
+ </feed>
90
+ FEED
91
+ ) { |feed|
92
+ assert_equal("http://www.example.com/xhtml/somewhere/", feed.link)
93
+ assert_equal(1, feed.images.size)
94
+ assert_equal("http://www.example.com/something.jpeg",
95
+ feed.images[0].url)
96
+ }
97
+ end
40
98
 
41
- def test_copyright
99
+ def test_feed_copyright
42
100
  with_feed(:from_file =>
43
101
  'wellformed/atom/feed_copyright_base64.xml') { |feed|
44
102
  assert_equal("Example <b>Atom</b>", feed.copyright)
@@ -49,10 +107,34 @@ class AtomTest < Test::Unit::TestCase
49
107
  }
50
108
  end
51
109
 
52
- def test_feed_author
53
- # feed = FeedTools::Feed.open(
54
- # 'http://feedparser.org/tests/wellformed/atom/atom_namespace_5.xml')
55
- # assert_equal("Example Atom", feed.title)
110
+ def test_feed_item_author
111
+ with_feed(:from_data => <<-FEED
112
+ <?xml version="1.0" encoding="iso-8859-1"?>
113
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#" xml:lang="en">
114
+ <entry>
115
+ <author>
116
+ <name>Cooper Baker</name>
117
+ </author>
118
+ </entry>
119
+ </feed>
120
+ FEED
121
+ ) { |feed|
122
+ assert_equal(1, feed.entries.size)
123
+ assert_equal("Cooper Baker", feed.entries[0].author.name)
124
+ }
125
+ end
126
+
127
+ def test_feed_images
128
+ with_feed(:from_data => <<-FEED
129
+ <feed version="0.3" xmlns="http://purl.org/atom/ns#">
130
+ <link type="image/jpeg" href="http://www.example.com/image.jpeg" />
131
+ </feed>
132
+ FEED
133
+ ) { |feed|
134
+ assert_equal(1, feed.images.size)
135
+ assert_equal("http://www.example.com/image.jpeg", feed.images[0].url)
136
+ assert_equal(nil, feed.link)
137
+ }
56
138
  end
57
139
  end
58
140
 
@@ -1,15 +1,22 @@
1
1
  require 'test/unit'
2
2
  require 'feed_tools'
3
+ require 'feed_tools/helpers/feed_tools_helper'
3
4
 
4
5
  class CacheTest < Test::Unit::TestCase
6
+ include FeedTools::FeedToolsHelper
7
+
5
8
  def setup
6
- FeedTools.tidy_enabled = false
9
+ FeedTools.reset_configurations
10
+ FeedTools.configurations[:tidy_enabled] = false
11
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
12
+ FeedTools::FeedToolsHelper.default_local_path =
13
+ File.expand_path(
14
+ File.expand_path(File.dirname(__FILE__)) + '/../feeds')
7
15
  end
8
16
 
9
17
  def test_database_connection
10
18
  # Ensure the cache is on for this test
11
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
12
-
19
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
13
20
  unless FeedTools.feed_cache.nil?
14
21
  # Assumes that there is a database.yml file handy
15
22
  assert_equal(true, FeedTools.feed_cache_connected?)
@@ -20,38 +27,41 @@ class CacheTest < Test::Unit::TestCase
20
27
 
21
28
  def test_redirects_when_cache_disabled
22
29
  # Turn the cache off for this test
23
- FeedTools.feed_cache = nil
24
-
25
- # We just want to make sure there's no unexepected exceptions
30
+ FeedTools.configurations[:feed_cache] = nil
31
+ # We just want to make sure there's no unexpected exceptions
26
32
  begin
27
33
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
28
34
  rescue FeedTools::FeedAccessError
29
35
  end
30
36
 
31
37
  # Turn the cache back on
32
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
38
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
33
39
  end
34
40
 
35
41
  def test_redirects_when_cache_enabled
36
42
  # Ensure the cache is on for this test
37
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
38
-
43
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
39
44
  begin
40
45
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
41
46
  assert(slashdot_feed.feed_data != nil, "No content retrieved.")
42
47
  slashdot_feed.expire!
43
48
  assert_equal(true, slashdot_feed.expired?)
49
+ assert_equal(false, slashdot_feed.url.blank?)
44
50
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
45
51
  assert(slashdot_feed.feed_data != nil, "No content retrieved.")
46
52
  assert_equal(true, slashdot_feed.live?)
53
+ assert_equal(false, slashdot_feed.url.blank?)
47
54
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
48
55
  assert(slashdot_feed.feed_data != nil, "No content retrieved.")
49
56
  assert_equal(false, slashdot_feed.live?)
57
+ assert_equal(false, slashdot_feed.url.blank?)
50
58
  slashdot_feed.expire!
51
59
  slashdot_feed.expire!
60
+ assert_equal(false, slashdot_feed.url.blank?)
52
61
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
53
62
  assert(slashdot_feed.feed_data != nil, "No content retrieved.")
54
63
  assert_equal(true, slashdot_feed.live?)
64
+ assert_equal(false, slashdot_feed.url.blank?)
55
65
  FeedTools::Feed.open(slashdot_feed.url)
56
66
 
57
67
  entries = FeedTools::DatabaseFeedCache.find_all_by_url(slashdot_feed.url)
@@ -62,16 +72,17 @@ class CacheTest < Test::Unit::TestCase
62
72
 
63
73
  def test_cached_item_expiration
64
74
  # Ensure the cache is on for this test
65
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
66
-
75
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
67
76
  begin
68
77
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
69
78
  assert(slashdot_feed.feed_data != nil, "No content retrieved.")
70
79
  slashdot_feed.expire!
71
80
  assert_equal(true, slashdot_feed.expired?)
81
+ assert_equal(false, slashdot_feed.url.blank?)
72
82
  slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
73
83
  assert(slashdot_feed.feed_data != nil, "No content retrieved.")
74
84
  assert_equal(true, slashdot_feed.live?)
85
+ assert_equal(false, slashdot_feed.url.blank?)
75
86
  slashdot_feed.time_to_live = 1.hour
76
87
  slashdot_feed.last_retrieved = (Time.now - 55.minute)
77
88
  assert_equal(false, slashdot_feed.expired?)
@@ -80,4 +91,12 @@ class CacheTest < Test::Unit::TestCase
80
91
  rescue FeedTools::FeedAccessError
81
92
  end
82
93
  end
94
+
95
+ def test_file_protocol_url_cache_disuse
96
+ # Ensure the cache is on for this test
97
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
98
+ with_feed(:from_file => 'wellformed/rss/aaa_wellformed.xml') { |feed|
99
+ assert_equal(nil, feed.cache_object)
100
+ }
101
+ end
83
102
  end
@@ -3,12 +3,13 @@ require 'feed_tools'
3
3
  require 'feed_tools/helpers/feed_tools_helper'
4
4
 
5
5
  class CdfTest < Test::Unit::TestCase
6
- include FeedToolsHelper
6
+ include FeedTools::FeedToolsHelper
7
7
 
8
8
  def setup
9
- FeedTools.tidy_enabled = false
10
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
11
- FeedToolsHelper.default_local_path =
9
+ FeedTools.reset_configurations
10
+ FeedTools.configurations[:tidy_enabled] = false
11
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
12
+ FeedTools::FeedToolsHelper.default_local_path =
12
13
  File.expand_path(
13
14
  File.expand_path(File.dirname(__FILE__)) + '/../feeds')
14
15
  end
@@ -61,6 +62,7 @@ class CdfTest < Test::Unit::TestCase
61
62
  </CHANNEL>
62
63
  FEED
63
64
  ) { |feed|
65
+ assert_equal(2, feed.images.size)
64
66
  assert_equal("http://www.example.com/exampleicon.gif", feed.images[0].url)
65
67
  assert_equal("icon", feed.images[0].style)
66
68
  assert_equal("http://www.example.com/exampleimage.gif", feed.images[1].url)
@@ -0,0 +1,99 @@
1
+ require 'test/unit'
2
+ require 'feed_tools'
3
+ require 'feed_tools/helpers/feed_tools_helper'
4
+
5
+ class EncodingTest < Test::Unit::TestCase
6
+ include FeedTools::FeedToolsHelper
7
+
8
+ def setup
9
+ FeedTools.reset_configurations
10
+ FeedTools.configurations[:tidy_enabled] = false
11
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
12
+ FeedTools::FeedToolsHelper.default_local_path =
13
+ File.expand_path(
14
+ File.expand_path(File.dirname(__FILE__)) + '/../feeds')
15
+ end
16
+
17
+ def test_http_headers_nil
18
+ with_feed(:from_url =>
19
+ 'http://rss.slashdot.org/Slashdot/slashdot') { |feed|
20
+ assert_equal(false, feed.http_headers.blank?)
21
+ assert_equal('http://rss.slashdot.org/Slashdot/slashdot', feed.url)
22
+ feed.feed_data = <<-FEED
23
+ <rss>
24
+ <channel>
25
+ <title>Feed Title</title>
26
+ </channel>
27
+ </rss>
28
+ FEED
29
+ assert_equal(true, feed.http_headers.blank?)
30
+ assert_equal(nil, feed.url)
31
+ }
32
+ end
33
+
34
+ def test_encoding_from_instruct
35
+ with_feed(:from_data => <<-FEED
36
+ <?xml version="1.0" encoding="UTF-8"?>
37
+ <rss version="2.0">
38
+ </rss>
39
+ FEED
40
+ ) { |feed|
41
+ assert_equal("utf-8", feed.encoding_from_xml_data)
42
+ assert_equal("utf-8", feed.encoding)
43
+ }
44
+
45
+ with_feed(:from_data => <<-FEED
46
+ <?xml encoding="US-ascii" version="1.0" ?>
47
+ <rss version="2.0">
48
+ </rss>
49
+ FEED
50
+ ) { |feed|
51
+ assert_equal("us-ascii", feed.encoding_from_xml_data)
52
+ assert_equal("us-ascii", feed.encoding)
53
+ }
54
+
55
+ with_feed(:from_data => <<-FEED
56
+ <?xml encoding="US-ascii"?>
57
+ <rss version="2.0">
58
+ </rss>
59
+ FEED
60
+ ) { |feed|
61
+ assert_equal("us-ascii", feed.encoding_from_xml_data)
62
+ assert_equal("us-ascii", feed.encoding)
63
+ }
64
+
65
+ with_feed(:from_data => <<-FEED
66
+ <?xml encoding="big5" ?>
67
+ <rss version="2.0">
68
+ </rss>
69
+ FEED
70
+ ) { |feed|
71
+ assert_equal("big5", feed.encoding_from_xml_data)
72
+ assert_equal("big5", feed.encoding)
73
+ }
74
+
75
+ with_feed(:from_data => <<-FEED
76
+ <?xml bogus="crap" encoding="mac" bogus="crap" ?>
77
+ <rss version="2.0">
78
+ </rss>
79
+ FEED
80
+ ) { |feed|
81
+ assert_equal("mac", feed.encoding_from_xml_data)
82
+ assert_equal("mac", feed.encoding)
83
+ }
84
+ end
85
+
86
+ def test_ebcdic
87
+ with_feed(:from_file =>
88
+ '/wellformed/encoding/x80_ebcdic-cp-us.xml') { |feed|
89
+ assert_equal("ebcdic-cp-us", feed.encoding)
90
+ }
91
+ end
92
+
93
+ def test_big_5
94
+ with_feed(:from_file =>
95
+ '/wellformed/encoding/big5.xml') { |feed|
96
+ assert_equal("big5", feed.encoding)
97
+ }
98
+ end
99
+ end
@@ -3,8 +3,9 @@ require 'feed_tools'
3
3
 
4
4
  class GenerationTest < Test::Unit::TestCase
5
5
  def setup
6
- FeedTools.tidy_enabled = false
7
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
6
+ FeedTools.reset_configurations
7
+ FeedTools.configurations[:tidy_enabled] = false
8
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
8
9
  end
9
10
 
10
11
  def test_generate_rss_20_from_scratch
@@ -120,42 +121,4 @@ class GenerationTest < Test::Unit::TestCase
120
121
  assert_equal('atom', parsed_feed.feed_type)
121
122
  assert_equal(1.0, parsed_feed.feed_version)
122
123
  end
123
-
124
- def test_generate_atom_03_from_scratch
125
- # Create the feed
126
- feed = FeedTools::Feed.new
127
- feed.title = 'Test Feed'
128
- feed.description = 'Test Feed Description'
129
- feed.link = 'http://example.com/'
130
- 3.times do |i|
131
- item = FeedTools::FeedItem.new
132
- item.content = "This is item number #{i}"
133
- item.link = "http://example.com/item#{i}/"
134
- feed.items << item
135
- sleep(1)
136
- end
137
- output_xml = feed.build_xml('atom', 0.3)
138
-
139
- # Now read it back in
140
- parsed_feed = FeedTools::Feed.new
141
- parsed_feed.feed_data = output_xml
142
- parsed_feed.feed_data_type = :xml
143
-
144
- assert_equal('Test Feed', parsed_feed.title)
145
- assert_equal('Test Feed Description', parsed_feed.description)
146
- assert_equal('http://example.com/', parsed_feed.link)
147
-
148
- # Note reverse chronological order
149
- assert_equal('This is item number 2', parsed_feed.items[0].content)
150
- assert_equal('http://example.com/item2/', parsed_feed.items[0].link)
151
- assert_equal('This is item number 1', parsed_feed.items[1].content)
152
- assert_equal('http://example.com/item1/', parsed_feed.items[1].link)
153
- assert_equal('This is item number 0', parsed_feed.items[2].content)
154
- assert_equal('http://example.com/item0/', parsed_feed.items[2].link)
155
-
156
- # Check feed information
157
- assert_equal(:xml, parsed_feed.feed_data_type)
158
- assert_equal('atom', parsed_feed.feed_type)
159
- assert_equal(0.3, parsed_feed.feed_version)
160
- end
161
124
  end
@@ -1,15 +1,68 @@
1
1
  require 'test/unit'
2
2
  require 'feed_tools'
3
+ require 'feed_tools/helpers/feed_tools_helper'
3
4
 
4
5
  class HelperTest < Test::Unit::TestCase
6
+ include FeedTools::FeedToolsHelper
7
+ include FeedTools::GenericHelper
8
+
5
9
  def setup
6
- FeedTools.tidy_enabled = false
7
- FeedTools.feed_cache = FeedTools::DatabaseFeedCache
8
- FeedToolsHelper.default_local_path =
10
+ FeedTools.reset_configurations
11
+ FeedTools.configurations[:tidy_enabled] = false
12
+ FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
13
+ FeedTools::FeedToolsHelper.default_local_path =
9
14
  File.expand_path(
10
15
  File.expand_path(File.dirname(__FILE__)) + '/../feeds')
11
16
  end
12
17
 
18
+ def test_xpath_case_insensitivity
19
+ FEED_TOOLS_NAMESPACES["testnamespace"] = "http://example.com/ns/"
20
+
21
+ xml = <<-XML
22
+ <RoOt>
23
+ <ChIlD>Test String #1</ChIlD>
24
+ </RoOt>
25
+ XML
26
+ xml_doc = REXML::Document.new(xml)
27
+ test_string = try_xpaths(xml_doc, [
28
+ "ROOT/child/text()"
29
+ ], :select_result_value => true)
30
+ assert_equal("Test String #1", test_string)
31
+
32
+ xml = <<-XML
33
+ <root xmlns:TESTnAmEsPace="http://example.com/ns/">
34
+ <TESTnAmEsPace:ChIlD>Test String #2</TESTnAmEsPace:ChIlD>
35
+ </root>
36
+ XML
37
+ xml_doc = REXML::Document.new(xml)
38
+ test_string = try_xpaths(xml_doc, [
39
+ "ROOT/testnamespace:child/text()"
40
+ ], :select_result_value => true)
41
+ assert_equal("Test String #2", test_string)
42
+
43
+ xml = <<-XML
44
+ <RoOt>
45
+ <ChIlD AttRib="Test String #3" />
46
+ </RoOt>
47
+ XML
48
+ xml_doc = REXML::Document.new(xml)
49
+ test_string = try_xpaths(xml_doc, [
50
+ "ROOT/child/@ATTRIB"
51
+ ], :select_result_value => true)
52
+ assert_equal("Test String #3", test_string)
53
+
54
+ xml = <<-XML
55
+ <RoOt xmlns:TESTnAmEsPace="http://example.com/ns/">
56
+ <ChIlD TESTnAmEsPace:AttRib="Test String #4" />
57
+ </RoOt>
58
+ XML
59
+ xml_doc = REXML::Document.new(xml)
60
+ test_string = try_xpaths(xml_doc, [
61
+ "ROOT/child/@testnamespace:ATTRIB"
62
+ ], :select_result_value => true)
63
+ assert_equal("Test String #4", test_string)
64
+ end
65
+
13
66
  def test_escape_entities
14
67
  end
15
68
 
@@ -19,7 +72,9 @@ class HelperTest < Test::Unit::TestCase
19
72
  def test_normalize_url
20
73
  assert_equal("http://slashdot.org/",
21
74
  FeedTools.normalize_url("slashdot.org"))
22
-
75
+ assert_equal("http://example.com/index.php",
76
+ FeedTools.normalize_url("example.com/index.php"))
77
+
23
78
  # Test windows-style file: protocol normalization
24
79
  assert_equal("file:///c:/windows/My%20Documents%20100%20/foo.txt",
25
80
  FeedTools.normalize_url("c:\\windows\\My Documents 100%20\\foo.txt"))
@@ -36,10 +91,15 @@ class HelperTest < Test::Unit::TestCase
36
91
 
37
92
  def test_sanitize_html
38
93
  assert_equal("<!--foo-->", FeedTools.sanitize_html("<!--foo-->"))
94
+ assert_equal("<P>Upper-case tags</P>",
95
+ FeedTools.sanitize_html("<P>Upper-case tags</P>"))
96
+ assert_equal("<A HREF='/dev/null'>Upper-case attributes</A>",
97
+ FeedTools.sanitize_html(
98
+ "<A HREF='/dev/null'>Upper-case attributes</A>"))
39
99
  end
40
100
 
41
101
  def test_tidy_html
42
- FeedTools.tidy_enabled = true
102
+ FeedTools.configurations[:tidy_enabled] = true
43
103
  unless FeedTools.tidy_enabled?
44
104
  puts "\nCould not test tidy support. Libtidy couldn't be found."
45
105
  else
@@ -78,7 +138,7 @@ class HelperTest < Test::Unit::TestCase
78
138
  assert_not_equal(nil, illegal_pre_after_tidy =~ /class HTTPIO &lt; HTTP/,
79
139
  "Tidy failed to clean up illegal chars in <pre> block.")
80
140
  end
81
- FeedTools.tidy_enabled = false
141
+ FeedTools.configurations[:tidy_enabled] = false
82
142
  end
83
143
 
84
144
  def test_build_urn_uri