diff options
Diffstat (limited to 'test/rss')
-rw-r--r-- | test/rss/common.rb | 45 | ||||
-rw-r--r-- | test/rss/test_trackback.rb | 33 |
2 files changed, 73 insertions, 5 deletions
diff --git a/test/rss/common.rb b/test/rss/common.rb index d41d79e2db..64bf0100fc 100644 --- a/test/rss/common.rb +++ b/test/rss/common.rb @@ -99,4 +99,49 @@ EOI </textinput> EOT end + + def make_Rss2(content=nil, xmlns=[]) + <<-EORSS +#{make_xmldecl} +<rss version="2.0" +#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}> +#{block_given? ? yield : content} +</rss> +EORSS + end + + def make_channel2(content=nil) + <<-EOC +<channel> + <title>#{TITLE_VALUE}</title> + <link>#{LINK_VALUE}</link> + <description>#{DESCRIPTION_VALUE}</description> + + <image> + <url>#{RDF_RESOURCE}</url> + <title>#{TITLE_VALUE}</title> + <link>#{LINK_VALUE}</link> + </image> + +#{RESOURCES.collect do |res| '<item><link>' + res + '</link></item>' end.join("\n")} + + <textInput> + <link>#{RDF_RESOURCE}</link> + </textInput> + +#{block_given? ? yield : content} +</channel> +EOC + end + + def make_item2(content=nil) + <<-EOI +<item> + <title>#{TITLE_VALUE}</title> + <link>#{LINK_VALUE}</link> + <description>#{DESCRIPTION_VALUE}</description> +#{block_given? ? yield : content} +</item> +EOI + end end diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb index 85ab533617..936f3683f0 100644 --- a/test/rss/test_trackback.rb +++ b/test/rss/test_trackback.rb @@ -5,6 +5,7 @@ require "cgi-lib" require "rexml/document" require "rss/1.0" +require "rss/2.0" require "rss/trackback" require "common" @@ -26,6 +27,10 @@ class TestTrackBack < Test::Unit::TestCase "<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>" end.join("\n") + @content_nodes2 = @elems.collect do |name, value| + "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>" + end.join("\n") + @rss_source = make_RDF(<<-EOR, {@prefix => @uri}) #{make_channel()} #{make_image()} @@ -34,6 +39,14 @@ class TestTrackBack < Test::Unit::TestCase EOR @rss = Parser.parse(@rss_source) + + @rss2_source = make_Rss2(nil, {@prefix => @uri}) do + make_channel2(nil) do + make_item2(@content_nodes2) + end + end + + @rss2 = Parser.parse(@rss2_source, false) end def test_parser @@ -76,11 +89,21 @@ EOR @elems.each do |name, value| @parents.each do |parent| - elem = @rss.send(parent).send("#{RSS::TRACKBACK_PREFIX}_#{name}") - meth = "resource" - assert_equal(value, elem.send(meth)) - elem.send("#{meth}=", new_value[name].to_s) - assert_equal(new_value[name], elem.send(meth)) + accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}" + target_accessor = "resource" + target = @rss.send(parent).send(accessor) + target2 = @rss2.channel.send(parent, -1) + assert_equal(value, target.send(target_accessor)) + assert_equal(value, target2.send(accessor)) + target.send("#{target_accessor}=", new_value[name].to_s) + if name == :about + # abount is zero or more + target2.send("#{accessor}=", 0, new_value[name].to_s) + else + target2.send("#{accessor}=", new_value[name].to_s) + end + assert_equal(new_value[name], target.send(target_accessor)) + assert_equal(new_value[name], target2.send(accessor)) end end |