/source/ruby-1.9.2-p180/test/rss/rss-testcase.rb
Ruby | 478 lines | 380 code | 69 blank | 29 comment | 5 complexity | e92143a752873ccbce64fe9ac74b477b MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
- require "erb"
- require "test/unit"
- require 'rss-assertions'
- require "rss"
- module RSS
- class TestCase < Test::Unit::TestCase
- include ERB::Util
- include RSS
- include Assertions
- XMLDECL_VERSION = "1.0"
- XMLDECL_ENCODING = "UTF-8"
- XMLDECL_STANDALONE = "no"
- RDF_ABOUT = "http://www.xml.com/xml/news.rss"
- RDF_RESOURCE = "http://xml.com/universal/images/xml_tiny.gif"
- TITLE_VALUE = "XML.com"
- LINK_VALUE = "http://xml.com/pub"
- URL_VALUE = "http://xml.com/universal/images/xml_tiny.gif"
- NAME_VALUE = "hogehoge"
- LANGUAGE_VALUE = "ja"
- DESCRIPTION_VALUE = "
- XML.com features a rich mix of information and services
- for the XML community.
- "
- RESOURCES = [
- "http://xml.com/pub/2000/08/09/xslt/xslt.html",
- "http://xml.com/pub/2000/08/09/rdfdb/index.html",
- ]
- CLOUD_DOMAIN = "data.ourfavoritesongs.com"
- CLOUD_PORT = "80"
- CLOUD_PATH = "/RPC2"
- CLOUD_REGISTER_PROCEDURE = "ourFavoriteSongs.rssPleaseNotify"
- CLOUD_PROTOCOL = "xml-rpc"
- ENCLOSURE_URL = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
- ENCLOSURE_LENGTH = "12216320"
- ENCLOSURE_TYPE = "audio/mpeg"
- 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:rael@oreilly.com)",
- :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
- private
- def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE)
- rv = "<?xml version='#{v}'"
- rv << " encoding='#{e}'" if e
- rv << " standalone='#{s}'" if s
- rv << "?>"
- rv
- end
- def make_RDF(content=nil, xmlns=[])
- <<-EORSS
- #{make_xmldecl}
- <rdf:RDF xmlns="#{URI}" xmlns:rdf="#{RDF::URI}"
- #{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
- #{block_given? ? yield : content}
- </rdf:RDF>
- EORSS
- end
- def make_channel(content=nil)
- <<-EOC
- <channel rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
- <image rdf:resource="#{RDF_RESOURCE}" />
- <items>
- <rdf:Seq>
- #{RESOURCES.collect do |res| '<rdf:li resource="' + res + '" />' end.join("\n")}
- </rdf:Seq>
- </items>
- <textinput rdf:resource="#{RDF_RESOURCE}" />
- #{block_given? ? yield : content}
- </channel>
- EOC
- end
- def make_image(content=nil)
- <<-EOI
- <image rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <url>#{URL_VALUE}</url>
- <link>#{LINK_VALUE}</link>
- #{block_given? ? yield : content}
- </image>
- EOI
- end
- def make_item(content=nil)
- <<-EOI
- <item rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
- #{block_given? ? yield : content}
- </item>
- EOI
- end
- def make_textinput(content=nil)
- <<-EOT
- <textinput rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <description>#{DESCRIPTION_VALUE}</description>
- <name>#{NAME_VALUE}</name>
- <link>#{LINK_VALUE}</link>
- #{block_given? ? yield : content}
- </textinput>
- EOT
- end
- def make_sample_RDF
- make_RDF(<<-EOR)
- #{make_channel}
- #{make_image}
- #{make_item}
- #{make_textinput}
- EOR
- end
- def make_rss20(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_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>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
- <language>#{LANGUAGE_VALUE}</language>
- <image>
- <url>#{RDF_RESOURCE}</url>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- </image>
- #{make_sample_items20}
- <textInput>
- <title>#{TITLE_VALUE}</title>
- <description>#{DESCRIPTION_VALUE}</description>
- <name>#{NAME_VALUE}</name>
- <link>#{RDF_RESOURCE}</link>
- </textInput>
- #{block_given? ? yield : content}
- </channel>
- EOC
- end
- def make_item20(content=nil)
- <<-EOI
- <item>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
- #{block_given? ? yield : content}
- </item>
- EOI
- end
- def make_cloud20
- <<-EOC
- <cloud
- domain="#{CLOUD_DOMAIN}"
- port="#{CLOUD_PORT}"
- path="#{CLOUD_PATH}"
- registerProcedure="#{CLOUD_REGISTER_PROCEDURE}"
- protocol="#{CLOUD_PROTOCOL}" />
- EOC
- end
- def make_sample_rss20
- make_rss20(<<-EOR)
- #{make_channel20}
- EOR
- end