rss-nokogiri 0.0.1
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.
- data/.gemtest +0 -0
- data/.gitignore +19 -0
- data/.gitmodules +3 -0
- data/BSDL +22 -0
- data/COPYING +56 -0
- data/COPYING.ja +51 -0
- data/Gemfile +4 -0
- data/LEGAL +8 -0
- data/README.markdown +51 -0
- data/Rakefile +12 -0
- data/lib/rss/nokogiri.rb +92 -0
- data/rss-nokogiri.gemspec +24 -0
- data/test/regression/dot.png +0 -0
- data/test/regression/rss-assertions.rb +2090 -0
- data/test/regression/rss-testcase.rb +478 -0
- data/test/regression/test_1.0.rb +295 -0
- data/test/regression/test_2.0.rb +409 -0
- data/test/regression/test_accessor.rb +103 -0
- data/test/regression/test_atom.rb +681 -0
- data/test/regression/test_content.rb +104 -0
- data/test/regression/test_dublincore.rb +279 -0
- data/test/regression/test_image.rb +214 -0
- data/test/regression/test_inherit.rb +40 -0
- data/test/regression/test_itunes.rb +347 -0
- data/test/regression/test_maker_0.9.rb +474 -0
- data/test/regression/test_maker_1.0.rb +516 -0
- data/test/regression/test_maker_2.0.rb +757 -0
- data/test/regression/test_maker_atom_entry.rb +393 -0
- data/test/regression/test_maker_atom_feed.rb +454 -0
- data/test/regression/test_maker_content.rb +47 -0
- data/test/regression/test_maker_dc.rb +149 -0
- data/test/regression/test_maker_image.rb +62 -0
- data/test/regression/test_maker_itunes.rb +471 -0
- data/test/regression/test_maker_slash.rb +37 -0
- data/test/regression/test_maker_sy.rb +44 -0
- data/test/regression/test_maker_taxo.rb +81 -0
- data/test/regression/test_maker_trackback.rb +41 -0
- data/test/regression/test_maker_xml-stylesheet.rb +83 -0
- data/test/regression/test_parser.rb +62 -0
- data/test/regression/test_parser_1.0.rb +528 -0
- data/test/regression/test_parser_2.0.rb +122 -0
- data/test/regression/test_parser_atom_entry.rb +163 -0
- data/test/regression/test_parser_atom_feed.rb +276 -0
- data/test/regression/test_setup_maker_0.9.rb +246 -0
- data/test/regression/test_setup_maker_1.0.rb +550 -0
- data/test/regression/test_setup_maker_2.0.rb +308 -0
- data/test/regression/test_setup_maker_atom_entry.rb +409 -0
- data/test/regression/test_setup_maker_atom_feed.rb +445 -0
- data/test/regression/test_setup_maker_itunes.rb +144 -0
- data/test/regression/test_setup_maker_slash.rb +38 -0
- data/test/regression/test_slash.rb +64 -0
- data/test/regression/test_syndication.rb +125 -0
- data/test/regression/test_taxonomy.rb +172 -0
- data/test/regression/test_to_s.rb +670 -0
- data/test/regression/test_trackback.rb +135 -0
- data/test/regression/test_version.rb +9 -0
- data/test/regression/test_xml-stylesheet.rb +108 -0
- metadata +220 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "rss-testcase"
|
|
2
|
+
|
|
3
|
+
require "rss/maker"
|
|
4
|
+
|
|
5
|
+
module RSS
|
|
6
|
+
class TestMakerSlash < TestCase
|
|
7
|
+
def setup
|
|
8
|
+
@elements = {
|
|
9
|
+
"section" => "articles",
|
|
10
|
+
"department" => "not-an-ocean-unless-there-are-lobsters",
|
|
11
|
+
"comments" => 177,
|
|
12
|
+
"hit_parades" => [177, 155, 105, 33, 6, 3, 0],
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_rss10
|
|
17
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
18
|
+
setup_dummy_channel(maker)
|
|
19
|
+
|
|
20
|
+
setup_dummy_item(maker)
|
|
21
|
+
item = maker.items.last
|
|
22
|
+
@elements.each do |name, value|
|
|
23
|
+
item.send("slash_#{name}=", value)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
item = rss.items.last
|
|
28
|
+
assert_not_nil(item)
|
|
29
|
+
assert_slash_elements(item)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
def assert_slash_elements(target)
|
|
34
|
+
super(@elements, target)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "rss-testcase"
|
|
2
|
+
|
|
3
|
+
require "rss/maker"
|
|
4
|
+
|
|
5
|
+
module RSS
|
|
6
|
+
class TestMakerSyndication < TestCase
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@uri = "http://purl.org/rss/1.0/modules/syndication/"
|
|
10
|
+
|
|
11
|
+
t = Time.iso8601("2000-01-01T12:00:05+00:00")
|
|
12
|
+
class << t
|
|
13
|
+
alias_method(:to_s, :iso8601)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
@elements = {
|
|
17
|
+
:updatePeriod => "hourly",
|
|
18
|
+
:updateFrequency => "2",
|
|
19
|
+
:updateBase => t,
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_rss10
|
|
24
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
25
|
+
setup_dummy_channel(maker)
|
|
26
|
+
set_elements(maker.channel)
|
|
27
|
+
setup_dummy_item(maker)
|
|
28
|
+
end
|
|
29
|
+
assert_syndication(@elements, rss.channel)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
def accessor_name(name)
|
|
34
|
+
"sy_#{name}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def set_elements(target)
|
|
38
|
+
@elements.each do |name, value|
|
|
39
|
+
target.__send__("#{accessor_name(name)}=", value)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require "rss-testcase"
|
|
2
|
+
|
|
3
|
+
require "rss/maker"
|
|
4
|
+
|
|
5
|
+
module RSS
|
|
6
|
+
class TestMakerTaxonomy < TestCase
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@uri = "http://purl.org/rss/1.0/modules/taxonomy/"
|
|
10
|
+
|
|
11
|
+
@resources = [
|
|
12
|
+
"http://meerkat.oreillynet.com/?c=cat23",
|
|
13
|
+
"http://meerkat.oreillynet.com/?c=47",
|
|
14
|
+
"http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
@topics = [
|
|
18
|
+
{
|
|
19
|
+
:link => "http://meerkat.oreillynet.com/?c=cat23",
|
|
20
|
+
:title => "Data: XML",
|
|
21
|
+
:description => "A Meerkat channel",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
:link => "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
|
|
25
|
+
:title => "XML",
|
|
26
|
+
:subject => "XML",
|
|
27
|
+
:description => "DMOZ category",
|
|
28
|
+
:topics => [
|
|
29
|
+
"http://meerkat.oreillynet.com/?c=cat23",
|
|
30
|
+
"http://dmoz.org/Computers/Data_Formats/Markup_Languages/SGML/",
|
|
31
|
+
"http://dmoz.org/Computers/Programming/Internet/",
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_rss10
|
|
38
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
39
|
+
setup_dummy_channel(maker)
|
|
40
|
+
set_topics(maker.channel)
|
|
41
|
+
|
|
42
|
+
setup_dummy_item(maker)
|
|
43
|
+
set_topics(maker.items.last)
|
|
44
|
+
|
|
45
|
+
setup_taxo_topic(maker, @topics)
|
|
46
|
+
end
|
|
47
|
+
assert_equal(@resources, rss.channel.taxo_topics.resources)
|
|
48
|
+
assert_equal(@resources, rss.items.last.taxo_topics.resources)
|
|
49
|
+
assert_taxo_topic(@topics, rss)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def _test_date
|
|
53
|
+
t1 = Time.iso8601("2000-01-01T12:00:05+00:00")
|
|
54
|
+
t2 = Time.iso8601("2005-01-01T12:00:05+00:00")
|
|
55
|
+
|
|
56
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
57
|
+
setup_dummy_channel(maker)
|
|
58
|
+
maker.channel.date = t1
|
|
59
|
+
maker.channel.dc_dates.new_date do |date|
|
|
60
|
+
date.value = t2
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
setup_dummy_item(maker)
|
|
64
|
+
item = maker.items.last
|
|
65
|
+
item.date = t2
|
|
66
|
+
item.dc_dates.new_date do |date|
|
|
67
|
+
date.value = t1
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
assert_equal([t1, t2], rss.channel.dc_dates.collect{|x| x.value})
|
|
71
|
+
assert_equal([t2, t1], rss.items.last.dc_dates.collect{|x| x.value})
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
def set_topics(target, resources=@resources)
|
|
76
|
+
resources.each do |value|
|
|
77
|
+
target.taxo_topics << value
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "rss-testcase"
|
|
2
|
+
|
|
3
|
+
require "rss/maker"
|
|
4
|
+
|
|
5
|
+
module RSS
|
|
6
|
+
class TestMakerTrackBack < TestCase
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@uri = "http://madskills.com/public/xml/rss/module/trackback/"
|
|
10
|
+
|
|
11
|
+
@elements = {
|
|
12
|
+
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
|
|
13
|
+
:abouts => [
|
|
14
|
+
"http://foo.com/trackback/tb.cgi?tb_id=20020923",
|
|
15
|
+
"http://bar.com/trackback/tb.cgi?tb_id=20041114",
|
|
16
|
+
],
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_rss10
|
|
21
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
22
|
+
setup_dummy_channel(maker)
|
|
23
|
+
|
|
24
|
+
setup_dummy_item(maker)
|
|
25
|
+
item = maker.items.last
|
|
26
|
+
item.trackback_ping = @elements[:ping]
|
|
27
|
+
@elements[:abouts].each do |about|
|
|
28
|
+
item.trackback_abouts.new_about do |new_about|
|
|
29
|
+
new_about.value = about
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
assert_trackback(@elements, rss.items.last)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
def accessor_name(name)
|
|
38
|
+
"trackback_#{name}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require "rss-testcase"
|
|
2
|
+
|
|
3
|
+
require "rss/maker"
|
|
4
|
+
|
|
5
|
+
module RSS
|
|
6
|
+
class TestMakerXMLStyleSheet < TestCase
|
|
7
|
+
|
|
8
|
+
def test_xml_stylesheet
|
|
9
|
+
href = 'a.xsl'
|
|
10
|
+
type = 'text/xsl'
|
|
11
|
+
title = 'sample'
|
|
12
|
+
media = 'printer'
|
|
13
|
+
charset = 'UTF-8'
|
|
14
|
+
alternate = 'yes'
|
|
15
|
+
|
|
16
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
17
|
+
maker.xml_stylesheets.new_xml_stylesheet do |xss|
|
|
18
|
+
xss.href = href
|
|
19
|
+
xss.type = type
|
|
20
|
+
xss.title = title
|
|
21
|
+
xss.media = media
|
|
22
|
+
xss.charset = charset
|
|
23
|
+
xss.alternate = alternate
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
setup_dummy_channel(maker)
|
|
27
|
+
setup_dummy_item(maker)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
xss = rss.xml_stylesheets.first
|
|
31
|
+
assert_equal(href, xss.href)
|
|
32
|
+
assert_equal(type, xss.type)
|
|
33
|
+
assert_equal(title, xss.title)
|
|
34
|
+
assert_equal(media, xss.media)
|
|
35
|
+
assert_equal(charset, xss.charset)
|
|
36
|
+
assert_equal(alternate, xss.alternate)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
href = 'http://example.com/index.xsl'
|
|
40
|
+
type = 'text/xsl'
|
|
41
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
42
|
+
maker.xml_stylesheets.new_xml_stylesheet do |_xss|
|
|
43
|
+
_xss.href = href
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
setup_dummy_channel(maker)
|
|
47
|
+
setup_dummy_item(maker)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
xss = rss.xml_stylesheets.first
|
|
51
|
+
assert_equal(href, xss.href)
|
|
52
|
+
assert_equal(type, xss.type)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_not_valid_xml_stylesheet
|
|
56
|
+
href = 'xss.XXX'
|
|
57
|
+
type = "text/xsl"
|
|
58
|
+
|
|
59
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
60
|
+
maker.xml_stylesheets.new_xml_stylesheet do |xss|
|
|
61
|
+
# xss.href = href
|
|
62
|
+
xss.type = type
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
setup_dummy_channel(maker)
|
|
66
|
+
setup_dummy_item(maker)
|
|
67
|
+
end
|
|
68
|
+
assert(rss.xml_stylesheets.empty?)
|
|
69
|
+
|
|
70
|
+
rss = RSS::Maker.make("1.0") do |maker|
|
|
71
|
+
maker.xml_stylesheets.new_xml_stylesheet do |xss|
|
|
72
|
+
xss.href = href
|
|
73
|
+
# xss.type = type
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
setup_dummy_channel(maker)
|
|
77
|
+
setup_dummy_item(maker)
|
|
78
|
+
end
|
|
79
|
+
assert(rss.xml_stylesheets.empty?)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
|
|
3
|
+
require "rss-testcase"
|
|
4
|
+
|
|
5
|
+
require "rss/1.0"
|
|
6
|
+
require "rss/dublincore"
|
|
7
|
+
|
|
8
|
+
module RSS
|
|
9
|
+
class TestParser < TestCase
|
|
10
|
+
def setup
|
|
11
|
+
@_default_parser = Parser.default_parser
|
|
12
|
+
@rss10 = make_RDF(<<-EOR)
|
|
13
|
+
#{make_channel}
|
|
14
|
+
#{make_item}
|
|
15
|
+
#{make_textinput}
|
|
16
|
+
#{make_image}
|
|
17
|
+
EOR
|
|
18
|
+
@rss_file = "rss10.rdf"
|
|
19
|
+
File.open(@rss_file, "w") {|f| f.print(@rss10)}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def teardown
|
|
23
|
+
Parser.default_parser = @_default_parser
|
|
24
|
+
FileUtils.rm_f(@rss_file)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_default_parser
|
|
28
|
+
assert_nothing_raised do
|
|
29
|
+
Parser.default_parser = RSS::AVAILABLE_PARSERS.first
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_raise(RSS::NotValidXMLParser) do
|
|
33
|
+
Parser.default_parser = RSS::Parser
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_parse
|
|
38
|
+
assert_not_nil(RSS::Parser.parse(@rss_file))
|
|
39
|
+
|
|
40
|
+
garbage_rss_file = @rss_file + "-garbage"
|
|
41
|
+
if RSS::Parser.default_parser.name == "RSS::XMLParserParser"
|
|
42
|
+
assert_raise(RSS::NotWellFormedError) do
|
|
43
|
+
RSS::Parser.parse(garbage_rss_file)
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
assert_nil(RSS::Parser.parse(garbage_rss_file))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_parse_tag_includes_hyphen
|
|
51
|
+
assert_nothing_raised do
|
|
52
|
+
RSS::Parser.parse(make_RDF(<<-EOR))
|
|
53
|
+
<xCal:x-calconnect-venue xmlns:xCal="urn:ietf:params:xml:ns:xcal" />
|
|
54
|
+
#{make_channel}
|
|
55
|
+
#{make_item}
|
|
56
|
+
#{make_textinput}
|
|
57
|
+
#{make_image}
|
|
58
|
+
EOR
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
require "rss-testcase"
|
|
2
|
+
|
|
3
|
+
require "rss/1.0"
|
|
4
|
+
require "rss/dublincore"
|
|
5
|
+
|
|
6
|
+
module RSS
|
|
7
|
+
class TestParser10 < TestCase
|
|
8
|
+
def test_RDF
|
|
9
|
+
assert_ns("", RDF::URI) do
|
|
10
|
+
Parser.parse(<<-EOR)
|
|
11
|
+
#{make_xmldecl}
|
|
12
|
+
<RDF/>
|
|
13
|
+
EOR
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
assert_ns("", RDF::URI) do
|
|
17
|
+
Parser.parse(<<-EOR)
|
|
18
|
+
#{make_xmldecl}
|
|
19
|
+
<RDF xmlns="hoge"/>
|
|
20
|
+
EOR
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
assert_ns("rdf", RDF::URI) do
|
|
24
|
+
Parser.parse(<<-EOR)
|
|
25
|
+
#{make_xmldecl}
|
|
26
|
+
<rdf:RDF xmlns:rdf="hoge"/>
|
|
27
|
+
EOR
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
|
|
31
|
+
#{make_xmldecl}
|
|
32
|
+
<rdf:RDF xmlns:rdf="#{RSS::RDF::URI}"/>
|
|
33
|
+
EOR
|
|
34
|
+
|
|
35
|
+
assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
|
|
36
|
+
#{make_xmldecl}
|
|
37
|
+
<RDF xmlns="#{RSS::RDF::URI}"/>
|
|
38
|
+
EOR
|
|
39
|
+
|
|
40
|
+
assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
|
|
41
|
+
#{make_xmldecl}
|
|
42
|
+
<RDF xmlns="#{RSS::RDF::URI}"/>
|
|
43
|
+
EOR
|
|
44
|
+
|
|
45
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
|
46
|
+
#{make_channel}
|
|
47
|
+
EOR
|
|
48
|
+
|
|
49
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
|
50
|
+
#{make_channel}
|
|
51
|
+
#{make_image}
|
|
52
|
+
EOR
|
|
53
|
+
|
|
54
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
|
55
|
+
#{make_channel}
|
|
56
|
+
#{make_textinput}
|
|
57
|
+
EOR
|
|
58
|
+
|
|
59
|
+
assert_too_much_tag("image", "RDF") do
|
|
60
|
+
Parser.parse(make_RDF(<<-EOR))
|
|
61
|
+
#{make_channel}
|
|
62
|
+
#{make_image}
|
|
63
|
+
#{make_image}
|
|
64
|
+
#{make_item}
|
|
65
|
+
#{make_textinput}
|
|
66
|
+
EOR
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
70
|
+
#{make_channel}
|
|
71
|
+
#{make_item}
|
|
72
|
+
#{make_image}
|
|
73
|
+
#{make_textinput}
|
|
74
|
+
EOR
|
|
75
|
+
|
|
76
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
77
|
+
#{make_channel}
|
|
78
|
+
#{make_item}
|
|
79
|
+
#{make_textinput}
|
|
80
|
+
#{make_image}
|
|
81
|
+
EOR
|
|
82
|
+
|
|
83
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
84
|
+
#{make_channel}
|
|
85
|
+
#{make_image}
|
|
86
|
+
#{make_item}
|
|
87
|
+
EOR
|
|
88
|
+
|
|
89
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
90
|
+
#{make_channel}
|
|
91
|
+
#{make_image}
|
|
92
|
+
#{make_item}
|
|
93
|
+
#{make_textinput}
|
|
94
|
+
EOR
|
|
95
|
+
|
|
96
|
+
1.step(15, 3) do |i|
|
|
97
|
+
rss = make_RDF() do
|
|
98
|
+
res = make_channel
|
|
99
|
+
i.times { res << make_item }
|
|
100
|
+
res
|
|
101
|
+
end
|
|
102
|
+
assert_parse(rss, :nothing_raised)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_undefined_entity
|
|
107
|
+
return unless RSS::Parser.default_parser.raise_for_undefined_entity?
|
|
108
|
+
assert_parse(make_RDF(<<-EOR), :raises, RSS::NotWellFormedError)
|
|
109
|
+
#{make_channel}
|
|
110
|
+
#{make_image}
|
|
111
|
+
<item rdf:about="#{RDF_ABOUT}">
|
|
112
|
+
<title>#{TITLE_VALUE} &UNKNOWN_ENTITY;</title>
|
|
113
|
+
<link>#{LINK_VALUE}</link>
|
|
114
|
+
<description>#{DESCRIPTION_VALUE}</description>
|
|
115
|
+
</item>
|
|
116
|
+
#{make_textinput}
|
|
117
|
+
EOR
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_channel
|
|
121
|
+
assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "rdf:about")
|
|
122
|
+
<channel />
|
|
123
|
+
EOR
|
|
124
|
+
|
|
125
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel")
|
|
126
|
+
<channel rdf:about="http://example.com/"/>
|
|
127
|
+
EOR
|
|
128
|
+
|
|
129
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel")
|
|
130
|
+
<channel rdf:about="http://example.com/">
|
|
131
|
+
<title>hoge</title>
|
|
132
|
+
</channel>
|
|
133
|
+
EOR
|
|
134
|
+
|
|
135
|
+
assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel")
|
|
136
|
+
<channel rdf:about="http://example.com/">
|
|
137
|
+
<title>hoge</title>
|
|
138
|
+
<link>http://example.com/</link>
|
|
139
|
+
</channel>
|
|
140
|
+
EOR
|
|
141
|
+
|
|
142
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
|
|
143
|
+
<channel rdf:about="http://example.com/">
|
|
144
|
+
<title>hoge</title>
|
|
145
|
+
<link>http://example.com/</link>
|
|
146
|
+
<description>hogehoge</description>
|
|
147
|
+
</channel>
|
|
148
|
+
EOR
|
|
149
|
+
|
|
150
|
+
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:resource")
|
|
151
|
+
<channel rdf:about="http://example.com/">
|
|
152
|
+
<title>hoge</title>
|
|
153
|
+
<link>http://example.com/</link>
|
|
154
|
+
<description>hogehoge</description>
|
|
155
|
+
<image/>
|
|
156
|
+
</channel>
|
|
157
|
+
EOR
|
|
158
|
+
|
|
159
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
|
|
160
|
+
<channel rdf:about="http://example.com/">
|
|
161
|
+
<title>hoge</title>
|
|
162
|
+
<link>http://example.com/</link>
|
|
163
|
+
<description>hogehoge</description>
|
|
164
|
+
<image rdf:resource="http://example.com/hoge.png" />
|
|
165
|
+
</channel>
|
|
166
|
+
EOR
|
|
167
|
+
|
|
168
|
+
rss = make_RDF(<<-EOR)
|
|
169
|
+
<channel rdf:about="http://example.com/">
|
|
170
|
+
<title>hoge</title>
|
|
171
|
+
<link>http://example.com/</link>
|
|
172
|
+
<description>hogehoge</description>
|
|
173
|
+
<image rdf:resource="http://example.com/hoge.png" />
|
|
174
|
+
<items/>
|
|
175
|
+
</channel>
|
|
176
|
+
EOR
|
|
177
|
+
|
|
178
|
+
assert_missing_tag("Seq", "items") do
|
|
179
|
+
Parser.parse(rss)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
assert_missing_tag("item", "RDF") do
|
|
183
|
+
Parser.parse(rss, false).validate
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
|
187
|
+
<channel rdf:about="http://example.com/">
|
|
188
|
+
<title>hoge</title>
|
|
189
|
+
<link>http://example.com/</link>
|
|
190
|
+
<description>hogehoge</description>
|
|
191
|
+
<image rdf:resource="http://example.com/hoge.png" />
|
|
192
|
+
<items>
|
|
193
|
+
<rdf:Seq>
|
|
194
|
+
</rdf:Seq>
|
|
195
|
+
</items>
|
|
196
|
+
</channel>
|
|
197
|
+
EOR
|
|
198
|
+
|
|
199
|
+
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:resource")
|
|
200
|
+
<channel rdf:about="http://example.com/">
|
|
201
|
+
<title>hoge</title>
|
|
202
|
+
<link>http://example.com/</link>
|
|
203
|
+
<description>hogehoge</description>
|
|
204
|
+
<image rdf:resource="http://example.com/hoge.png" />
|
|
205
|
+
<items>
|
|
206
|
+
<rdf:Seq>
|
|
207
|
+
</rdf:Seq>
|
|
208
|
+
</items>
|
|
209
|
+
<textinput/>
|
|
210
|
+
</channel>
|
|
211
|
+
EOR
|
|
212
|
+
|
|
213
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
|
214
|
+
<channel rdf:about="http://example.com/">
|
|
215
|
+
<title>hoge</title>
|
|
216
|
+
<link>http://example.com/</link>
|
|
217
|
+
<description>hogehoge</description>
|
|
218
|
+
<image rdf:resource="http://example.com/hoge.png" />
|
|
219
|
+
<items>
|
|
220
|
+
<rdf:Seq>
|
|
221
|
+
</rdf:Seq>
|
|
222
|
+
</items>
|
|
223
|
+
<textinput rdf:resource="http://example.com/search" />
|
|
224
|
+
</channel>
|
|
225
|
+
EOR
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def test_rdf_li
|
|
229
|
+
rss = make_RDF(<<-EOR)
|
|
230
|
+
<channel rdf:about="http://example.com/">
|
|
231
|
+
<title>hoge</title>
|
|
232
|
+
<link>http://example.com/</link>
|
|
233
|
+
<description>hogehoge</description>
|
|
234
|
+
<image rdf:resource="http://example.com/hoge.png" />
|
|
235
|
+
<items>
|
|
236
|
+
<rdf:Seq>
|
|
237
|
+
<rdf:li \#{rdf_li_attr}/>
|
|
238
|
+
</rdf:Seq>
|
|
239
|
+
</items>
|
|
240
|
+
<textinput rdf:resource="http://example.com/search" />
|
|
241
|
+
</channel>
|
|
242
|
+
#{make_item}
|
|
243
|
+
EOR
|
|
244
|
+
|
|
245
|
+
source = Proc.new do |rdf_li_attr|
|
|
246
|
+
eval(%Q[%Q[#{rss}]], binding)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
attr = %q[resource="http://example.com/hoge"]
|
|
250
|
+
assert_parse(source.call(attr), :nothing_raised)
|
|
251
|
+
|
|
252
|
+
attr = %q[rdf:resource="http://example.com/hoge"]
|
|
253
|
+
assert_parse(source.call(attr), :nothing_raised)
|
|
254
|
+
|
|
255
|
+
assert_parse(source.call(""), :missing_attribute, "li", "resource")
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def test_image
|
|
259
|
+
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:about")
|
|
260
|
+
#{make_channel}
|
|
261
|
+
<image>
|
|
262
|
+
</image>
|
|
263
|
+
EOR
|
|
264
|
+
|
|
265
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image")
|
|
266
|
+
#{make_channel}
|
|
267
|
+
<image rdf:about="http://example.com/hoge.png">
|
|
268
|
+
</image>
|
|
269
|
+
EOR
|
|
270
|
+
|
|
271
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image")
|
|
272
|
+
#{make_channel}
|
|
273
|
+
<image rdf:about="http://example.com/hoge.png">
|
|
274
|
+
<title>hoge</title>
|
|
275
|
+
</image>
|
|
276
|
+
EOR
|
|
277
|
+
|
|
278
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image")
|
|
279
|
+
#{make_channel}
|
|
280
|
+
<image rdf:about="http://example.com/hoge.png">
|
|
281
|
+
<title>hoge</title>
|
|
282
|
+
<url>http://example.com/hoge.png</url>
|
|
283
|
+
</image>
|
|
284
|
+
EOR
|
|
285
|
+
|
|
286
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
|
287
|
+
#{make_channel}
|
|
288
|
+
<image rdf:about="http://example.com/hoge.png">
|
|
289
|
+
<title>hoge</title>
|
|
290
|
+
<url>http://example.com/hoge.png</url>
|
|
291
|
+
<link>http://example.com/</link>
|
|
292
|
+
</image>
|
|
293
|
+
EOR
|
|
294
|
+
|
|
295
|
+
rss = make_RDF(<<-EOR)
|
|
296
|
+
#{make_channel}
|
|
297
|
+
<image rdf:about="http://example.com/hoge.png">
|
|
298
|
+
<link>http://example.com/</link>
|
|
299
|
+
<url>http://example.com/hoge.png</url>
|
|
300
|
+
<title>hoge</title>
|
|
301
|
+
</image>
|
|
302
|
+
EOR
|
|
303
|
+
|
|
304
|
+
assert_missing_tag("item", "RDF") do
|
|
305
|
+
Parser.parse(rss)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
assert_missing_tag("item", "RDF") do
|
|
309
|
+
Parser.parse(rss, false).validate
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def test_item
|
|
314
|
+
assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "rdf:about")
|
|
315
|
+
#{make_channel}
|
|
316
|
+
#{make_image}
|
|
317
|
+
<item>
|
|
318
|
+
</item>
|
|
319
|
+
EOR
|
|
320
|
+
|
|
321
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item")
|
|
322
|
+
#{make_channel}
|
|
323
|
+
#{make_image}
|
|
324
|
+
<item rdf:about="http://example.com/hoge.html">
|
|
325
|
+
</item>
|
|
326
|
+
EOR
|
|
327
|
+
|
|
328
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item")
|
|
329
|
+
#{make_channel}
|
|
330
|
+
#{make_image}
|
|
331
|
+
<item rdf:about="http://example.com/hoge.html">
|
|
332
|
+
<title>hoge</title>
|
|
333
|
+
</item>
|
|
334
|
+
EOR
|
|
335
|
+
|
|
336
|
+
assert_too_much_tag("title", "item") do
|
|
337
|
+
Parser.parse(make_RDF(<<-EOR))
|
|
338
|
+
#{make_channel}
|
|
339
|
+
#{make_image}
|
|
340
|
+
<item rdf:about="http://example.com/hoge.html">
|
|
341
|
+
<title>hoge</title>
|
|
342
|
+
<title>hoge</title>
|
|
343
|
+
<link>http://example.com/hoge.html</link>
|
|
344
|
+
</item>
|
|
345
|
+
EOR
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
349
|
+
#{make_channel}
|
|
350
|
+
#{make_image}
|
|
351
|
+
<item rdf:about="http://example.com/hoge.html">
|
|
352
|
+
<title>hoge</title>
|
|
353
|
+
<link>http://example.com/hoge.html</link>
|
|
354
|
+
</item>
|
|
355
|
+
EOR
|
|
356
|
+
|
|
357
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
358
|
+
#{make_channel}
|
|
359
|
+
#{make_image}
|
|
360
|
+
<item rdf:about="http://example.com/hoge.html">
|
|
361
|
+
<title>hoge</title>
|
|
362
|
+
<link>http://example.com/hoge.html</link>
|
|
363
|
+
<description>hogehoge</description>
|
|
364
|
+
</item>
|
|
365
|
+
EOR
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def test_textinput
|
|
369
|
+
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:about")
|
|
370
|
+
#{make_channel}
|
|
371
|
+
#{make_image}
|
|
372
|
+
#{make_item}
|
|
373
|
+
<textinput>
|
|
374
|
+
</textinput>
|
|
375
|
+
EOR
|
|
376
|
+
|
|
377
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput")
|
|
378
|
+
#{make_channel}
|
|
379
|
+
#{make_image}
|
|
380
|
+
#{make_item}
|
|
381
|
+
<textinput rdf:about="http://example.com/search.html">
|
|
382
|
+
</textinput>
|
|
383
|
+
EOR
|
|
384
|
+
|
|
385
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput")
|
|
386
|
+
#{make_channel}
|
|
387
|
+
#{make_image}
|
|
388
|
+
#{make_item}
|
|
389
|
+
<textinput rdf:about="http://example.com/search.html">
|
|
390
|
+
<title>hoge</title>
|
|
391
|
+
</textinput>
|
|
392
|
+
EOR
|
|
393
|
+
|
|
394
|
+
assert_too_much_tag("title", "textinput") do
|
|
395
|
+
Parser.parse(make_RDF(<<-EOR))
|
|
396
|
+
#{make_channel}
|
|
397
|
+
#{make_image}
|
|
398
|
+
#{make_item}
|
|
399
|
+
<textinput rdf:about="http://example.com/search.html">
|
|
400
|
+
<title>hoge</title>
|
|
401
|
+
<title>hoge</title>
|
|
402
|
+
<description>hogehoge</description>
|
|
403
|
+
</textinput>
|
|
404
|
+
EOR
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput")
|
|
408
|
+
#{make_channel}
|
|
409
|
+
#{make_image}
|
|
410
|
+
#{make_item}
|
|
411
|
+
<textinput rdf:about="http://example.com/search.html">
|
|
412
|
+
<title>hoge</title>
|
|
413
|
+
<description>hogehoge</description>
|
|
414
|
+
</textinput>
|
|
415
|
+
EOR
|
|
416
|
+
|
|
417
|
+
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput")
|
|
418
|
+
#{make_channel}
|
|
419
|
+
#{make_image}
|
|
420
|
+
#{make_item}
|
|
421
|
+
<textinput rdf:about="http://example.com/search.html">
|
|
422
|
+
<title>hoge</title>
|
|
423
|
+
<description>hogehoge</description>
|
|
424
|
+
<name>key</name>
|
|
425
|
+
</textinput>
|
|
426
|
+
EOR
|
|
427
|
+
|
|
428
|
+
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
|
429
|
+
#{make_channel}
|
|
430
|
+
#{make_image}
|
|
431
|
+
#{make_item}
|
|
432
|
+
<textinput rdf:about="http://example.com/search.html">
|
|
433
|
+
<title>hoge</title>
|
|
434
|
+
<description>hogehoge</description>
|
|
435
|
+
<name>key</name>
|
|
436
|
+
<link>http://example.com/search.html</link>
|
|
437
|
+
</textinput>
|
|
438
|
+
EOR
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def test_ignore
|
|
442
|
+
name = "a"
|
|
443
|
+
rss = make_RDF(<<-EOR)
|
|
444
|
+
#{make_channel}
|
|
445
|
+
#{make_item}
|
|
446
|
+
<#{name}/>
|
|
447
|
+
EOR
|
|
448
|
+
assert_not_expected_tag(name, ::RSS::URI, "RDF") do
|
|
449
|
+
Parser.parse(rss, true, false)
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
uri = ""
|
|
453
|
+
name = "a"
|
|
454
|
+
rss = make_RDF(<<-EOR)
|
|
455
|
+
#{make_channel}
|
|
456
|
+
#{make_item}
|
|
457
|
+
<#{name} xmlns=""/>
|
|
458
|
+
EOR
|
|
459
|
+
assert_parse(rss, :nothing_raised)
|
|
460
|
+
assert_not_expected_tag(name, uri, "RDF") do
|
|
461
|
+
Parser.parse(rss, true, false)
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
uri = "http://example.com/"
|
|
465
|
+
name = "a"
|
|
466
|
+
rss = make_RDF(<<-EOR)
|
|
467
|
+
#{make_channel}
|
|
468
|
+
#{make_item}
|
|
469
|
+
<x:#{name} xmlns:x="#{uri}"/>
|
|
470
|
+
EOR
|
|
471
|
+
assert_parse(rss, :nothing_raised)
|
|
472
|
+
assert_not_expected_tag(name, uri, "RDF") do
|
|
473
|
+
Parser.parse(rss, true, false)
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
uri = ::RSS::URI
|
|
477
|
+
name = "a"
|
|
478
|
+
rss = make_RDF(<<-EOR)
|
|
479
|
+
#{make_channel}
|
|
480
|
+
#{make_item}
|
|
481
|
+
#{make_image("<#{name}/>")}
|
|
482
|
+
EOR
|
|
483
|
+
assert_parse(rss, :nothing_raised)
|
|
484
|
+
assert_not_expected_tag(name, uri, "image") do
|
|
485
|
+
Parser.parse(rss, true, false)
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
uri = CONTENT_URI
|
|
489
|
+
name = "encoded"
|
|
490
|
+
elem = "<#{name} xmlns='#{uri}'/>"
|
|
491
|
+
rss = make_RDF(<<-EOR)
|
|
492
|
+
#{make_channel}
|
|
493
|
+
#{make_item}
|
|
494
|
+
#{make_image(elem)}
|
|
495
|
+
EOR
|
|
496
|
+
assert_parse(rss, :nothing_raised)
|
|
497
|
+
assert_not_expected_tag(name, uri, "image") do
|
|
498
|
+
Parser.parse(rss, true, false)
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
def test_unknown_duplicated_element
|
|
503
|
+
xmlns = {"test" => "http://localhost/test"}
|
|
504
|
+
assert_parse(make_RDF(<<-EOR, xmlns), :nothing_raised)
|
|
505
|
+
#{make_channel("<test:string/>")}
|
|
506
|
+
#{make_item}
|
|
507
|
+
#{make_image}
|
|
508
|
+
EOR
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
def test_unknown_case_insensitive_duplicated_element
|
|
512
|
+
xmlns = {
|
|
513
|
+
"foaf" => "http://xmlns.com/foaf/0.1/",
|
|
514
|
+
"dc" => "http://purl.org/dc/elements/1.1/",
|
|
515
|
+
}
|
|
516
|
+
assert_parse(make_RDF(<<-EOR, xmlns), :nothing_raised)
|
|
517
|
+
#{make_channel}
|
|
518
|
+
#{make_item}
|
|
519
|
+
#{make_image}
|
|
520
|
+
<foaf:Image rdf:about="http://example.com/myself.png">
|
|
521
|
+
<dc:title>Myself</dc:title>
|
|
522
|
+
<dc:link>http://example.com/</dc:link>
|
|
523
|
+
</foaf:Image>
|
|
524
|
+
EOR
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
|