2004-02-25 06:44:58 -05:00
|
|
|
require "cgi"
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rexml/document"
|
|
|
|
|
2004-03-21 05:03:17 -05:00
|
|
|
require "rss-testcase"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@prefix = "sy"
|
|
|
|
@uri = "http://purl.org/rss/1.0/modules/syndication/"
|
|
|
|
|
|
|
|
@parents = %w(channel)
|
|
|
|
|
|
|
|
t = Time.iso8601("2000-01-01T12:00:05+00:00")
|
|
|
|
class << t
|
|
|
|
alias_method(:to_s, :iso8601)
|
|
|
|
end
|
|
|
|
|
|
|
|
@elems = {
|
|
|
|
:updatePeriod => "hourly",
|
|
|
|
:updateFrequency => 2,
|
|
|
|
:updateBase => t,
|
|
|
|
}
|
|
|
|
|
|
|
|
@sy_nodes = @elems.collect do |name, value|
|
|
|
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
|
|
|
end.join("\n")
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
def test_parser
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
Parser.parse(@rss_source)
|
|
|
|
end
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
def test_accessor
|
|
|
|
|
|
|
|
t = Time.iso8601("2003-01-01T12:00:23+09:00")
|
|
|
|
class << t
|
|
|
|
alias_method(:to_s, :iso8601)
|
|
|
|
end
|
|
|
|
|
|
|
|
new_value = {
|
|
|
|
:updatePeriod => "daily",
|
|
|
|
:updateFrequency => +11,
|
|
|
|
:updateBase => t,
|
|
|
|
}
|
|
|
|
|
|
|
|
@elems.each do |name, value|
|
|
|
|
@parents.each do |parent|
|
* ext/tk/lib/tk/font.rb, ext/tk/lib/tkextlib/ICONS/icons.rb,
ext/tk/sample/tkextlib/treectrl/demo.rb, lib/net/imap.rb,
lib/rss/parser.rb, test/rss/test_content.rb,
test/rss/test_dublincore.rb, test/rss/test_syndication.rb,
test/rss/test_trackback.rb, test/ruby/test_eval.rb,
test/socket/test_socket.rb, test/socket/test_udp.rb:
Object#fcall was renamed as Object#funcall.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-10-22 00:48:34 -04:00
|
|
|
assert_equal(value, @rss.send(parent).funcall("sy_#{name}"))
|
|
|
|
@rss.send(parent).funcall("sy_#{name}=", new_value[name].to_s)
|
|
|
|
assert_equal(new_value[name], @rss.send(parent).funcall("sy_#{name}"))
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(hourly daily weekly monthly yearly).each do |x|
|
|
|
|
@parents.each do |parent|
|
|
|
|
assert_nothing_raised do
|
|
|
|
@rss.send(parent).sy_updatePeriod = x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(-2 0.3 -0.4).each do |x|
|
|
|
|
@parents.each do |parent|
|
|
|
|
assert_not_available_value("updateBase", x) do
|
|
|
|
@rss.send(parent).sy_updateBase = x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_to_s
|
|
|
|
|
|
|
|
@elems.each do |name, value|
|
|
|
|
excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
|
|
|
|
@parents.each do |parent|
|
* ext/tk/lib/tk/font.rb, ext/tk/lib/tkextlib/ICONS/icons.rb,
ext/tk/sample/tkextlib/treectrl/demo.rb, lib/net/imap.rb,
lib/rss/parser.rb, test/rss/test_content.rb,
test/rss/test_dublincore.rb, test/rss/test_syndication.rb,
test/rss/test_trackback.rb, test/ruby/test_eval.rb,
test/socket/test_socket.rb, test/socket/test_udp.rb:
Object#fcall was renamed as Object#funcall.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-10-22 00:48:34 -04:00
|
|
|
assert_equal(excepted, @rss.send(parent).funcall("sy_#{name}_element"))
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|