summaryrefslogtreecommitdiff
path: root/test/rss/test_content.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rss/test_content.rb')
-rw-r--r--test/rss/test_content.rb68
1 files changed, 39 insertions, 29 deletions
diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb
index 70d456f..02db591 100644
--- a/test/rss/test_content.rb
+++ b/test/rss/test_content.rb
@@ -3,18 +3,14 @@ require "rexml/document"
require "rss-testcase"
-require "rss/1.0"
require "rss/content"
module RSS
class TestContent < TestCase
-
def setup
@prefix = "content"
@uri = "http://purl.org/rss/1.0/modules/content/"
- @parents = %w(item)
-
@elems = {
:encoded => "<em>ATTENTION</em>",
}
@@ -23,63 +19,79 @@ module RSS
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
end.join("\n")
- @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+ @rss10_source = make_RDF(<<-EOR, {@prefix => @uri})
#{make_channel()}
#{make_image()}
#{make_item(@content_nodes)}
#{make_textinput()}
EOR
- @rss = Parser.parse(@rss_source)
+ @rss10 = Parser.parse(@rss10_source)
+
+
+ @rss20_source = make_rss20(<<-EOR, {@prefix => @uri})
+#{make_channel20(make_item20(@content_nodes))}
+EOR
+
+ @rss20 = Parser.parse(@rss20_source)
end
-
+
def test_parser
+ assert_nothing_raised do
+ Parser.parse(@rss10_source)
+ end
assert_nothing_raised do
- Parser.parse(@rss_source)
+ Parser.parse(@rss20_source)
end
-
+
@elems.each do |tag, value|
+ tag_name = "#{@prefix}:#{tag}"
+ content_encodes = make_element(tag_name, {}, value) * 2
+
assert_too_much_tag(tag.to_s, "item") do
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
-#{make_channel()}
-#{make_item(("<" + @prefix + ":" + tag.to_s + ">" +
- CGI.escapeHTML(value.to_s) +
- "</" + @prefix + ":" + tag.to_s + ">") * 2)}
+#{make_channel}
+#{make_item(content_encodes)}
EOR
end
- end
+ 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
end
-
+
def test_accessor
-
new_value = {
:encoded => "<![CDATA[<it>hoge</it>]]>",
}
@elems.each do |name, value|
- @parents.each do |parent|
+ [@rss10, @rss20].each do |rss|
meth = "#{RSS::CONTENT_PREFIX}_#{name}"
- assert_equal(value, @rss.__send__(parent).__send__(meth))
- @rss.__send__(parent).__send__("#{meth}=", new_value[name].to_s)
- assert_equal(new_value[name], @rss.__send__(parent).__send__(meth))
+ 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))
end
end
-
end
def test_to_s
@elems.each do |name, value|
- excepted = "<#{@prefix}:#{name}>#{CGI.escapeHTML(value)}</#{@prefix}:#{name}>"
- @parents.each do |parent|
- meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
- assert_equal(excepted, @rss.__send__(parent).__send__(meth))
+ excepted = make_element("#{@prefix}:#{name}", {}, value)
+ meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
+ [@rss10, @rss20].each do |rss|
+ assert_equal(excepted, rss.items.last.__send__(meth))
end
end
- REXML::Document.new(@rss_source).root.each_element do |parent|
- if @parents.include?(parent.name)
+ [@rss10_source, @rss20_source].each do |source|
+ REXML::Document.new(source).root.each_element do |parent|
+ next unless parent.name != "item"
parent.each_element do |elem|
if elem.namespace == @uri
assert_equal(elem.text, @elems[elem.name.intern].to_s)
@@ -87,8 +99,6 @@ EOR
end
end
end
-
end
-
end
end