summaryrefslogtreecommitdiff
path: root/test/rss
diff options
context:
space:
mode:
Diffstat (limited to 'test/rss')
-rw-r--r--test/rss/rss-assertions.rb329
-rw-r--r--test/rss/test_1.0.rb5
-rw-r--r--test/rss/test_maker_0.9.rb30
-rw-r--r--test/rss/test_maker_2.0.rb56
-rw-r--r--test/rss/test_maker_content.rb2
-rw-r--r--test/rss/test_maker_dc.rb2
-rw-r--r--test/rss/test_maker_sy.rb2
-rw-r--r--test/rss/test_maker_trackback.rb13
-rw-r--r--test/rss/test_parser.rb12
-rw-r--r--test/rss/test_to_s.rb440
-rw-r--r--test/rss/test_trackback.rb10
-rw-r--r--test/rss/test_xml-stylesheet.rb6
12 files changed, 840 insertions, 67 deletions
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
index 6b83cbe093..a51fc1fd60 100644
--- a/test/rss/rss-assertions.rb
+++ b/test/rss/rss-assertions.rb
@@ -94,27 +94,32 @@ module RSS
end
end
end
+
+ def assert_xml_declaration(version, encoding, standalone, rss)
+ _wrap_assertion do
+ assert_equal(version, rss.version)
+ assert_equal(encoding, rss.encoding)
+ assert_equal(standalone, rss.standalone)
+ end
+ end
- def assert_xml_stylesheet_attrs(xsl, attrs)
+ def assert_xml_stylesheet_attrs(attrs, xsl)
_wrap_assertion do
- normalized_attrs = {}
- attrs.each do |name, value|
- normalized_attrs[name.to_s] = value
- end
+ n_attrs = normalized_attrs(attrs)
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
- assert_equal(normalized_attrs[name], xsl.send(name))
+ assert_equal(n_attrs[name], xsl.send(name))
end
end
end
- def assert_xml_stylesheet(target, xsl, attrs)
+ def assert_xml_stylesheet(target, attrs, xsl)
_wrap_assertion do
if attrs.has_key?(:href)
if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
attrs[:type] = attrs[:guess_type]
end
assert_equal("xml-stylesheet", target)
- assert_xml_stylesheet_attrs(xsl, attrs)
+ assert_xml_stylesheet_attrs(attrs, xsl)
else
assert_nil(target)
assert_equal("", xsl.to_s)
@@ -123,39 +128,313 @@ module RSS
end
def assert_xml_stylesheet_pis(attrs_ary)
- rdf = ::RSS::RDF.new()
- xss_strs = []
- attrs_ary.each do |attrs|
- xss = ::RSS::XMLStyleSheet.new(*attrs)
- xss_strs.push(xss.to_s)
- rdf.xml_stylesheets.push(xss)
+ _wrap_assertion do
+ rdf = ::RSS::RDF.new()
+ xss_strs = []
+ attrs_ary.each do |attrs|
+ xss = ::RSS::XMLStyleSheet.new(*attrs)
+ xss_strs.push(xss.to_s)
+ rdf.xml_stylesheets.push(xss)
+ end
+ pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
+ assert_equal(xss_strs.join("\n"), pi_str)
+ end
+ end
+
+ def assert_xml_stylesheets(attrs, xss)
+ _wrap_assertion do
+ xss.each_with_index do |xs, i|
+ assert_xml_stylesheet_attrs(attrs[i], xs)
+ end
+ end
+ end
+
+
+ def assert_channel10(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(about title link description)
+ assert_attributes(attrs, names, channel)
+
+ %w(image items textinput).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel10_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel10_image(attrs, image)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(resource), image)
+ end
+ end
+
+ def assert_channel10_textinput(attrs, textinput)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(resource), textinput)
+ end
+ end
+
+ def assert_channel10_items(attrs, items)
+ _wrap_assertion do
+ items.Seq.lis.each_with_index do |li, i|
+ assert_attributes(attrs[i], %w(resource), li)
+ end
+ end
+ end
+
+ def assert_image10(attrs, image)
+ _wrap_assertion do
+ names = %w(about title url link)
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items10(attrs, items)
+ _wrap_assertion do
+ names = %w(about title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+ end
+ end
+ end
+
+ def assert_textinput10(attrs, textinput)
+ _wrap_assertion do
+ names = %w(about title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
+ def assert_channel09(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(title description link language rating
+ copyright pubDate lastBuildDate docs
+ managingEditor webMaster)
+ assert_attributes(attrs, names, channel)
+
+ %w(skipHours skipDays).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel09_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel09_skipDays(contents, skipDays)
+ _wrap_assertion do
+ days = skipDays.days
+ contents.each_with_index do |content, i|
+ assert_equal(content, days[i].content)
+ end
+ end
+ end
+
+ def assert_channel09_skipHours(contents, skipHours)
+ _wrap_assertion do
+ hours = skipHours.hours
+ contents.each_with_index do |content, i|
+ assert_equal(content, hours[i].content)
+ end
+ end
+ end
+
+ def assert_image09(attrs, image)
+ _wrap_assertion do
+ names = %w(url link title description width height)
+ assert_attributes(attrs, names, image)
end
- pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
- assert_equal(xss_strs.join("\n"), pi_str)
end
+ def assert_items09(attrs, items)
+ _wrap_assertion do
+ names = %w(title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+ end
+ end
+ end
+
+ def assert_textinput09(attrs, textinput)
+ _wrap_assertion do
+ names = %w(title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
+ def assert_channel20(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(title link description language copyright
+ managingEditor webMaster pubDate
+ lastBuildDate generator docs ttl rating)
+ assert_attributes(attrs, names, channel)
+
+ %w(cloud categories skipHours skipDays).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel20_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel20_skipDays(contents, skipDays)
+ assert_channel09_skipDays(contents, skipDays)
+ end
+
+ def assert_channel20_skipHours(contents, skipHours)
+ assert_channel09_skipHours(contents, skipHours)
+ end
+
+ def assert_channel20_cloud(attrs, cloud)
+ _wrap_assertion do
+ names = %w(domain port path registerProcedure protocol)
+ assert_attributes(attrs, names, cloud)
+ end
+ end
+
+ def assert_channel20_categories(attrs, categories)
+ _wrap_assertion do
+ names = %w(domain content)
+ categories.each_with_index do |category, i|
+ assert_attributes(attrs[i], names, category)
+ end
+ end
+ end
+
+ def assert_image20(attrs, image)
+ _wrap_assertion do
+ names = %w(url link title description width height)
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items20(attrs, items)
+ _wrap_assertion do
+ names = %w(about title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+
+ n_attrs = normalized_attrs(attrs[i])
+
+ %w(source enclosure categories guid).each do |name|
+ value = n_attrs[name]
+ if value
+ target = item.__send__(name)
+ __send__("assert_items20_#{name}", value, target)
+ end
+ end
+ end
+ end
+ end
+
+ def assert_items20_source(attrs, source)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(url content), source)
+ end
+ end
+
+ def assert_items20_enclosure(attrs, enclosure)
+ _wrap_assertion do
+ names = %w(url length type)
+ assert_attributes(attrs, names, enclosure)
+ end
+ end
+
+ def assert_items20_categories(attrs, categories)
+ _wrap_assertion do
+ assert_channel20_categories(attrs, categories)
+ end
+ end
+
+ def assert_items20_guid(attrs, guid)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(isPermaLink content), guid)
+ end
+ end
+
+ def assert_textinput20(attrs, textinput)
+ _wrap_assertion do
+ names = %w(title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
def assert_dublin_core(elems, target)
- elems.each do |name, value|
- assert_equal(value, target.__send__("dc_#{name}"))
+ _wrap_assertion do
+ elems.each do |name, value|
+ assert_equal(value, target.__send__("dc_#{name}"))
+ end
end
end
def assert_syndication(elems, target)
- elems.each do |name, value|
- assert_equal(value, target.__send__("sy_#{name}"))
+ _wrap_assertion do
+ elems.each do |name, value|
+ assert_equal(value, target.__send__("sy_#{name}"))
+ end
end
end
def assert_content(elems, target)
- elems.each do |name, value|
- assert_equal(value, target.__send__("content_#{name}"))
+ _wrap_assertion do
+ elems.each do |name, value|
+ assert_equal(value, target.__send__("content_#{name}"))
+ end
+ end
+ end
+
+ def assert_trackback(attrs, target)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+ if n_attrs["ping"]
+ assert_equal(n_attrs["ping"], target.trackback_ping)
+ end
+ if n_attrs["abouts"]
+ n_attrs["abouts"].each_with_index do |about, i|
+ assert_equal(about, target.trackback_abouts[i].value)
+ end
+ end
+ end
+ end
+
+
+ def assert_attributes(attrs, names, target)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+ names.each do |name|
+ value = n_attrs[name]
+ if value.is_a?(Time)
+ actual = target.__send__(name)
+ assert_instance_of(Time, actual)
+ assert_equal(value.to_i, actual.to_i)
+ elsif value
+ assert_equal(value, target.__send__(name))
+ end
+ end
end
end
- def assert_trackback(elems, target)
- elems.each do |name, value|
- assert_equal(value, target.__send__("trackback_#{name}"))
+ def normalized_attrs(attrs)
+ n_attrs = {}
+ attrs.each do |name, value|
+ n_attrs[name.to_s] = value
end
+ n_attrs
end
end
diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb
index e6a81af2bd..c37bd84616 100644
--- a/test/rss/test_1.0.rb
+++ b/test/rss/test_1.0.rb
@@ -19,7 +19,7 @@ module RSS
version = "1.0"
encoding = "UTF-8"
- standalone = "no"
+ standalone = false
rdf = RDF.new(version, encoding, standalone)
@@ -27,9 +27,10 @@ module RSS
xmldecl = doc.xml_decl
- %w(version encoding standalone).each do |x|
+ %w(version encoding).each do |x|
assert_equal(instance_eval(x), xmldecl.send(x))
end
+ assert_equal(standalone, !xmldecl.standalone.nil?)
assert_equal(@rdf_uri, doc.root.namespace)
diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb
index df8cd5fe11..5f356cc8c4 100644
--- a/test/rss/test_maker_0.9.rb
+++ b/test/rss/test_maker_0.9.rb
@@ -55,8 +55,14 @@ module RSS
webMaster = "web master"
rating = "6"
docs = "http://foo.com/doc"
- skipDays = "Sunday"
- skipHours = "13"
+ skipDays = [
+ "Sunday",
+ "Monday",
+ ]
+ skipHours = [
+ 0,
+ 13,
+ ]
pubDate = Time.now
lastBuildDate = Time.now
@@ -70,11 +76,18 @@ module RSS
maker.channel.webMaster = webMaster
maker.channel.rating = rating
maker.channel.docs = docs
- maker.channel.skipDays = skipDays
- maker.channel.skipHours = skipHours
maker.channel.pubDate = pubDate
maker.channel.lastBuildDate = lastBuildDate
+ skipDays.each do |day|
+ new_day = maker.channel.skipDays.new_day
+ new_day.content = day
+ end
+ skipHours.each do |hour|
+ new_hour = maker.channel.skipHours.new_hour
+ new_hour.content = hour
+ end
+
setup_dummy_image(maker)
end
channel = rss.channel
@@ -88,11 +101,16 @@ module RSS
assert_equal(webMaster, channel.webMaster)
assert_equal(rating, channel.rating)
assert_equal(docs, channel.docs)
- assert_equal(skipDays, channel.skipDays)
- assert_equal(skipHours, channel.skipHours)
assert_equal(pubDate, channel.pubDate)
assert_equal(lastBuildDate, channel.lastBuildDate)
+ skipDays.each_with_index do |day, i|
+ assert_equal(day, channel.skipDays.days[i].content)
+ end
+ skipHours.each_with_index do |hour, i|
+ assert_equal(hour, channel.skipHours.hours[i].content)
+ end
+
assert(channel.items.empty?)
assert_not_nil(channel.image)
assert_nil(channel.textInput)
diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb
index b0752f985f..dc08ada34b 100644
--- a/test/rss/test_maker_2.0.rb
+++ b/test/rss/test_maker_2.0.rb
@@ -51,11 +51,20 @@ module RSS
webMaster = "web master"
rating = "6"
docs = "http://foo.com/doc"
- skipDays = "Sunday"
- skipHours = "13"
+ skipDays = [
+ "Sunday",
+ "Monday",
+ ]
+ skipHours = [
+ 0,
+ 13,
+ ]
pubDate = Time.now
lastBuildDate = Time.now
- category = "Nespapers"
+ categories = [
+ "Nespapers",
+ "misc",
+ ]
generator = "RSS Maker"
ttl = 60
@@ -69,11 +78,23 @@ module RSS
maker.channel.webMaster = webMaster
maker.channel.rating = rating
maker.channel.docs = docs
- maker.channel.skipDays = skipDays
- maker.channel.skipHours = skipHours
maker.channel.pubDate = pubDate
maker.channel.lastBuildDate = lastBuildDate
- maker.channel.category = category
+
+ skipDays.each do |day|
+ new_day = maker.channel.skipDays.new_day
+ new_day.content = day
+ end
+ skipHours.each do |hour|
+ new_hour = maker.channel.skipHours.new_hour
+ new_hour.content = hour
+ end
+
+ categories.each do |category|
+ new_category = maker.channel.categories.new_category
+ new_category.content = category
+ end
+
maker.channel.generator = generator
maker.channel.ttl = ttl
end
@@ -88,11 +109,20 @@ module RSS
assert_equal(webMaster, channel.webMaster)
assert_equal(rating, channel.rating)
assert_equal(docs, channel.docs)
- assert_equal(skipDays, channel.skipDays)
- assert_equal(skipHours, channel.skipHours)
assert_equal(pubDate, channel.pubDate)
assert_equal(lastBuildDate, channel.lastBuildDate)
- assert_equal(category, channel.category)
+
+ skipDays.each_with_index do |day, i|
+ assert_equal(day, channel.skipDays.days[i].content)
+ end
+ skipHours.each_with_index do |hour, i|
+ assert_equal(hour, channel.skipHours.hours[i].content)
+ end
+
+ channel.categories.each_with_index do |category, i|
+ assert_equal(categories[i], category.content)
+ end
+
assert_equal(generator, channel.generator)
assert_equal(ttl, channel.ttl)
@@ -519,11 +549,11 @@ module RSS
setup_dummy_channel(maker)
setup_dummy_item(maker)
- category = maker.items.last.category
+ category = maker.items.last.categories.new_category
category.domain = domain
category.content = content
end
- category = rss.channel.items.last.category
+ category = rss.channel.items.last.categories.last
assert_equal(domain, category.domain)
assert_equal(content, category.content)
end
@@ -535,10 +565,10 @@ module RSS
setup_dummy_channel(maker)
setup_dummy_item(maker)
- category = maker.items.last.category
+ category = maker.items.last.categories.new_category
# category.content = content
end
- assert_nil(rss.channel.items.last.category)
+ assert(rss.channel.items.last.categories.empty?)
end
def test_textInput
diff --git a/test/rss/test_maker_content.rb b/test/rss/test_maker_content.rb
index faadd87131..c29d75a649 100644
--- a/test/rss/test_maker_content.rb
+++ b/test/rss/test_maker_content.rb
@@ -14,7 +14,7 @@ module RSS
end
def test_rss10
- rss = RSS::Maker.make("1.0", ["content"]) do |maker|
+ rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
setup_dummy_item(maker)
diff --git a/test/rss/test_maker_dc.rb b/test/rss/test_maker_dc.rb
index 512622d29f..0a4a4d42cf 100644
--- a/test/rss/test_maker_dc.rb
+++ b/test/rss/test_maker_dc.rb
@@ -34,7 +34,7 @@ module RSS
end
def test_rss10
- rss = RSS::Maker.make("1.0", ["dublincore"]) do |maker|
+ rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
set_elements(maker.channel)
diff --git a/test/rss/test_maker_sy.rb b/test/rss/test_maker_sy.rb
index c41ec1d310..58e95d917a 100644
--- a/test/rss/test_maker_sy.rb
+++ b/test/rss/test_maker_sy.rb
@@ -21,7 +21,7 @@ module RSS
end
def test_rss10
- rss = RSS::Maker.make("1.0", ["syndication"]) do |maker|
+ rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
set_elements(maker.channel)
end
diff --git a/test/rss/test_maker_trackback.rb b/test/rss/test_maker_trackback.rb
index bffa60e963..e90bb600a3 100644
--- a/test/rss/test_maker_trackback.rb
+++ b/test/rss/test_maker_trackback.rb
@@ -10,18 +10,23 @@ module RSS
@elements = {
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
- :about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
+ :abouts => [
+ "http://foo.com/trackback/tb.cgi?tb_id=20020923",
+ "http://bar.com/trackback/tb.cgi?tb_id=20041114",
+ ],
}
end
def test_rss10
- rss = RSS::Maker.make("1.0", ["trackback"]) do |maker|
+ rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
setup_dummy_item(maker)
item = maker.items.last
- @elements.each do |name, value|
- item.__send__("#{accessor_name(name)}=", value)
+ item.trackback_ping = @elements[:ping]
+ @elements[:abouts].each do |about|
+ new_about = item.trackback_abouts.new_about
+ new_about.value = about
end
end
assert_trackback(@elements, rss.items.last)
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
index de4894997f..019030bcce 100644
--- a/test/rss/test_parser.rb
+++ b/test/rss/test_parser.rb
@@ -116,7 +116,7 @@ EOR
def test_channel
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "rdf:about")
<channel />
EOR
@@ -145,7 +145,7 @@ EOR
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:resource")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -194,7 +194,7 @@ EOR
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:resource")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -257,7 +257,7 @@ EOR
def test_image
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:about")
#{make_channel}
<image>
</image>
@@ -314,7 +314,7 @@ EOR
def test_item
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "rdf:about")
#{make_channel}
#{make_image}
<item>
@@ -371,7 +371,7 @@ EOR
def test_textinput
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:about")
#{make_channel}
#{make_image}
#{make_item}
diff --git a/test/rss/test_to_s.rb b/test/rss/test_to_s.rb
new file mode 100644
index 0000000000..e2263ca17c
--- /dev/null
+++ b/test/rss/test_to_s.rb
@@ -0,0 +1,440 @@
+require "rexml/document"
+
+require "rss-testcase"
+
+require "rss/maker"
+require "rss/1.0"
+require "rss/2.0"
+require "rss/content"
+require "rss/dublincore"
+require "rss/syndication"
+require "rss/trackback"
+
+module RSS
+ class TestToS < TestCase
+
+ def setup
+ @image_url = "http://example.com/foo.png"
+ @textinput_link = "http://example.com/search.cgi"
+ @item_links = [
+ "http://example.com/1",
+ "http://example.com/2",
+ ]
+
+ setup_xml_declaration_info
+ setup_xml_stylesheet_infos
+ setup_channel_info
+ setup_item_infos
+ setup_image_info
+ setup_textinput_info
+
+ setup_dublin_core_info
+ setup_syndication_info
+ setup_content_info
+ setup_trackback_info
+ end
+
+ def test_to_s_10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_full(maker)
+ end
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel10(@channel_info, rss.channel)
+ assert_items10(@item_infos, rss.items)
+ rss.items.each do |item|
+ assert_trackback(@trackback_info, item)
+ end
+ assert_image10(@image_info, rss.image)
+ assert_textinput10(@textinput_info, rss.textinput)
+
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel10(@channel_info, rss.channel)
+ assert_items10(@item_infos, rss.items)
+ assert_image10(@image_info, rss.image)
+ assert_textinput10(@textinput_info, rss.textinput)
+ end
+
+ def test_to_s_09
+ rss = RSS::Maker.make("0.9") do |maker|
+ setup_full(maker)
+ end
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel09(@channel_info, rss.channel)
+ assert_items09(@item_infos, rss.items)
+ assert_image09(@image_info, rss.image)
+ assert_textinput09(@textinput_info, rss.textinput)
+
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel09(@channel_info, rss.channel)
+ assert_items09(@item_infos, rss.items)
+ assert_image09(@image_info, rss.image)
+ assert_textinput09(@textinput_info, rss.textinput)
+ end
+
+ def test_to_s_20
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_full(maker)
+ end
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel20(@channel_info, rss.channel)
+ assert_items20(@item_infos, rss.items)
+ assert_image20(@image_info, rss.image)
+ assert_textinput20(@textinput_info, rss.textinput)
+
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel20(@channel_info, rss.channel)
+ assert_items20(@item_infos, rss.items)
+ assert_image20(@image_info, rss.image)
+ assert_textinput20(@textinput_info, rss.textinput)
+ end
+
+ private
+ def setup_xml_declaration_info
+ @version = "1.0"
+ @encoding = "UTF-8"
+ @standalone = false
+ end
+
+ def setup_xml_stylesheet_infos
+ @xs_infos = [
+ {
+ "href" => "XXX.xsl",
+ "type" => "text/xsl",
+ "title" => "XXX",
+ "media" => "print",
+ "alternate" => "no",
+ },
+ {
+ "href" => "YYY.css",
+ "type" => "text/css",
+ "title" => "YYY",
+ "media" => "all",
+ "alternate" => "no",
+ },
+ ]
+ end
+
+ def setup_channel_info
+ @channel_info = {
+ "about" => "http://example.com/index.rdf",
+ "title" => "Sample RSS",
+ "link" => "http://example.com/",
+ "description" => "Sample\n\n\n\n\nSite",
+ "language" => "en",
+ "copyright" => "FDL",
+ "managingEditor" => "foo@example.com",
+ "webMaster" => "webmaster@example.com",
+ "rating" => '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))',
+ "docs" => "http://backend.userland.com/rss091",
+ "skipDays" => [
+ "Monday",
+ "Friday",
+ ],
+ "skipHours" => [
+ 12,
+ 23,
+ ],
+ "date" => Time.now,
+ "lastBuildDate" => Time.now - 3600,
+ "generator" => "RSS Maker",
+ "ttl" => 60,
+ "cloud" => {
+ "domain" => "rpc.sys.com",
+ "port" => "80",
+ "path" => "/RPC2",
+ "registerProcedure" => "myCloud.rssPleaseNotify",
+ "protocol" => "xml-rpc",
+ },
+ "category" => {
+ "domain" => "http://example.com/misc/",
+ "content" => "misc",
+ },
+
+ "image" => {
+ "resource" => @image_url,
+ },
+
+ "textinput" => {
+ "resource" => @textinput_link,
+ },
+
+ "items" => @item_links.collect{|link| {"resource" => link}},
+ }
+ end
+
+ def setup_item_infos
+ @item_infos = [
+ {
+ "title" => "Sample item1",
+ "link" => @item_links[0],
+ "description" => "Sample description1",
+ "date" => Time.now - 3600,
+ "author" => "foo@example.com",
+ "comments" => "http://example.com/1/comments",
+ "guid" => {
+ "isPermaLink" => "ture",
+ "content" => "http://example.com/1",
+ },
+ "enclosure" => {
+ "url" => "http://example.com/1.mp3",
+ "length" => "100",
+ "type" => "audio/mpeg",
+ },
+ "source" => {
+ "url" => "http:/example.com/",
+ "content" => "Sample site",
+ },
+ "category" => {
+ "domain" => "http://example.com/misc/",
+ "content" => "misc",
+ },
+ },
+
+ {
+ "title" => "Sample item2",
+ "link" => @item_links[1],
+ "description" => "Sample description2",
+ "date" => Time.now - 7200,
+ "author" => "foo@example.com",
+ "comments" => "http://example.com/2/comments",
+ "guid" => {
+ "isPermaLink" => "false",
+ "content" => "http://example.com/2",
+ },
+ "enclosure" => {
+ "url" => "http://example.com/2.mp3",
+ "length" => "200",
+ "type" => "audio/mpeg",
+ },
+ "source" => {
+ "url" => "http:/example.com/",
+ "content" => "Sample site",
+ },
+ "category" => {
+ "domain" => "http://example.com/misc/",
+ "content" => "misc",
+ },
+ },
+ ]
+ end
+
+ def setup_image_info
+ @image_info = {
+ "title" => "Sample image",
+ "url" => @image_url,
+ "width" => "88",
+ "height" => "31",
+ "description" => "Sample",
+ }
+ end
+
+ def setup_textinput_info
+ @textinput_info = {
+ "title" => "Sample textinput",
+ "description" => "Search",
+ "name" => "key",
+ "link" => @textinput_link,
+ }
+ end
+
+ def setup_dublin_core_info
+ @dc_info = {
+ "title" => "DC title",
+ "description" => "DC desc",
+ "creator" => "DC creator",
+ "subject" => "DC subject",
+ "publisher" => "DC publisher",
+ "contributor" => "DC contributor",
+ "type" => "DC type",
+ "format" => "DC format",
+ "identifier" => "DC identifier",
+ "source" => "DC source",
+ "language" => "ja",
+ "relation" => "DC relation",
+ "coverage" => "DC coverage",
+ "rights" => "DC rights",
+ "date" => Time.now - 60,
+ }
+ end
+
+ def setup_syndication_info
+ @sy_info = {
+ "updatePeriod" => "hourly",
+ "updateFrequency" => 2,
+ "updateBase" => Time.now - 3600,
+ }
+ end
+
+ def setup_content_info
+ @content_info = {
+ "encoded" => "<p>p</p>",
+ }
+ end
+
+ def setup_trackback_info
+ @trackback_info = {
+ "ping" => "http://example.com/tb.cgi?tb_id=XXX",
+ "abouts" => [
+ "http://example.net/tb.cgi?tb_id=YYY",
+ "http://example.org/tb.cgi?tb_id=ZZZ",
+ ]
+ }
+ end
+
+
+ def setup_full(maker)
+ setup_xml_declaration(maker)
+ setup_xml_stylesheets(maker)
+ setup_channel(maker)
+ setup_image(maker)
+ setup_items(maker)
+ setup_textinput(maker)
+ end
+
+ def setup_xml_declaration(maker)
+ %w(version encoding standalone).each do |name|
+ maker.__send__("#{name}=", instance_eval("@#{name}"))
+ end
+ end
+
+ def setup_xml_stylesheets(maker)
+ @xs_infos.each do |info|
+ xs = maker.xml_stylesheets.new_xml_stylesheet
+ info.each do |name, value|
+ xs.__send__("#{name}=", value)
+ end
+ end
+ end
+
+ def setup_channel(maker)
+ channel = maker.channel
+ info = @channel_info
+
+ %w(about title link description language copyright
+ managingEditor webMaster rating docs date
+ lastBuildDate generator ttl).each do |name|
+ channel.__send__("#{name}=", info[name])
+ end
+
+ skipDays = channel.skipDays
+ info["skipDays"].each do |day|
+ new_day = skipDays.new_day
+ new_day.content = day
+ end
+
+ skipHours = channel.skipHours
+ info["skipHours"].each do |hour|
+ new_hour = skipHours.new_hour
+ new_hour.content = hour
+ end
+
+ cloud = channel.cloud
+ %w(domain port path registerProcedure protocol).each do |name|
+ cloud.__send__("#{name}=", info["cloud"][name])
+ end
+
+ category = channel.categories.new_category
+ %w(domain content).each do |name|
+ category.__send__("#{name}=", info["category"][name])
+ end
+ end
+
+ def setup_image(maker)
+ image = maker.image
+ info = @image_info
+
+ %w(title url width height description).each do |name|
+ image.__send__("#{name}=", info[name])
+ end
+ end
+
+ def setup_items(maker)
+ items = maker.items
+
+ @item_infos.each do |info|
+ item = items.new_item
+ %w(title link description date author comments).each do |name|
+ item.__send__("#{name}=", info[name])
+ end
+
+ guid = item.guid
+ %w(isPermaLink content).each do |name|
+ guid.__send__("#{name}=", info["guid"][name])
+ end
+
+ enclosure = item.enclosure
+ %w(url length type).each do |name|
+ enclosure.__send__("#{name}=", info["enclosure"][name])
+ end
+
+ source = item.source
+ %w(url content).each do |name|
+ source.__send__("#{name}=", info["source"][name])
+ end
+
+ category = item.categories.new_category
+ %w(domain content).each do |name|
+ category.__send__("#{name}=", info["category"][name])
+ end
+
+ setup_trackback(item)
+ end
+ end
+
+ def setup_textinput(maker)
+ textinput = maker.textinput
+ info = @textinput_info
+
+ %w(title description name link).each do |name|
+ textinput.__send__("#{name}=", info[name])
+ end
+ end
+
+ def setup_content(target)
+ prefix = "content"
+ %w(encoded).each do |name|
+ target.__send__("#{prefix}_#{name}=", @content_info[name])
+ end
+ end
+
+ def setup_dublin_core(target)
+ prefix = "dc"
+ %w(title description creator subject publisher
+ contributor type format identifier source language
+ relation coverage rights).each do |name|
+ target.__send__("#{prefix}_#{name}=", @dc_info[name])
+ end
+ end
+
+ def setup_syndicate(target)
+ prefix = "sy"
+ %w(updatePeriod updateFrequency updateBase).each do |name|
+ target.__send__("#{prefix}_#{name}=", @sy_info[name])
+ end
+ end
+
+ def setup_trackback(target)
+ target.trackback_ping = @trackback_info["ping"]
+ @trackback_info["abouts"].each do |about|
+ new_about = target.trackback_abouts.new_about
+ new_about.value = about
+ end
+ end
+
+ end
+end
diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb
index bfe39d005b..a3f023e887 100644
--- a/test/rss/test_trackback.rb
+++ b/test/rss/test_trackback.rb
@@ -88,19 +88,19 @@ EOR
@elems.each do |name, value|
@parents.each do |parent|
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
- target_accessor = "resource"
- target = @rss.send(parent).send(accessor)
+ target = @rss.send(parent)
target20 = @rss20.channel.send(parent, -1)
- assert_equal(value, target.send(target_accessor))
+ assert_equal(value, target.send(accessor))
assert_equal(value, target20.send(accessor))
- target.send("#{target_accessor}=", new_value[name].to_s)
if name == :about
# abount is zero or more
+ target.send("#{accessor}=", 0, new_value[name].to_s)
target20.send("#{accessor}=", 0, new_value[name].to_s)
else
+ target.send("#{accessor}=", new_value[name].to_s)
target20.send("#{accessor}=", new_value[name].to_s)
end
- assert_equal(new_value[name], target.send(target_accessor))
+ assert_equal(new_value[name], target.send(accessor))
assert_equal(new_value[name], target20.send(accessor))
end
end
diff --git a/test/rss/test_xml-stylesheet.rb b/test/rss/test_xml-stylesheet.rb
index ab16d6e2ff..c88a858f56 100644
--- a/test/rss/test_xml-stylesheet.rb
+++ b/test/rss/test_xml-stylesheet.rb
@@ -14,7 +14,7 @@ module RSS
{:media => "print", :title => "FOO"},
{:charset => "UTF-8", :alternate => "yes"},
].each do |attrs|
- assert_xml_stylesheet_attrs(XMLStyleSheet.new(*attrs), attrs)
+ assert_xml_stylesheet_attrs(attrs, XMLStyleSheet.new(*attrs))
end
end
@@ -36,7 +36,7 @@ module RSS
:alternate => "yes"},
].each do |attrs|
target, contents = parse_pi(XMLStyleSheet.new(*attrs).to_s)
- assert_xml_stylesheet(target, XMLStyleSheet.new(*contents), attrs)
+ assert_xml_stylesheet(target, attrs, XMLStyleSheet.new(*contents))
end
end
@@ -88,7 +88,7 @@ module RSS
assert_equal(have_href_xsss.size, rss.xml_stylesheets.size)
rss.xml_stylesheets.each_with_index do |stylesheet, i|
target, = parse_pi(stylesheet.to_s)
- assert_xml_stylesheet(target, stylesheet, have_href_xsss[i])
+ assert_xml_stylesheet(target, have_href_xsss[i], stylesheet)
end
end
end