feedtools 0.2.17 → 0.2.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/lib/feed_tools.rb +34 -12
- data/lib/feed_tools/database_feed_cache.rb +24 -0
- data/lib/feed_tools/feed.rb +238 -82
- data/lib/feed_tools/feed_item.rb +218 -106
- data/lib/feed_tools/helpers/feed_helper.rb +27 -0
- data/lib/feed_tools/helpers/feed_item_helper.rb +27 -0
- data/lib/feed_tools/helpers/feed_tools_helper.rb +78 -0
- data/lib/feed_tools/helpers/generic_helper.rb +36 -0
- data/lib/feed_tools/helpers/module_helper.rb +27 -0
- data/rakefile +2 -2
- data/test/unit/amp_test.rb +406 -398
- data/test/unit/atom_test.rb +41 -16
- data/test/unit/cdf_test.rb +55 -49
- data/test/unit/generation_test.rb +1 -1
- data/test/unit/helper_test.rb +4 -0
- data/test/unit/nonstandard_test.rb +58 -50
- data/test/unit/rss_test.rb +510 -530
- metadata +8 -2
data/test/unit/atom_test.rb
CHANGED
@@ -1,28 +1,52 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'feed_tools'
|
3
|
+
require 'feed_tools/helpers/feed_tools_helper'
|
3
4
|
|
4
5
|
class AtomTest < Test::Unit::TestCase
|
6
|
+
include FeedToolsHelper
|
7
|
+
|
5
8
|
def setup
|
6
9
|
FeedTools.tidy_enabled = false
|
7
10
|
FeedTools.feed_cache = FeedTools::DatabaseFeedCache
|
11
|
+
FeedToolsHelper.default_local_path =
|
12
|
+
File.expand_path(
|
13
|
+
File.expand_path(File.dirname(__FILE__)) + '/../feeds')
|
8
14
|
end
|
9
15
|
|
10
16
|
def test_feed_title
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
with_feed(:from_file => 'wellformed/atom/atom_namespace_1.xml') { |feed|
|
18
|
+
assert_equal("Example Atom", feed.title)
|
19
|
+
}
|
20
|
+
with_feed(:from_file => 'wellformed/atom/atom_namespace_2.xml') { |feed|
|
21
|
+
assert_equal("Example Atom", feed.title)
|
22
|
+
}
|
23
|
+
with_feed(:from_file => 'wellformed/atom/atom_namespace_3.xml') { |feed|
|
24
|
+
assert_equal("Example Atom", feed.title)
|
25
|
+
}
|
26
|
+
with_feed(:from_file => 'wellformed/atom/atom_namespace_4.xml') { |feed|
|
27
|
+
assert_equal("Example Atom", feed.title)
|
28
|
+
}
|
29
|
+
with_feed(:from_file => 'wellformed/atom/atom_namespace_5.xml') { |feed|
|
30
|
+
assert_equal("Example Atom", feed.title)
|
31
|
+
}
|
32
|
+
with_feed(:from_file => 'wellformed/atom/feed_title_base64.xml') { |feed|
|
33
|
+
assert_equal("Example <b>Atom</b>", feed.title)
|
34
|
+
}
|
35
|
+
with_feed(:from_file =>
|
36
|
+
'wellformed/atom/feed_title_base64_2.xml') { |feed|
|
37
|
+
assert_equal("<p>History of the <blink> tag</p>", feed.title)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_copyright
|
42
|
+
with_feed(:from_file =>
|
43
|
+
'wellformed/atom/feed_copyright_base64.xml') { |feed|
|
44
|
+
assert_equal("Example <b>Atom</b>", feed.copyright)
|
45
|
+
}
|
46
|
+
with_feed(:from_file =>
|
47
|
+
'wellformed/atom/feed_copyright_base64_2.xml') { |feed|
|
48
|
+
assert_equal("<p>History of the <blink> tag</p>", feed.copyright)
|
49
|
+
}
|
26
50
|
end
|
27
51
|
|
28
52
|
def test_feed_author
|
@@ -30,4 +54,5 @@ class AtomTest < Test::Unit::TestCase
|
|
30
54
|
# 'http://feedparser.org/tests/wellformed/atom/atom_namespace_5.xml')
|
31
55
|
# assert_equal("Example Atom", feed.title)
|
32
56
|
end
|
33
|
-
end
|
57
|
+
end
|
58
|
+
|
data/test/unit/cdf_test.rb
CHANGED
@@ -1,46 +1,52 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'feed_tools'
|
3
|
+
require 'feed_tools/helpers/feed_tools_helper'
|
3
4
|
|
4
5
|
class CdfTest < Test::Unit::TestCase
|
6
|
+
include FeedToolsHelper
|
7
|
+
|
5
8
|
def setup
|
6
9
|
FeedTools.tidy_enabled = false
|
7
10
|
FeedTools.feed_cache = FeedTools::DatabaseFeedCache
|
11
|
+
FeedToolsHelper.default_local_path =
|
12
|
+
File.expand_path(
|
13
|
+
File.expand_path(File.dirname(__FILE__)) + '/../feeds')
|
8
14
|
end
|
9
15
|
|
10
16
|
def test_feed_title
|
11
|
-
|
12
|
-
feed.feed_data = <<-FEED
|
17
|
+
with_feed(:from_data => <<-FEED
|
13
18
|
<CHANNEL>
|
14
19
|
<TITLE>Example Title</TITLE>
|
15
20
|
</CHANNEL>
|
16
21
|
FEED
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
) { |feed|
|
23
|
+
assert_equal("Example Title", feed.title)
|
24
|
+
}
|
25
|
+
with_feed(:from_file => 'wellformed/cdf/channel_title.xml') { |feed|
|
20
26
|
assert_equal("Example feed", feed.title)
|
27
|
+
}
|
21
28
|
end
|
22
29
|
|
23
30
|
def test_feed_description
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
'channel_abstract_map_tagline.xml')
|
31
|
-
assert_equal("Example description", feed.tagline)
|
31
|
+
with_feed(:from_file => 'wellformed/cdf/channel_abstract_map_description.xml') { |feed|
|
32
|
+
assert_equal("Example description", feed.description)
|
33
|
+
}
|
34
|
+
with_feed(:from_file => 'wellformed/cdf/channel_abstract_map_tagline.xml') { |feed|
|
35
|
+
assert_equal("Example description", feed.tagline)
|
36
|
+
}
|
32
37
|
end
|
33
38
|
|
34
39
|
def test_feed_href
|
35
|
-
|
36
|
-
feed.feed_data = <<-FEED
|
40
|
+
with_feed(:from_data => <<-FEED
|
37
41
|
<CHANNEL HREF="http://www.example.com/">
|
38
42
|
</CHANNEL>
|
39
43
|
FEED
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
) { |feed|
|
45
|
+
assert_equal("http://www.example.com/", feed.link)
|
46
|
+
}
|
47
|
+
with_feed(:from_file => 'wellformed/cdf/channel_href_map_link.xml') { |feed|
|
48
|
+
assert_equal("http://www.example.org/", feed.link)
|
49
|
+
}
|
44
50
|
end
|
45
51
|
|
46
52
|
def test_feed_links
|
@@ -48,40 +54,39 @@ class CdfTest < Test::Unit::TestCase
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def test_feed_images
|
51
|
-
|
52
|
-
feed.feed_data = <<-FEED
|
57
|
+
with_feed(:from_data => <<-FEED
|
53
58
|
<CHANNEL>
|
54
59
|
<LOGO HREF="http://www.example.com/exampleicon.gif" STYLE="ICON" />
|
55
60
|
<LOGO HREF="http://www.example.com/exampleimage.gif" STYLE="IMAGE" />
|
56
61
|
</CHANNEL>
|
57
62
|
FEED
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
) { |feed|
|
64
|
+
assert_equal("http://www.example.com/exampleicon.gif", feed.images[0].url)
|
65
|
+
assert_equal("icon", feed.images[0].style)
|
66
|
+
assert_equal("http://www.example.com/exampleimage.gif", feed.images[1].url)
|
67
|
+
assert_equal("image", feed.images[1].style)
|
68
|
+
}
|
62
69
|
end
|
63
70
|
|
64
71
|
def test_feed_item_title
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
with_feed(:from_file => 'wellformed/cdf/item_title.xml') { |feed|
|
73
|
+
assert_equal("Example item", feed.items.first.title)
|
74
|
+
}
|
68
75
|
end
|
69
76
|
|
70
77
|
def test_feed_item_description
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
'item_abstract_map_summary.xml')
|
78
|
-
assert_equal("Example description", feed.items.first.summary)
|
78
|
+
with_feed(:from_file => 'wellformed/cdf/item_abstract_map_description.xml') { |feed|
|
79
|
+
assert_equal("Example description", feed.items.first.description)
|
80
|
+
}
|
81
|
+
with_feed(:from_file => 'wellformed/cdf/item_abstract_map_summary.xml') { |feed|
|
82
|
+
assert_equal("Example description", feed.items.first.summary)
|
83
|
+
}
|
79
84
|
end
|
80
85
|
|
81
86
|
def test_feed_item_href
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
with_feed(:from_file => 'wellformed/cdf/item_href_map_link.xml') { |feed|
|
88
|
+
assert_equal("http://www.example.org/", feed.items.first.link)
|
89
|
+
}
|
85
90
|
end
|
86
91
|
|
87
92
|
def test_feed_item_links
|
@@ -89,8 +94,7 @@ class CdfTest < Test::Unit::TestCase
|
|
89
94
|
end
|
90
95
|
|
91
96
|
def test_feed_item_images
|
92
|
-
|
93
|
-
feed.feed_data = <<-FEED
|
97
|
+
with_feed(:from_data => <<-FEED
|
94
98
|
<CHANNEL>
|
95
99
|
<ITEM HREF="http://www.example.com/item">
|
96
100
|
<LOGO HREF="http://www.example.com/exampleicon.gif" STYLE="ICON" />
|
@@ -98,13 +102,15 @@ class CdfTest < Test::Unit::TestCase
|
|
98
102
|
</ITEM>
|
99
103
|
</CHANNEL>
|
100
104
|
FEED
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
) { |feed|
|
106
|
+
assert_equal("http://www.example.com/item",
|
107
|
+
feed.items.first.link)
|
108
|
+
assert_equal("http://www.example.com/exampleicon.gif",
|
109
|
+
feed.items.first.images[0].url)
|
110
|
+
assert_equal("icon", feed.items.first.images[0].style)
|
111
|
+
assert_equal("http://www.example.com/exampleimage.gif",
|
112
|
+
feed.items.first.images[1].url)
|
113
|
+
assert_equal("image", feed.items.first.images[1].style)
|
114
|
+
}
|
109
115
|
end
|
110
116
|
end
|
data/test/unit/helper_test.rb
CHANGED
@@ -5,6 +5,9 @@ class HelperTest < Test::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
FeedTools.tidy_enabled = false
|
7
7
|
FeedTools.feed_cache = FeedTools::DatabaseFeedCache
|
8
|
+
FeedToolsHelper.default_local_path =
|
9
|
+
File.expand_path(
|
10
|
+
File.expand_path(File.dirname(__FILE__)) + '/../feeds')
|
8
11
|
end
|
9
12
|
|
10
13
|
def test_escape_entities
|
@@ -32,6 +35,7 @@ class HelperTest < Test::Unit::TestCase
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def test_sanitize_html
|
38
|
+
assert_equal("<!--foo-->", FeedTools.sanitize_html("<!--foo-->"))
|
35
39
|
end
|
36
40
|
|
37
41
|
def test_tidy_html
|
@@ -1,15 +1,20 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'feed_tools'
|
3
|
+
require 'feed_tools/helpers/feed_tools_helper'
|
3
4
|
|
4
5
|
class NonStandardTest < Test::Unit::TestCase
|
6
|
+
include FeedToolsHelper
|
7
|
+
|
5
8
|
def setup
|
6
9
|
FeedTools.tidy_enabled = false
|
7
10
|
FeedTools.feed_cache = FeedTools::DatabaseFeedCache
|
11
|
+
FeedToolsHelper.default_local_path =
|
12
|
+
File.expand_path(
|
13
|
+
File.expand_path(File.dirname(__FILE__)) + '/../feeds')
|
8
14
|
end
|
9
15
|
|
10
16
|
def test_xss_strict
|
11
|
-
|
12
|
-
feed.feed_data = <<-FEED
|
17
|
+
with_feed(:from_data => <<-FEED
|
13
18
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
14
19
|
<rss version="2.0/XSS-strict">
|
15
20
|
<channel>
|
@@ -44,30 +49,31 @@ class NonStandardTest < Test::Unit::TestCase
|
|
44
49
|
</channel>
|
45
50
|
</rss>
|
46
51
|
FEED
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
52
|
+
) { |feed|
|
53
|
+
assert_equal("tima thinking outloud.", feed.title)
|
54
|
+
assert_equal("http://www.timaoutloud.org/", feed.link)
|
55
|
+
assert_equal("The personal weblog of Timothy Appnel", feed.description)
|
56
|
+
|
57
|
+
assert_equal("OSCON Wrap-Up.", feed.items[0].title)
|
58
|
+
assert_equal("http://www.timaoutloud.org/archives/000415.html",
|
59
|
+
feed.items[0].link)
|
60
|
+
assert_equal(false, feed.items[0].description == nil)
|
61
|
+
|
62
|
+
assert_equal("Write For The People Who Support You.", feed.items[1].title)
|
63
|
+
assert_equal("http://www.timaoutloud.org/archives/000414.html",
|
64
|
+
feed.items[1].link)
|
65
|
+
assert_equal(false, feed.items[1].description == nil)
|
66
|
+
|
67
|
+
assert_equal("tima@OSCON", feed.items[2].title)
|
68
|
+
assert_equal("http://www.timaoutloud.org/archives/000413.html",
|
69
|
+
feed.items[2].link)
|
70
|
+
assert_equal(false, feed.items[2].description == nil)
|
71
|
+
}
|
65
72
|
end
|
66
73
|
|
67
74
|
def test_rss_30_lite
|
68
75
|
# Delusions of grandeur...
|
69
|
-
|
70
|
-
feed.feed_data = <<-FEED
|
76
|
+
with_feed(:from_data => <<-FEED
|
71
77
|
<?xml version="1.0" encoding="UTF-8"?>
|
72
78
|
<rss version="3.0" type="lite"
|
73
79
|
source="http://www.rss3.org/files/liteSample.rss">
|
@@ -116,33 +122,35 @@ class NonStandardTest < Test::Unit::TestCase
|
|
116
122
|
</channel>
|
117
123
|
</rss>
|
118
124
|
FEED
|
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
|
-
|
125
|
+
) { |feed|
|
126
|
+
assert_equal("RSS Version 3", feed.title)
|
127
|
+
assert_equal("http://www.rss3.org/", feed.link)
|
128
|
+
assert_equal("This is a sample RSS 3 Lite-type feed", feed.description)
|
129
|
+
assert_equal("http://no.address/", feed.generator)
|
130
|
+
assert_equal("en", feed.language)
|
131
|
+
assert_equal("http://www.rss3.org/files/r1.ico", feed.icon)
|
132
|
+
assert_equal("Jonathan Avidan 2005 (c)", feed.copyright)
|
133
|
+
assert_equal(7.day, feed.ttl)
|
134
|
+
assert_equal("http://www.rss3.org/rss3lite.html", feed.docs)
|
135
|
+
|
136
|
+
assert_equal("RSS 3 Lite First Draft Now Available", feed.items[0].title)
|
137
|
+
assert_equal("http://www.rss3.org/archive/rss3lite/first_draft.html",
|
138
|
+
feed.items[0].link)
|
139
|
+
assert_equal(false, feed.items[0].description == nil)
|
140
|
+
assert_equal(Time.utc(2005, "Aug", 18, 9, 53, 59), feed.items[0].time)
|
141
|
+
assert_equal("Jonathan Avidan", feed.items[0].author.name)
|
142
|
+
assert_equal("jonathan@rss3.org", feed.items[0].author.email)
|
143
|
+
assert_equal("6457894357689", feed.items[0].guid)
|
144
|
+
|
145
|
+
assert_equal("Welcome to the RSS 3 Official Blog!", feed.items[1].title)
|
146
|
+
assert_equal("http://www.rss3.org/official_blog/?p=2", feed.items[1].link)
|
147
|
+
assert_equal(false, feed.items[1].description == nil)
|
148
|
+
assert_equal("http://www.rss3.org/official_blog/?p=2#comments",
|
149
|
+
feed.items[1].comments)
|
150
|
+
assert_equal(Time.utc(2005, "Jul", 27, 14, 34, 51), feed.items[1].time)
|
151
|
+
assert_equal("Jonathan Avidan", feed.items[1].author.name)
|
152
|
+
assert_equal("jonathan@rss3.org", feed.items[1].author.email)
|
153
|
+
assert_equal("http://www.rss3.org/official_blog/?p=2", feed.items[1].guid)
|
154
|
+
}
|
147
155
|
end
|
148
156
|
end
|
data/test/unit/rss_test.rb
CHANGED
@@ -1,579 +1,553 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'feed_tools'
|
3
|
+
require 'feed_tools/helpers/feed_tools_helper'
|
3
4
|
|
4
5
|
class RssTest < Test::Unit::TestCase
|
6
|
+
include FeedToolsHelper
|
7
|
+
|
5
8
|
def setup
|
6
9
|
FeedTools.tidy_enabled = false
|
7
10
|
FeedTools.feed_cache = FeedTools::DatabaseFeedCache
|
11
|
+
FeedToolsHelper.default_local_path =
|
12
|
+
File.expand_path(
|
13
|
+
File.expand_path(File.dirname(__FILE__)) + '/../feeds')
|
8
14
|
end
|
9
15
|
|
10
16
|
def test_feed_well_formed
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
with_feed(:from_file => 'wellformed/rss/aaa_wellformed.xml') { |feed|
|
18
|
+
assert_not_nil feed
|
19
|
+
}
|
20
|
+
end
|
14
21
|
|
15
22
|
def test_feed_title
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
'
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
with_feed(:from_file => 'wellformed/rss/channel_title.xml') { |feed|
|
24
|
+
assert_equal("Example feed", feed.title)
|
25
|
+
}
|
26
|
+
with_feed(:from_file => 'wellformed/rss/channel_title_apos.xml') { |feed|
|
27
|
+
assert_equal("Mark's title", feed.title)
|
28
|
+
}
|
29
|
+
with_feed(:from_file => 'wellformed/rss/channel_title_gt.xml') { |feed|
|
30
|
+
assert_equal("2 > 1", feed.title)
|
31
|
+
}
|
32
|
+
with_feed(:from_file => 'wellformed/rss/channel_title_lt.xml') { |feed|
|
33
|
+
assert_equal("1 < 2", feed.title)
|
34
|
+
}
|
35
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_title.xml') { |feed|
|
36
|
+
assert_equal("Example title", feed.title)
|
37
|
+
}
|
31
38
|
end
|
32
39
|
|
33
40
|
def test_feed_description
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
'http://feedparser.org/tests/wellformed/rss/' +
|
52
|
-
'channel_description_shorttag.xml')
|
53
|
-
assert_equal(nil, feed.description)
|
54
|
-
assert_equal('http://example.com/', feed.link)
|
41
|
+
with_feed(:from_file => 'wellformed/rss/channel_description.xml') { |feed|
|
42
|
+
assert_equal(nil, feed.title)
|
43
|
+
assert_equal("Example description", feed.description)
|
44
|
+
}
|
45
|
+
with_feed(:from_file => 'wellformed/rss/channel_description_escaped_markup.xml') { |feed|
|
46
|
+
assert_equal("<p>Example description</p>", feed.description)
|
47
|
+
}
|
48
|
+
with_feed(:from_file => 'wellformed/rss/channel_description_map_tagline.xml') { |feed|
|
49
|
+
assert_equal("Example description", feed.tagline)
|
50
|
+
}
|
51
|
+
with_feed(:from_file => 'wellformed/rss/channel_description_naked_markup.xml') { |feed|
|
52
|
+
assert_equal("<p>Example description</p>", feed.description)
|
53
|
+
}
|
54
|
+
with_feed(:from_file => 'wellformed/rss/channel_description_shorttag.xml') { |feed|
|
55
|
+
assert_equal(nil, feed.description)
|
56
|
+
assert_equal('http://example.com/', feed.link)
|
57
|
+
}
|
55
58
|
end
|
56
59
|
|
57
60
|
def test_feed_link
|
58
|
-
|
59
|
-
'http://
|
60
|
-
|
61
|
+
with_feed(:from_file => 'wellformed/rss/channel_link.xml') { |feed|
|
62
|
+
assert_equal('http://example.com/', feed.link)
|
63
|
+
}
|
61
64
|
end
|
62
65
|
|
63
66
|
def test_feed_generator
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
with_feed(:from_file => 'wellformed/rss/channel_generator.xml') { |feed|
|
68
|
+
assert_equal("Example generator", feed.generator)
|
69
|
+
}
|
67
70
|
end
|
68
71
|
|
69
72
|
def test_feed_docs
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
with_feed(:from_file => 'wellformed/rss/channel_docs.xml') { |feed|
|
74
|
+
assert_equal("http://www.example.com/", feed.docs)
|
75
|
+
}
|
73
76
|
end
|
74
77
|
|
75
78
|
def test_feed_ttl
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
+
with_feed(:from_file => 'wellformed/rss/channel_ttl.xml') { |feed|
|
80
|
+
assert_equal(1.hour, feed.ttl)
|
81
|
+
}
|
79
82
|
end
|
80
83
|
|
81
84
|
def test_feed_author
|
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
|
-
'/channel_managingEditor_map_author_detail_email.xml')
|
137
|
-
assert_equal("Example editor (me@example.com)", feed.author.raw)
|
138
|
-
assert_equal("Example editor", feed.author.name)
|
139
|
-
assert_equal("me@example.com", feed.author.email)
|
140
|
-
assert_equal(nil, feed.author.url)
|
85
|
+
with_feed(:from_file => 'wellformed/rss/channel_author.xml') { |feed|
|
86
|
+
assert_equal("Example editor (me@example.com)", feed.author.raw)
|
87
|
+
assert_equal("Example editor", feed.author.name)
|
88
|
+
assert_equal("me@example.com", feed.author.email)
|
89
|
+
assert_equal(nil, feed.author.url)
|
90
|
+
}
|
91
|
+
with_feed(:from_file => 'wellformed/rss/channel_author_map_author_detail_email_2.xml') { |feed|
|
92
|
+
assert_equal("Example editor (me+spam@example.com)", feed.author.raw)
|
93
|
+
assert_equal("Example editor", feed.author.name)
|
94
|
+
assert_equal("me+spam@example.com", feed.author.email)
|
95
|
+
assert_equal(nil, feed.author.url)
|
96
|
+
}
|
97
|
+
with_feed(:from_file => 'wellformed/rss/channel_author_map_author_detail_email_3.xml') { |feed|
|
98
|
+
assert_equal("me@example.com (Example editor)", feed.author.raw)
|
99
|
+
assert_equal("Example editor", feed.author.name)
|
100
|
+
assert_equal("me@example.com", feed.author.email)
|
101
|
+
assert_equal(nil, feed.author.url)
|
102
|
+
}
|
103
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_author.xml') { |feed|
|
104
|
+
assert_equal("Example editor", feed.author.raw)
|
105
|
+
assert_equal("Example editor", feed.author.name)
|
106
|
+
assert_equal(nil, feed.author.email)
|
107
|
+
assert_equal(nil, feed.author.url)
|
108
|
+
}
|
109
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_author_map_author_detail_email.xml') { |feed|
|
110
|
+
assert_equal("Example editor (me@example.com)", feed.author.raw)
|
111
|
+
assert_equal("Example editor", feed.author.name)
|
112
|
+
assert_equal("me@example.com", feed.author.email)
|
113
|
+
assert_equal(nil, feed.author.url)
|
114
|
+
}
|
115
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_creator.xml') { |feed|
|
116
|
+
assert_equal("Example editor", feed.author.raw)
|
117
|
+
assert_equal("Example editor", feed.author.name)
|
118
|
+
assert_equal(nil, feed.author.email)
|
119
|
+
assert_equal(nil, feed.author.url)
|
120
|
+
}
|
121
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_creator_map_author_detail_email.xml') { |feed|
|
122
|
+
assert_equal("Example editor (me@example.com)", feed.author.raw)
|
123
|
+
assert_equal("Example editor", feed.author.name)
|
124
|
+
assert_equal("me@example.com", feed.author.email)
|
125
|
+
assert_equal(nil, feed.author.url)
|
126
|
+
}
|
127
|
+
with_feed(:from_file => 'wellformed/rss/channel_managingEditor.xml') { |feed|
|
128
|
+
assert_equal("Example editor", feed.author.raw)
|
129
|
+
assert_equal("Example editor", feed.author.name)
|
130
|
+
assert_equal(nil, feed.author.email)
|
131
|
+
assert_equal(nil, feed.author.url)
|
132
|
+
}
|
133
|
+
with_feed(:from_file => 'wellformed/rss/channel_managingEditor_map_author_detail_email.xml') { |feed|
|
134
|
+
assert_equal("Example editor (me@example.com)", feed.author.raw)
|
135
|
+
assert_equal("Example editor", feed.author.name)
|
136
|
+
assert_equal("me@example.com", feed.author.email)
|
137
|
+
assert_equal(nil, feed.author.url)
|
138
|
+
}
|
141
139
|
end
|
142
140
|
|
143
141
|
def test_feed_publisher
|
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
|
-
assert_equal("me@example.com", feed.publisher.email)
|
169
|
-
assert_equal(nil, feed.publisher.url)
|
142
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_publisher.xml') { |feed|
|
143
|
+
assert_equal("Example editor", feed.publisher.raw)
|
144
|
+
assert_equal("Example editor", feed.publisher.name)
|
145
|
+
assert_equal(nil, feed.publisher.email)
|
146
|
+
assert_equal(nil, feed.publisher.url)
|
147
|
+
}
|
148
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_publisher_email.xml') { |feed|
|
149
|
+
assert_equal("Example editor (me@example.com)", feed.publisher.raw)
|
150
|
+
assert_equal("Example editor", feed.publisher.name)
|
151
|
+
assert_equal("me@example.com", feed.publisher.email)
|
152
|
+
assert_equal(nil, feed.publisher.url)
|
153
|
+
}
|
154
|
+
with_feed(:from_file => 'wellformed/rss/channel_webMaster.xml') { |feed|
|
155
|
+
assert_equal("Example editor", feed.publisher.raw)
|
156
|
+
assert_equal("Example editor", feed.publisher.name)
|
157
|
+
assert_equal(nil, feed.publisher.email)
|
158
|
+
assert_equal(nil, feed.publisher.url)
|
159
|
+
}
|
160
|
+
with_feed(:from_file => 'wellformed/rss/channel_webMaster_email.xml') { |feed|
|
161
|
+
assert_equal("Example editor (me@example.com)", feed.publisher.raw)
|
162
|
+
assert_equal("Example editor", feed.publisher.name)
|
163
|
+
assert_equal("me@example.com", feed.publisher.email)
|
164
|
+
assert_equal(nil, feed.publisher.url)
|
165
|
+
}
|
170
166
|
end
|
171
167
|
|
172
168
|
def test_feed_categories
|
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
|
-
assert_equal("Example category 1", feed.categories[0].value)
|
208
|
-
assert_equal(nil, feed.categories[0].domain)
|
209
|
-
assert_equal("Example category 2", feed.categories[1].value)
|
210
|
-
assert_equal(nil, feed.categories[1].domain)
|
169
|
+
with_feed(:from_file => 'wellformed/rss/channel_category.xml') { |feed|
|
170
|
+
assert_equal(1, feed.categories.size)
|
171
|
+
assert_equal("Example category", feed.categories.first.value)
|
172
|
+
}
|
173
|
+
with_feed(:from_file => 'wellformed/rss/channel_category_domain.xml') { |feed|
|
174
|
+
assert_equal(1, feed.categories.size)
|
175
|
+
assert_equal("Example category", feed.categories.first.value)
|
176
|
+
assert_equal("http://www.example.com/", feed.categories.first.domain)
|
177
|
+
}
|
178
|
+
with_feed(:from_file => 'wellformed/rss/channel_category_multiple.xml') { |feed|
|
179
|
+
assert_equal(2, feed.categories.size)
|
180
|
+
assert_equal("Example category 1", feed.categories[0].value)
|
181
|
+
assert_equal("http://www.example.com/1", feed.categories[0].domain)
|
182
|
+
assert_equal("Example category 2", feed.categories[1].value)
|
183
|
+
assert_equal("http://www.example.com/2", feed.categories[1].domain)
|
184
|
+
}
|
185
|
+
with_feed(:from_file => 'wellformed/rss/channel_category_multiple_2.xml') { |feed|
|
186
|
+
assert_equal(2, feed.categories.size)
|
187
|
+
assert_equal("Example category 1", feed.categories[0].value)
|
188
|
+
assert_equal(nil, feed.categories[0].domain)
|
189
|
+
assert_equal("Example category 2", feed.categories[1].value)
|
190
|
+
assert_equal(nil, feed.categories[1].domain)
|
191
|
+
}
|
192
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_subject.xml') { |feed|
|
193
|
+
assert_equal(1, feed.categories.size)
|
194
|
+
assert_equal("Example category", feed.categories.first.value)
|
195
|
+
}
|
196
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_subject_multiple.xml') { |feed|
|
197
|
+
assert_equal(2, feed.categories.size)
|
198
|
+
assert_equal("Example category 1", feed.categories[0].value)
|
199
|
+
assert_equal(nil, feed.categories[0].domain)
|
200
|
+
assert_equal("Example category 2", feed.categories[1].value)
|
201
|
+
assert_equal(nil, feed.categories[1].domain)
|
202
|
+
}
|
211
203
|
end
|
212
204
|
|
213
205
|
def test_feed_copyright
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
206
|
+
with_feed(:from_file => 'wellformed/rss/channel_copyright.xml') { |feed|
|
207
|
+
assert_equal("Example copyright", feed.copyright)
|
208
|
+
}
|
209
|
+
with_feed(:from_file => 'wellformed/rss/channel_dc_rights.xml') { |feed|
|
210
|
+
assert_equal("Example copyright", feed.copyright)
|
211
|
+
}
|
220
212
|
end
|
221
213
|
|
222
214
|
def test_feed_cloud
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
215
|
+
with_feed(:from_file => 'wellformed/rss/channel_cloud_domain.xml') { |feed|
|
216
|
+
assert_equal("rpc.sys.com", feed.cloud.domain)
|
217
|
+
assert_equal(80, feed.cloud.port)
|
218
|
+
assert_equal("/RPC2", feed.cloud.path)
|
219
|
+
assert_equal("myCloud.rssPleaseNotify", feed.cloud.register_procedure)
|
220
|
+
assert_equal("xml-rpc", feed.cloud.protocol)
|
221
|
+
}
|
230
222
|
end
|
231
223
|
|
232
224
|
def test_feed_time_to_live
|
233
|
-
|
234
|
-
|
235
|
-
|
225
|
+
with_feed(:from_file => 'wellformed/rss/channel_ttl.xml') { |feed|
|
226
|
+
assert_equal(1.hour, feed.time_to_live)
|
227
|
+
}
|
236
228
|
end
|
237
229
|
|
238
230
|
def test_feed_images
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
feed.images.first.
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
assert_equal(15, feed.images.first.height)
|
231
|
+
with_feed(:from_file => 'wellformed/rss/channel_image_description.xml') { |feed|
|
232
|
+
assert_equal("Sample image", feed.images.first.title)
|
233
|
+
assert_equal("Available in Netscape RSS 0.91",
|
234
|
+
feed.images.first.description)
|
235
|
+
assert_equal("http://example.org/url", feed.images.first.url)
|
236
|
+
assert_equal("http://example.org/link", feed.images.first.link)
|
237
|
+
assert_equal(80, feed.images.first.width)
|
238
|
+
assert_equal(15, feed.images.first.height)
|
239
|
+
}
|
249
240
|
end
|
250
241
|
|
251
242
|
def test_feed_text_input
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
assert_equal(nil, feed.text_input.link)
|
243
|
+
with_feed(:from_file => 'wellformed/rss/channel_textInput_description.xml') { |feed|
|
244
|
+
assert_equal("Real title", feed.title)
|
245
|
+
assert_equal("Real description", feed.description)
|
246
|
+
assert_equal("textInput title", feed.text_input.title)
|
247
|
+
assert_equal("textInput description", feed.text_input.description)
|
248
|
+
assert_equal(nil, feed.text_input.link)
|
249
|
+
assert_equal(nil, feed.text_input.name)
|
250
|
+
}
|
251
|
+
with_feed(:from_file => 'wellformed/rss/channel_textInput_link.xml') { |feed|
|
252
|
+
assert_equal("http://channel.example.com/", feed.link)
|
253
|
+
assert_equal("http://textinput.example.com/", feed.text_input.link)
|
254
|
+
assert_equal(nil, feed.text_input.title)
|
255
|
+
assert_equal(nil, feed.text_input.description)
|
256
|
+
assert_equal(nil, feed.text_input.name)
|
257
|
+
}
|
258
|
+
with_feed(:from_file => 'wellformed/rss/channel_textInput_name.xml') { |feed|
|
259
|
+
assert_equal("textinput name", feed.text_input.name)
|
260
|
+
assert_equal(nil, feed.text_input.title)
|
261
|
+
assert_equal(nil, feed.text_input.description)
|
262
|
+
assert_equal(nil, feed.text_input.link)
|
263
|
+
}
|
274
264
|
end
|
275
265
|
|
276
266
|
def test_item_title
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
267
|
+
with_feed(:from_file => 'wellformed/rss/item_title.xml') { |feed|
|
268
|
+
assert_equal("Item 1 title", feed.items.first.title)
|
269
|
+
assert_equal(nil, feed.items.first.description)
|
270
|
+
}
|
271
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_title.xml') { |feed|
|
272
|
+
assert_equal("Example title", feed.items.first.title)
|
273
|
+
assert_equal(nil, feed.items.first.description)
|
274
|
+
}
|
285
275
|
end
|
286
276
|
|
287
277
|
def test_item_description
|
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
|
-
feed = FeedTools::Feed.open(
|
321
|
-
'http://feedparser.org/tests/wellformed/rss/item_xhtml_body.xml')
|
322
|
-
assert_equal('<p>Example content</p>', feed.entries.first.description)
|
323
|
-
assert_equal(nil, feed.entries.first.title)
|
278
|
+
with_feed(:from_file => 'wellformed/rss/item_description.xml') { |feed|
|
279
|
+
assert_equal('Example description', feed.entries.first.description)
|
280
|
+
assert_equal(nil, feed.entries.first.title)
|
281
|
+
}
|
282
|
+
with_feed(:from_file => 'wellformed/rss/item_description_escaped_markup.xml') { |feed|
|
283
|
+
assert_equal('<p>Example description</p>', feed.entries.first.description)
|
284
|
+
assert_equal(nil, feed.entries.first.title)
|
285
|
+
}
|
286
|
+
with_feed(:from_file => 'wellformed/rss/item_description_map_summary.xml') { |feed|
|
287
|
+
assert_equal('Example description', feed.entries.first.description)
|
288
|
+
assert_equal(nil, feed.entries.first.title)
|
289
|
+
}
|
290
|
+
with_feed(:from_file => 'wellformed/rss/item_description_naked_markup.xml') { |feed|
|
291
|
+
assert_equal('<p>Example description</p>', feed.entries.first.description)
|
292
|
+
assert_equal(nil, feed.entries.first.title)
|
293
|
+
}
|
294
|
+
with_feed(:from_file => 'wellformed/rss/item_description_not_a_doctype.xml') { |feed|
|
295
|
+
assert_equal('<!\' <a href="foo">', feed.entries.first.description)
|
296
|
+
assert_equal(nil, feed.entries.first.title)
|
297
|
+
}
|
298
|
+
with_feed(:from_file => 'wellformed/rss/item_content_encoded.xml') { |feed|
|
299
|
+
assert_equal('<p>Example content</p>', feed.entries.first.content)
|
300
|
+
assert_equal(nil, feed.entries.first.title)
|
301
|
+
}
|
302
|
+
with_feed(:from_file => 'wellformed/rss/item_fullitem.xml') { |feed|
|
303
|
+
assert_equal('<p>Example content</p>', feed.entries.first.content)
|
304
|
+
assert_equal(nil, feed.entries.first.title)
|
305
|
+
}
|
306
|
+
with_feed(:from_file => 'wellformed/rss/item_xhtml_body.xml') { |feed|
|
307
|
+
assert_equal('<p>Example content</p>', feed.entries.first.description)
|
308
|
+
assert_equal(nil, feed.entries.first.title)
|
309
|
+
}
|
324
310
|
end
|
325
311
|
|
326
312
|
def test_item_link
|
327
|
-
|
328
|
-
'http://
|
329
|
-
|
330
|
-
|
331
|
-
|
313
|
+
with_feed(:from_file => 'wellformed/rss/item_link.xml') { |feed|
|
314
|
+
assert_equal('http://example.com/', feed.entries.first.link)
|
315
|
+
assert_equal(nil, feed.entries.first.title)
|
316
|
+
assert_equal(nil, feed.entries.first.description)
|
317
|
+
}
|
332
318
|
end
|
333
319
|
|
334
320
|
def test_item_guid
|
335
|
-
|
336
|
-
'http://
|
337
|
-
|
338
|
-
|
339
|
-
'http://
|
340
|
-
'
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
'http://
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
'http://
|
349
|
-
|
350
|
-
assert_equal('http://guid.example.com/', feed.entries.first.guid)
|
351
|
-
assert_equal('http://guid.example.com/', feed.entries.first.link)
|
321
|
+
with_feed(:from_file => 'wellformed/rss/item_guid.xml') { |feed|
|
322
|
+
assert_equal('http://guid.example.com/', feed.entries.first.guid)
|
323
|
+
}
|
324
|
+
with_feed(:from_file => 'wellformed/rss/item_guid_conflict_link.xml') { |feed|
|
325
|
+
assert_equal('http://guid.example.com/', feed.entries.first.guid)
|
326
|
+
assert_equal('http://link.example.com/', feed.entries.first.link)
|
327
|
+
}
|
328
|
+
with_feed(:from_file => 'wellformed/rss/item_guid_guidislink.xml') { |feed|
|
329
|
+
assert_equal('http://guid.example.com/', feed.entries.first.guid)
|
330
|
+
assert_equal('http://guid.example.com/', feed.entries.first.link)
|
331
|
+
}
|
332
|
+
with_feed(:from_file => 'wellformed/rss/item_guid_isPermaLink_map_link.xml') { |feed|
|
333
|
+
assert_equal('http://guid.example.com/', feed.entries.first.guid)
|
334
|
+
assert_equal('http://guid.example.com/', feed.entries.first.link)
|
335
|
+
}
|
352
336
|
end
|
353
337
|
|
354
338
|
def test_item_author
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
feed.items.first.author.
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
feed.items.first.author.
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
assert_equal("Example editor", feed.items.first.author.name)
|
395
|
-
assert_equal("me@example.com", feed.items.first.author.email)
|
396
|
-
assert_equal(nil, feed.items.first.author.url)
|
339
|
+
with_feed(:from_file => 'wellformed/rss/item_author.xml') { |feed|
|
340
|
+
assert_equal("Example editor", feed.items.first.author.raw)
|
341
|
+
assert_equal("Example editor", feed.items.first.author.name)
|
342
|
+
assert_equal(nil, feed.items.first.author.email)
|
343
|
+
assert_equal(nil, feed.items.first.author.url)
|
344
|
+
}
|
345
|
+
with_feed(:from_file => 'wellformed/rss/item_author_map_author_detail_email.xml') { |feed|
|
346
|
+
assert_equal("Example editor (me@example.com)",
|
347
|
+
feed.items.first.author.raw)
|
348
|
+
assert_equal("Example editor", feed.items.first.author.name)
|
349
|
+
assert_equal("me@example.com", feed.items.first.author.email)
|
350
|
+
assert_equal(nil, feed.items.first.author.url)
|
351
|
+
}
|
352
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_author.xml') { |feed|
|
353
|
+
assert_equal("Example editor", feed.items.first.author.raw)
|
354
|
+
assert_equal("Example editor", feed.items.first.author.name)
|
355
|
+
assert_equal(nil, feed.items.first.author.email)
|
356
|
+
assert_equal(nil, feed.items.first.author.url)
|
357
|
+
}
|
358
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_author_map_author_detail_email.xml') { |feed|
|
359
|
+
assert_equal("Example editor (me@example.com)",
|
360
|
+
feed.items.first.author.raw)
|
361
|
+
assert_equal("Example editor", feed.items.first.author.name)
|
362
|
+
assert_equal("me@example.com", feed.items.first.author.email)
|
363
|
+
assert_equal(nil, feed.items.first.author.url)
|
364
|
+
}
|
365
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_creator.xml') { |feed|
|
366
|
+
assert_equal("Example editor", feed.items.first.author.raw)
|
367
|
+
assert_equal("Example editor", feed.items.first.author.name)
|
368
|
+
assert_equal(nil, feed.items.first.author.email)
|
369
|
+
assert_equal(nil, feed.items.first.author.url)
|
370
|
+
}
|
371
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_creator_map_author_detail_email.xml') { |feed|
|
372
|
+
assert_equal("Example editor (me@example.com)",
|
373
|
+
feed.items.first.author.raw)
|
374
|
+
assert_equal("Example editor", feed.items.first.author.name)
|
375
|
+
assert_equal("me@example.com", feed.items.first.author.email)
|
376
|
+
assert_equal(nil, feed.items.first.author.url)
|
377
|
+
}
|
397
378
|
end
|
398
379
|
|
399
380
|
def test_item_publisher
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
assert_equal(nil, feed.items.first.publisher.url)
|
381
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_publisher.xml') { |feed|
|
382
|
+
assert_equal("Example editor", feed.items.first.publisher.raw)
|
383
|
+
assert_equal("Example editor", feed.items.first.publisher.name)
|
384
|
+
assert_equal(nil, feed.items.first.publisher.email)
|
385
|
+
assert_equal(nil, feed.items.first.publisher.url)
|
386
|
+
}
|
387
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_publisher_email.xml') { |feed|
|
388
|
+
assert_equal("Example editor (me@example.com)", feed.items.first.publisher.raw)
|
389
|
+
assert_equal("Example editor", feed.items.first.publisher.name)
|
390
|
+
assert_equal("me@example.com", feed.items.first.publisher.email)
|
391
|
+
assert_equal(nil, feed.items.first.publisher.url)
|
392
|
+
}
|
413
393
|
end
|
414
394
|
|
415
395
|
def test_item_categories
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
feed.items.first.categories
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
feed.items.first.categories[
|
445
|
-
|
446
|
-
|
447
|
-
feed.items.first.categories
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
assert_equal("Example category 1", feed.items.first.categories[0].value)
|
458
|
-
assert_equal(nil, feed.items.first.categories[0].domain)
|
459
|
-
assert_equal("Example category 2", feed.items.first.categories[1].value)
|
460
|
-
assert_equal(nil, feed.items.first.categories[1].domain)
|
396
|
+
with_feed(:from_file => 'wellformed/rss/item_category.xml') { |feed|
|
397
|
+
assert_equal(1, feed.items.first.categories.size)
|
398
|
+
assert_equal("Example category", feed.items.first.categories.first.value)
|
399
|
+
}
|
400
|
+
with_feed(:from_file => 'wellformed/rss/item_category_domain.xml') { |feed|
|
401
|
+
assert_equal(1, feed.items.first.categories.size)
|
402
|
+
assert_equal("Example category", feed.items.first.categories.first.value)
|
403
|
+
assert_equal("http://www.example.com/",
|
404
|
+
feed.items.first.categories.first.domain)
|
405
|
+
}
|
406
|
+
with_feed(:from_file => 'wellformed/rss/item_category_multiple.xml') { |feed|
|
407
|
+
assert_equal(2, feed.items.first.categories.size)
|
408
|
+
assert_equal("Example category 1",
|
409
|
+
feed.items.first.categories[0].value)
|
410
|
+
assert_equal("http://www.example.com/1",
|
411
|
+
feed.items.first.categories[0].domain)
|
412
|
+
assert_equal("Example category 2",
|
413
|
+
feed.items.first.categories[1].value)
|
414
|
+
assert_equal("http://www.example.com/2",
|
415
|
+
feed.items.first.categories[1].domain)
|
416
|
+
}
|
417
|
+
with_feed(:from_file => 'wellformed/rss/item_category_multiple_2.xml') { |feed|
|
418
|
+
assert_equal(2, feed.items.first.categories.size)
|
419
|
+
assert_equal("Example category 1",
|
420
|
+
feed.items.first.categories[0].value)
|
421
|
+
assert_equal(nil, feed.items.first.categories[0].domain)
|
422
|
+
assert_equal("Example category 2",
|
423
|
+
feed.items.first.categories[1].value)
|
424
|
+
assert_equal(nil, feed.items.first.categories[1].domain)
|
425
|
+
}
|
426
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_subject.xml') { |feed|
|
427
|
+
assert_equal(1, feed.items.first.categories.size)
|
428
|
+
assert_equal("Example category", feed.items.first.categories.first.value)
|
429
|
+
}
|
430
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_subject_multiple.xml') { |feed|
|
431
|
+
assert_equal(2, feed.items.first.categories.size)
|
432
|
+
assert_equal("Example category 1", feed.items.first.categories[0].value)
|
433
|
+
assert_equal(nil, feed.items.first.categories[0].domain)
|
434
|
+
assert_equal("Example category 2", feed.items.first.categories[1].value)
|
435
|
+
assert_equal(nil, feed.items.first.categories[1].domain)
|
436
|
+
}
|
461
437
|
end
|
462
438
|
|
463
439
|
def test_item_copyright
|
464
|
-
|
465
|
-
|
466
|
-
|
440
|
+
with_feed(:from_file => 'wellformed/rss/item_dc_rights.xml') { |feed|
|
441
|
+
assert_equal("Example copyright", feed.items.first.copyright)
|
442
|
+
}
|
467
443
|
end
|
468
444
|
|
469
445
|
def test_item_comments
|
470
|
-
|
471
|
-
|
472
|
-
|
446
|
+
with_feed(:from_file => 'wellformed/rss/item_comments.xml') { |feed|
|
447
|
+
assert_equal("http://example.com/", feed.items.first.comments)
|
448
|
+
}
|
473
449
|
end
|
474
450
|
|
475
451
|
def test_item_enclosures
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
feed.items.first.enclosures[0].
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
feed.items.first.enclosures[0].
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
feed.items.first.enclosures[1].
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
assert_equal(nil, feed.items.first.description)
|
452
|
+
with_feed(:from_file => 'wellformed/rss/item_enclosure_length.xml') { |feed|
|
453
|
+
assert_equal("http://example.com/", feed.items.first.link)
|
454
|
+
assert_equal("http://example.com/",
|
455
|
+
feed.items.first.enclosures[0].link)
|
456
|
+
assert_equal(100000, feed.items.first.enclosures[0].file_size)
|
457
|
+
assert_equal("image/jpeg", feed.items.first.enclosures[0].type)
|
458
|
+
assert_equal(nil, feed.items.first.title)
|
459
|
+
assert_equal(nil, feed.items.first.description)
|
460
|
+
}
|
461
|
+
with_feed(:from_file => 'wellformed/rss/item_enclosure_multiple.xml') { |feed|
|
462
|
+
assert_equal("http://example.com/", feed.items.first.link)
|
463
|
+
assert_equal("http://example.com/1",
|
464
|
+
feed.items.first.enclosures[0].link)
|
465
|
+
assert_equal(100000, feed.items.first.enclosures[0].file_size)
|
466
|
+
assert_equal("image/jpeg", feed.items.first.enclosures[0].type)
|
467
|
+
assert_equal("http://example.com/2",
|
468
|
+
feed.items.first.enclosures[1].link)
|
469
|
+
assert_equal(200000, feed.items.first.enclosures[1].file_size)
|
470
|
+
assert_equal("image/gif", feed.items.first.enclosures[1].type)
|
471
|
+
assert_equal(nil, feed.items.first.title)
|
472
|
+
assert_equal(nil, feed.items.first.description)
|
473
|
+
}
|
499
474
|
end
|
500
475
|
|
501
476
|
def test_item_source
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
477
|
+
with_feed(:from_file => 'wellformed/rss/item_source.xml') { |feed|
|
478
|
+
assert_equal("http://example.com/", feed.items.first.source.url)
|
479
|
+
assert_equal("Example source", feed.items.first.source.value)
|
480
|
+
}
|
506
481
|
end
|
507
482
|
|
508
483
|
# This doesn't *really* test much since FeedTools isn't a namespace
|
509
484
|
# aware parser yet. Mostly it just verifies that switching namepaces
|
510
485
|
# doesn't make the feeds unreadable.
|
511
486
|
def test_namespaces
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
487
|
+
with_feed(:from_file => 'wellformed/rss/rss_namespace_1.xml') { |feed|
|
488
|
+
assert_equal("Example description", feed.description)
|
489
|
+
assert_equal(nil, feed.title)
|
490
|
+
}
|
491
|
+
with_feed(:from_file => 'wellformed/rss/rss_namespace_2.xml') { |feed|
|
492
|
+
assert_equal("Example description", feed.description)
|
493
|
+
assert_equal(nil, feed.title)
|
494
|
+
}
|
495
|
+
with_feed(:from_file => 'wellformed/rss/rss_namespace_3.xml') { |feed|
|
496
|
+
assert_equal("Example description", feed.description)
|
497
|
+
assert_equal(nil, feed.title)
|
498
|
+
}
|
499
|
+
with_feed(:from_file => 'wellformed/rss/rss_namespace_4.xml') { |feed|
|
500
|
+
assert_equal("Example description", feed.description)
|
501
|
+
assert_equal(nil, feed.title)
|
502
|
+
}
|
503
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_090.xml') { |feed|
|
504
|
+
assert_equal("rss", feed.feed_type)
|
505
|
+
assert_equal(0.9, feed.feed_version)
|
506
|
+
}
|
507
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_091_netscape.xml') { |feed|
|
508
|
+
assert_equal("rss", feed.feed_type)
|
509
|
+
assert_equal(0.91, feed.feed_version)
|
510
|
+
}
|
511
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_091_userland.xml') { |feed|
|
512
|
+
assert_equal("rss", feed.feed_type)
|
513
|
+
assert_equal(0.91, feed.feed_version)
|
514
|
+
}
|
515
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_092.xml') { |feed|
|
516
|
+
assert_equal("rss", feed.feed_type)
|
517
|
+
assert_equal(0.92, feed.feed_version)
|
518
|
+
}
|
519
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_093.xml') { |feed|
|
520
|
+
assert_equal("rss", feed.feed_type)
|
521
|
+
assert_equal(0.93, feed.feed_version)
|
522
|
+
}
|
523
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_094.xml') { |feed|
|
524
|
+
assert_equal("rss", feed.feed_type)
|
525
|
+
assert_equal(0.94, feed.feed_version)
|
526
|
+
}
|
527
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_20.xml') { |feed|
|
528
|
+
assert_equal("rss", feed.feed_type)
|
529
|
+
assert_equal(2.0, feed.feed_version)
|
530
|
+
}
|
531
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_201.xml') { |feed|
|
532
|
+
assert_equal("rss", feed.feed_type)
|
533
|
+
assert_equal(2.0, feed.feed_version)
|
534
|
+
}
|
535
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_21.xml') { |feed|
|
536
|
+
assert_equal("rss", feed.feed_type)
|
537
|
+
assert_equal(2.0, feed.feed_version)
|
538
|
+
}
|
539
|
+
with_feed(:from_file => 'wellformed/rss/rss_version_missing.xml') { |feed|
|
540
|
+
assert_equal("rss", feed.feed_type)
|
541
|
+
assert_equal(nil, feed.feed_version)
|
542
|
+
}
|
568
543
|
end
|
569
544
|
|
570
545
|
def test_content_encoded
|
571
|
-
|
572
|
-
|
573
|
-
<
|
574
|
-
|
575
|
-
|
576
|
-
<title>Test Feed Title</title>
|
546
|
+
with_feed(:from_data => <<-FEED
|
547
|
+
<rss>
|
548
|
+
<channel>
|
549
|
+
<item>
|
550
|
+
<title>Test Feed Title</title>
|
577
551
|
<content:encoded
|
578
552
|
xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
579
553
|
<![CDATA[
|
@@ -584,82 +558,88 @@ class RssTest < Test::Unit::TestCase
|
|
584
558
|
</channel>
|
585
559
|
</rss>
|
586
560
|
FEED
|
587
|
-
|
588
|
-
|
561
|
+
) { |feed|
|
562
|
+
assert_equal("Test Feed Title", feed.items.first.title)
|
563
|
+
assert_equal("Test Feed Content", feed.items.first.content)
|
564
|
+
}
|
589
565
|
end
|
590
566
|
|
591
567
|
def test_item_order
|
592
|
-
|
593
|
-
|
594
|
-
<
|
595
|
-
|
596
|
-
|
597
|
-
<title>Item 1</title>
|
568
|
+
with_feed(:from_data => <<-FEED
|
569
|
+
<rss>
|
570
|
+
<channel>
|
571
|
+
<item>
|
572
|
+
<title>Item 1</title>
|
598
573
|
</item>
|
599
|
-
|
600
|
-
|
574
|
+
<item>
|
575
|
+
<title>Item 2</title>
|
601
576
|
</item>
|
602
|
-
|
603
|
-
|
577
|
+
<item>
|
578
|
+
<title>Item 3</title>
|
604
579
|
</item>
|
605
|
-
|
580
|
+
</channel>
|
606
581
|
</rss>
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
582
|
+
FEED
|
583
|
+
) { |feed|
|
584
|
+
assert_equal("Item 1", feed.items[0].title)
|
585
|
+
assert_equal("Item 2", feed.items[1].title)
|
586
|
+
assert_equal("Item 3", feed.items[2].title)
|
587
|
+
}
|
611
588
|
|
612
|
-
|
613
|
-
|
614
|
-
<
|
615
|
-
|
616
|
-
|
617
|
-
<title>Item 1</title>
|
589
|
+
with_feed(:from_data => <<-FEED
|
590
|
+
<rss>
|
591
|
+
<channel>
|
592
|
+
<item>
|
593
|
+
<title>Item 1</title>
|
618
594
|
</item>
|
619
|
-
|
620
|
-
|
595
|
+
<item>
|
596
|
+
<title>Item 2</title>
|
621
597
|
<pubDate>Thu, 13 Oct 2005 19:59:00 +0000</pubDate>
|
622
|
-
|
598
|
+
</item>
|
623
599
|
<item>
|
624
600
|
<title>Item 3</title>
|
625
|
-
|
601
|
+
</item>
|
626
602
|
</channel>
|
627
603
|
</rss>
|
628
604
|
FEED
|
629
|
-
|
630
|
-
|
631
|
-
|
605
|
+
) { |feed|
|
606
|
+
assert_equal("Item 1", feed.items[0].title)
|
607
|
+
assert_equal("Item 2", feed.items[1].title)
|
608
|
+
assert_equal("Item 3", feed.items[2].title)
|
609
|
+
}
|
632
610
|
end
|
633
611
|
|
634
612
|
def test_usm
|
635
|
-
|
636
|
-
|
637
|
-
<
|
638
|
-
|
639
|
-
|
640
|
-
<title>Feed Title</title>
|
613
|
+
with_feed(:from_data => <<-FEED
|
614
|
+
<rss xmlns:atom="http://www.w3.org/2005/Atom">
|
615
|
+
<channel>
|
616
|
+
<atom:link href="http://nowhere.com/feed.xml" rel="self" />
|
617
|
+
<title>Feed Title</title>
|
641
618
|
</channel>
|
642
619
|
</rss>
|
643
620
|
FEED
|
644
|
-
|
645
|
-
|
621
|
+
) { |feed|
|
622
|
+
assert_equal("http://nowhere.com/feed.xml", feed.url)
|
623
|
+
assert_equal("Feed Title", feed.title)
|
624
|
+
}
|
646
625
|
|
647
|
-
|
648
|
-
feed.feed_data = <<-FEED
|
626
|
+
with_feed(:from_data => <<-FEED
|
649
627
|
<rss xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
628
|
+
xmlns:admin="http://webns.net/mvcb/">
|
629
|
+
<channel>
|
630
|
+
<admin:feed rdf:resource="http://nowhere.com/feed.xml" />
|
631
|
+
<title>Feed Title</title>
|
654
632
|
</channel>
|
655
633
|
</rss>
|
656
634
|
FEED
|
657
|
-
|
658
|
-
|
635
|
+
) { |feed|
|
636
|
+
assert_equal("http://nowhere.com/feed.xml", feed.url)
|
637
|
+
assert_equal("Feed Title", feed.title)
|
638
|
+
}
|
659
639
|
end
|
660
640
|
|
661
641
|
def test_http_retrieval
|
662
642
|
# Just make sure this doesn't toss out any errors
|
663
643
|
FeedTools::Feed.open('http://scobleizer.wordpress.com/feed/')
|
664
644
|
end
|
665
|
-
end
|
645
|
+
end
|