2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
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-02-13 06:02:03 -05:00
|
|
|
require "rss/2.0"
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rss/trackback"
|
|
|
|
|
2004-03-21 05:03:17 -05:00
|
|
|
module RSS
|
2004-10-16 00:51:15 -04:00
|
|
|
class TestTrackBack < TestCase
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def setup
|
|
|
|
@prefix = "trackback"
|
|
|
|
@uri = "http://madskills.com/public/xml/rss/module/trackback/"
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@parents = %w(item)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems = {
|
|
|
|
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
|
|
|
|
:about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@content_nodes = @elems.collect do |name, value|
|
|
|
|
"<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
|
|
|
|
end.join("\n")
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@content_nodes2 = @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()}
|
|
|
|
#{make_image()}
|
|
|
|
#{make_item(@content_nodes)}
|
|
|
|
#{make_textinput()}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@rss = Parser.parse(@rss_source)
|
2004-02-13 06:02:03 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@rss20_source = make_rss20(nil, {@prefix => @uri}) do
|
|
|
|
make_channel20(nil) do
|
|
|
|
make_item20(@content_nodes2)
|
|
|
|
end
|
|
|
|
end
|
2004-02-13 06:02:03 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@rss20 = Parser.parse(@rss20_source, false)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_parser
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_nothing_raised do
|
|
|
|
Parser.parse(@rss_source)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@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}))
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel()}
|
|
|
|
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
|
2004-10-16 00:51:15 -04:00
|
|
|
CGI.escapeHTML(value.to_s) +
|
|
|
|
"\"/>") * 2)}
|
2004-01-27 22:46:13 -05:00
|
|
|
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
|
|
|
@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}))
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel()}
|
|
|
|
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
|
2004-10-16 00:51:15 -04:00
|
|
|
CGI.escapeHTML(value.to_s) +
|
|
|
|
"\"/>") * 2)}
|
2004-01-27 22:46:13 -05:00
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-03-21 05:03:17 -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
|
|
|
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
|
|
|
new_value = {
|
|
|
|
:ping => "http://baz.com/trackback/tb.cgi?tb_id=20030808",
|
|
|
|
:about => "http://hoge.com/trackback/tb.cgi?tb_id=90030808",
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems.each do |name, value|
|
|
|
|
@parents.each do |parent|
|
|
|
|
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
|
2005-11-23 04:49:02 -05:00
|
|
|
target = @rss.__send__(parent)
|
|
|
|
target20 = @rss20.channel.__send__(parent, -1)
|
|
|
|
assert_equal(value, target.__send__(accessor))
|
|
|
|
assert_equal(value, target20.__send__(accessor))
|
2004-10-16 00:51:15 -04:00
|
|
|
if name == :about
|
|
|
|
# abount is zero or more
|
2005-11-23 04:49:02 -05:00
|
|
|
target.__send__("#{accessor}=", 0, new_value[name].to_s)
|
|
|
|
target20.__send__("#{accessor}=", 0, new_value[name].to_s)
|
2004-10-16 00:51:15 -04:00
|
|
|
else
|
2005-11-23 04:49:02 -05:00
|
|
|
target.__send__("#{accessor}=", new_value[name].to_s)
|
|
|
|
target20.__send__("#{accessor}=", new_value[name].to_s)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2005-11-23 04:49:02 -05:00
|
|
|
assert_equal(new_value[name], target.__send__(accessor))
|
|
|
|
assert_equal(new_value[name], target20.__send__(accessor))
|
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
|
|
|
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 = %Q!<#{@prefix}:#{name} rdf:resource="#{CGI.escapeHTML(value)}"/>!
|
|
|
|
@parents.each do |parent|
|
|
|
|
meth = "#{RSS::TRACKBACK_PREFIX}_#{name}_element"
|
|
|
|
meth << "s" if name == :about
|
2007-11-04 15:36:20 -05:00
|
|
|
assert_equal(excepted, @rss.__send__(parent).__send__(meth))
|
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.attributes["resource"], @elems[elem.name.intern])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -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
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|
2004-03-21 05:03:17 -05:00
|
|
|
|