2004-02-25 06:44:58 -05:00
|
|
|
require "cgi"
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rexml/document"
|
|
|
|
|
2013-02-24 08:10:46 -05:00
|
|
|
require_relative "rss-testcase"
|
2004-03-21 05:03:17 -05:00
|
|
|
|
2004-02-03 09:01:42 -05:00
|
|
|
require "rss/1.0"
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rss/syndication"
|
|
|
|
|
2004-03-21 05:03:17 -05:00
|
|
|
module RSS
|
2004-10-16 00:51:15 -04:00
|
|
|
class TestSyndication < TestCase
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def setup
|
|
|
|
@prefix = "sy"
|
|
|
|
@uri = "http://purl.org/rss/1.0/modules/syndication/"
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@parents = %w(channel)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
t = Time.iso8601("2000-01-01T12:00:05+00:00")
|
|
|
|
class << t
|
|
|
|
alias_method(:to_s, :iso8601)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems = {
|
|
|
|
:updatePeriod => "hourly",
|
2005-11-24 22:43:48 -05:00
|
|
|
:updateFrequency => "2",
|
2004-10-16 00:51:15 -04:00
|
|
|
:updateBase => t,
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@sy_nodes = @elems.collect do |name, value|
|
|
|
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
|
|
|
end.join("\n")
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel(@sy_nodes)}
|
|
|
|
#{make_image()}
|
|
|
|
#{make_item()}
|
|
|
|
#{make_textinput()}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@rss = Parser.parse(@rss_source)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_parser
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_nothing_raised do
|
|
|
|
Parser.parse(@rss_source)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems.each do |tag, value|
|
|
|
|
assert_too_much_tag(tag.to_s, "channel") do
|
|
|
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
|
2004-10-16 00:51:15 -04:00
|
|
|
CGI.escapeHTML(value.to_s) +
|
|
|
|
"</" + @prefix + ":" + tag.to_s + ">") * 2)}
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_item}
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_accessor
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
t = Time.iso8601("2003-01-01T12:00:23+09:00")
|
|
|
|
class << t
|
|
|
|
alias_method(:to_s, :iso8601)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
new_value = {
|
|
|
|
:updatePeriod => "daily",
|
2005-11-24 22:43:48 -05:00
|
|
|
:updateFrequency => "11",
|
2004-10-16 00:51:15 -04:00
|
|
|
:updateBase => t,
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems.each do |name, value|
|
2005-11-24 22:43:48 -05:00
|
|
|
value = value.to_i if name == :updateFrequency
|
2004-10-16 00:51:15 -04:00
|
|
|
@parents.each do |parent|
|
2005-11-24 22:43:48 -05:00
|
|
|
assert_equal(value, @rss.__send__(parent).__send__("sy_#{name}"))
|
|
|
|
@rss.__send__(parent).__send__("sy_#{name}=", new_value[name])
|
|
|
|
new_val = new_value[name]
|
|
|
|
new_val = new_val.to_i if name == :updateFrequency
|
|
|
|
assert_equal(new_val, @rss.__send__(parent).__send__("sy_#{name}"))
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
%w(hourly daily weekly monthly yearly).each do |x|
|
|
|
|
@parents.each do |parent|
|
|
|
|
assert_nothing_raised do
|
2005-11-23 04:49:02 -05:00
|
|
|
@rss.__send__(parent).sy_updatePeriod = x
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
%w(-2 0.3 -0.4).each do |x|
|
|
|
|
@parents.each do |parent|
|
2007-03-17 06:13:25 -04:00
|
|
|
assert_not_available_value("sy:updateBase", x) do
|
2005-11-23 04:49:02 -05:00
|
|
|
@rss.__send__(parent).sy_updateBase = x
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_to_s
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems.each do |name, value|
|
|
|
|
excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
|
|
|
|
@parents.each do |parent|
|
2005-11-23 04:49:02 -05:00
|
|
|
assert_equal(excepted,
|
2007-11-04 15:36:20 -05:00
|
|
|
@rss.__send__(parent).__send__("sy_#{name}_element"))
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
REXML::Document.new(@rss_source).root.each_element do |parent|
|
|
|
|
if @parents.include?(parent.name)
|
|
|
|
parent.each_element do |elem|
|
|
|
|
if elem.namespace == @uri
|
|
|
|
assert_equal(elem.text, @elems[elem.name.intern].to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|