1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rss/test_trackback.rb
kou 9be1ed43c8 * lib/rss/rss.rb (RSS::VERSION): 0.1.0 -> 0.1.1.
* lib/rss: #to_s used #tag.
* test/rss/test_to_s.rb: added.

* lib/rss/maker.rb (RSS::Maker.make): changed API. It's not
  received modules which is used as the second argument.

* lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#alternate):
  changed return value type which is not String but Boolean.

* lib/rss/2.0.rb (RSS::Rss::Channel#ttl): changed return value
  type which is not String but Integer.

* lib/rss/0.9.rb (RSS::Rss::Channel): <skipDays> has <day>s and
  <skipHours> has <hour>s.
* lib/rss/maker/0.9.rb (RSS::Maker::RSS09::Channel): ditto.

* lib/rss/0.9.rb (RSS::Rss::Channel::Item): <item> has <category>s.
* lib/rss/maker/2.0.rb (RSS::Maker::Rss20::Channel::Item): ditto.

* lib/rss/2.0.rb (RSS::Rss::Channel): <channel> has <category>s.
* lib/rss/maker/2.0.rb (RSS::Maker::RSS20::Channel): ditto.

* lib/rss/trackback.rb: parent element has <trackback:about>s.
* lib/rss/maker/trackback.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-19 08:25:25 +00:00

135 lines
3.7 KiB
Ruby

require "cgi"
require "rexml/document"
require "rss-testcase"
require "rss/1.0"
require "rss/2.0"
require "rss/trackback"
module RSS
class TestTrackBack < TestCase
def setup
@prefix = "trackback"
@uri = "http://madskills.com/public/xml/rss/module/trackback/"
@parents = %w(item)
@elems = {
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
:about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
}
@content_nodes = @elems.collect do |name, value|
"<#{@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()}
#{make_item(@content_nodes)}
#{make_textinput()}
EOR
@rss = Parser.parse(@rss_source)
@rss20_source = make_rss20(nil, {@prefix => @uri}) do
make_channel20(nil) do
make_item20(@content_nodes2)
end
end
@rss20 = Parser.parse(@rss20_source, false)
end
def test_parser
assert_nothing_raised do
Parser.parse(@rss_source)
end
@elems.find_all{|k, v| k == :ping}.each do |tag, value|
assert_too_much_tag(tag.to_s, "item") do
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel()}
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
CGI.escapeHTML(value.to_s) +
"\"/>") * 2)}
EOR
end
end
@elems.find_all{|k, v| k == :about}.each do |tag, value|
assert_missing_tag("trackback:ping", "item") do
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel()}
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
CGI.escapeHTML(value.to_s) +
"\"/>") * 2)}
EOR
end
end
end
def test_accessor
new_value = {
:ping => "http://baz.com/trackback/tb.cgi?tb_id=20030808",
:about => "http://hoge.com/trackback/tb.cgi?tb_id=90030808",
}
@elems.each do |name, value|
@parents.each do |parent|
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
target = @rss.send(parent)
target20 = @rss20.channel.send(parent, -1)
assert_equal(value, target.send(accessor))
assert_equal(value, target20.send(accessor))
if name == :about
# abount is zero or more
target.send("#{accessor}=", 0, new_value[name].to_s)
target20.send("#{accessor}=", 0, new_value[name].to_s)
else
target.send("#{accessor}=", new_value[name].to_s)
target20.send("#{accessor}=", new_value[name].to_s)
end
assert_equal(new_value[name], target.send(accessor))
assert_equal(new_value[name], target20.send(accessor))
end
end
end
def test_to_s
@elems.each do |name, value|
excepted = %Q!<#{@prefix}:#{name} rdf:resource="#{CGI.escapeHTML(value)}"/>!
@parents.each do |parent|
meth = "#{RSS::TRACKBACK_PREFIX}_#{name}_element"
meth << "s" if name == :about
assert_equal(excepted, @rss.send(parent).send(meth))
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.attributes["resource"], @elems[elem.name.intern])
end
end
end
end
end
end
end