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-01-27 22:46:13 -05:00
|
|
|
require "rss/content"
|
|
|
|
|
2004-03-21 05:03:17 -05:00
|
|
|
module RSS
|
2004-10-16 00:51:15 -04:00
|
|
|
class TestContent < TestCase
|
|
|
|
def setup
|
|
|
|
@prefix = "content"
|
|
|
|
@uri = "http://purl.org/rss/1.0/modules/content/"
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems = {
|
|
|
|
:encoded => "<em>ATTENTION</em>",
|
|
|
|
}
|
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}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
|
|
|
end.join("\n")
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-11-02 07:58:03 -04:00
|
|
|
@rss10_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
|
|
|
|
|
2007-11-02 07:58:03 -04:00
|
|
|
@rss10 = Parser.parse(@rss10_source)
|
|
|
|
|
|
|
|
|
|
|
|
@rss20_source = make_rss20(<<-EOR, {@prefix => @uri})
|
|
|
|
#{make_channel20(make_item20(@content_nodes))}
|
|
|
|
EOR
|
|
|
|
|
|
|
|
@rss20 = Parser.parse(@rss20_source)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2007-11-02 07:58:03 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_parser
|
2007-11-02 07:58:03 -04:00
|
|
|
assert_nothing_raised do
|
|
|
|
Parser.parse(@rss10_source)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_nothing_raised do
|
2007-11-02 07:58:03 -04:00
|
|
|
Parser.parse(@rss20_source)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2007-11-02 07:58:03 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems.each do |tag, value|
|
2007-11-02 07:58:03 -04:00
|
|
|
tag_name = "#{@prefix}:#{tag}"
|
|
|
|
content_encodes = make_element(tag_name, {}, value) * 2
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_too_much_tag(tag.to_s, "item") do
|
|
|
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
2007-11-02 07:58:03 -04:00
|
|
|
#{make_channel}
|
|
|
|
#{make_item(content_encodes)}
|
2004-01-27 22:46:13 -05:00
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2007-11-02 07:58:03 -04:00
|
|
|
assert_too_much_tag(tag.to_s, "item") do
|
|
|
|
Parser.parse(make_rss20(<<-EOR, {@prefix => @uri}))
|
|
|
|
#{make_channel20(make_item20(content_encodes))}
|
|
|
|
EOR
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2007-11-02 07:58:03 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_accessor
|
|
|
|
new_value = {
|
|
|
|
:encoded => "<![CDATA[<it>hoge</it>]]>",
|
|
|
|
}
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@elems.each do |name, value|
|
2007-11-02 07:58:03 -04:00
|
|
|
[@rss10, @rss20].each do |rss|
|
2004-10-16 00:51:15 -04:00
|
|
|
meth = "#{RSS::CONTENT_PREFIX}_#{name}"
|
2007-11-02 07:58:03 -04:00
|
|
|
parent = rss.items.last
|
|
|
|
assert_equal(value, parent.__send__(meth))
|
|
|
|
parent.__send__("#{meth}=", new_value[name].to_s)
|
|
|
|
assert_equal(new_value[name], parent.__send__(meth))
|
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
|
|
|
def test_to_s
|
|
|
|
@elems.each do |name, value|
|
2007-11-02 07:58:03 -04:00
|
|
|
excepted = make_element("#{@prefix}:#{name}", {}, value)
|
|
|
|
meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
|
|
|
|
[@rss10, @rss20].each do |rss|
|
2007-11-04 15:36:20 -05:00
|
|
|
assert_equal(excepted, rss.items.last.__send__(meth))
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2007-11-02 07:58:03 -04:00
|
|
|
[@rss10_source, @rss20_source].each do |source|
|
|
|
|
REXML::Document.new(source).root.each_element do |parent|
|
|
|
|
next unless parent.name != "item"
|
2004-10-16 00:51:15 -04:00
|
|
|
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
|