diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-17 10:13:25 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-17 10:13:25 +0000 |
commit | 966a25465aab5c2972e6c453f631a15fc2223256 (patch) | |
tree | 847090e856c9901ab2cc19251c179b9b0985e65b /test/rss/rss-testcase.rb | |
parent | 53cbab048452742b537ac8bccf494630d1c184c8 (diff) |
* lib/rss, test/rss:
- supported Atom.
- bumped version 0.1.6 to 0.1.7.
* sample/rss/convert.rb: added new sample.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rss/rss-testcase.rb')
-rw-r--r-- | test/rss/rss-testcase.rb | 201 |
1 files changed, 197 insertions, 4 deletions
diff --git a/test/rss/rss-testcase.rb b/test/rss/rss-testcase.rb index 0612abcccd..baac597c00 100644 --- a/test/rss/rss-testcase.rb +++ b/test/rss/rss-testcase.rb @@ -3,6 +3,8 @@ require "erb" require "test/unit" require 'rss-assertions' +require "rss" + module RSS class TestCase < Test::Unit::TestCase include ERB::Util @@ -22,7 +24,7 @@ module RSS NAME_VALUE = "hogehoge" LANGUAGE_VALUE = "ja" DESCRIPTION_VALUE = " - XML.com features a rich mix of information and services + XML.com features a rich mix of information and services for the XML community. " RESOURCES = [ @@ -42,6 +44,45 @@ module RSS CATEGORY_DOMAIN = "http://www.superopendirectory.com/" + FEED_TITLE = "dive into mark" + FEED_UPDATED = "2003-12-13T18:30:02Z" + FEED_AUTHOR_NAME = "John Doe" + FEED_ID = "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6" + + ENTRY_TITLE = "Atom-Powered Robots Run Amok" + ENTRY_LINK = "http://example.org/2003/12/13/atom03" + ENTRY_ID = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a" + ENTRY_UPDATED = "2003-12-13T18:30:02Z" + ENTRY_SUMMARY = "Some text." + + t = Time.iso8601("2000-01-01T12:00:05+00:00") + class << t + alias_method(:to_s, :iso8601) + end + + DC_ELEMENTS = { + :title => "hoge", + :description => + " XML is placing increasingly heavy loads on + the existing technical infrastructure of the Internet.", + :creator => "Rael Dornfest (mailto:[email protected])", + :subject => "XML", + :publisher => "The O'Reilly Network", + :contributor => "hogehoge", + :type => "fugafuga", + :format => "hohoho", + :identifier => "fufufu", + :source => "barbar", + :language => "ja", + :relation => "cococo", + :rights => "Copyright (c) 2000 O'Reilly & Associates, Inc.", + :date => t, + } + + DC_NODES = DC_ELEMENTS.collect do |name, value| + "<#{DC_PREFIX}:#{name}>#{value}</#{DC_PREFIX}:#{name}>" + end.join("\n") + def default_test # This class isn't tested end @@ -140,6 +181,15 @@ EOR EORSS end + def make_sample_items20 + RESOURCES.collect do |res| + elems = ["<link>#{res}</link>"] + elems << "<title>title of #{res}</title>" + elems = elems.join("\n") + item = "<item>\n#{elems}\n</item>" + end.join("\n") + end + def make_channel20(content=nil) <<-EOC <channel> @@ -154,7 +204,7 @@ EORSS <link>#{LINK_VALUE}</link> </image> -#{RESOURCES.collect do |res| '<item><link>' + res + '</link></item>' end.join("\n")} +#{make_sample_items20} <textInput> <title>#{TITLE_VALUE}</title> @@ -190,6 +240,88 @@ EOI EOC end + def make_sample_rss20 + make_rss20(<<-EOR) +#{make_channel20} +EOR + end + + def make_feed_without_entry(content=nil, xmlns=[]) + <<-EOA +<feed xmlns="#{Atom::URI}" +#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}> + <id>#{FEED_ID}</id> + <title>#{FEED_TITLE}</title> + <updated>#{FEED_UPDATED}</updated> + <author> + <name>#{FEED_AUTHOR_NAME}</name> + </author> +#{block_given? ? yield : content} +</feed> +EOA + end + + def make_entry(content=nil) + <<-EOA + <entry> + <title>#{ENTRY_TITLE}</title> + <id>#{ENTRY_ID}</id> + <updated>#{ENTRY_UPDATED}</updated> +#{block_given? ? yield : content} + </entry> +EOA + end + + def make_feed_with_open_entry(content=nil, xmlns=[], &block) + make_feed_without_entry(<<-EOA, xmlns) +#{make_entry(content, &block)} +EOA + end + + def make_feed_with_open_entry_source(content=nil, xmlns=[]) + make_feed_with_open_entry(<<-EOA, xmlns) + <source> +#{block_given? ? yield : content} + </source> +EOA + end + + def make_feed(content=nil, xmlns=[]) + make_feed_without_entry(<<-EOA, xmlns) + <entry> + <title>#{ENTRY_TITLE}</title> + <link href="#{ENTRY_LINK}"/> + <id>#{ENTRY_ID}</id> + <updated>#{ENTRY_UPDATED}</updated> + <summary>#{ENTRY_SUMMARY}</summary> + </entry> +#{block_given? ? yield : content} +EOA + end + + def make_entry_document(content=nil, xmlns=[]) + <<-EOA +<entry xmlns="#{Atom::URI}" +#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}> + <id>#{ENTRY_ID}</id> + <title>#{ENTRY_TITLE}</title> + <updated>#{ENTRY_UPDATED}</updated> + <author> + <name>#{FEED_AUTHOR_NAME}</name> + </author> +#{block_given? ? yield : content} +</entry> +EOA + end + + def make_entry_document_with_open_source(content=nil, xmlns=[]) + make_entry_document(<<-EOA, xmlns) + <source> +#{block_given? ? yield : content} + </source> +EOA + end + def make_element(elem_name, attrs, contents) attrs_str = attrs.collect do |name, value| "#{h name}='#{h value}'" @@ -202,10 +334,52 @@ EOC end private + def setup_rss10(rdf) + assert_equal("", rdf.to_s) + + channel = RDF::Channel.new + assert_equal("", channel.to_s) + channel.about = "http://example.com/index.rdf" + channel.title = "title" + channel.link = "http://example.com/" + channel.description = "description" + assert_equal("", channel.to_s) + + item_title = "item title" + item_link = "http://example.com/item" + channel.items = RDF::Channel::Items.new + channel.items.Seq.lis << RDF::Channel::Items::Seq::Li.new(item_link) + assert_not_equal("", channel.to_s) + + rdf.channel = channel + assert_equal("", rdf.to_s) + + item = RDF::Item.new + item.title = item_title + item.link = item_link + item.about = item_link + rdf.items << item + assert_not_equal("", rdf.to_s) + end + + def setup_rss20(rss) + assert_equal("", rss.to_s) + + channel = Rss::Channel.new + assert_equal("", channel.to_s) + channel.title = "title" + channel.link = "http://example.com/" + channel.description = "description" + assert_not_equal("", channel.to_s) + + rss.channel = channel + assert_not_equal("", rss.to_s) + end + def setup_dummy_channel(maker) about = "http://hoge.com" title = "fugafuga" - link = "http://hoge.com" + link = "http://hoge.com/feed.xml" description = "fugafugafugafuga" language = "ja" @@ -216,6 +390,17 @@ EOC maker.channel.language = language end + def setup_dummy_channel_atom(maker) + updated = Time.now + author = "Foo" + + setup_dummy_channel(maker) + maker.channel.links.first.rel = "self" + maker.channel.links.first.type = "application/atom+xml" + maker.channel.updated = updated + maker.channel.author = author + end + def setup_dummy_image(maker) title = "fugafuga" link = "http://hoge.com" @@ -247,7 +432,15 @@ EOC item.title = title item.link = link end - + + def setup_dummy_item_atom(maker) + setup_dummy_item(maker) + + item = maker.items.first + item.id = "http://example.net/xxx" + item.updated = Time.now + end + def setup_taxo_topic(target, topics) topics.each do |topic| taxo_topic = target.taxo_topics.new_taxo_topic |