summaryrefslogtreecommitdiff
path: root/test/rss/test_content.rb
blob: 46a76b1ae43a6755223ddc23a4dbfec19e303488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require "test/unit"
require "cgi-lib"
require "rexml/document"

require "rss/parser"
require "rss/content"
require "test/common"

class TestContent < Test::Unit::TestCase
	include TestRSSMixin

	def setup
		@prefix = "content"
		@uri = "http://purl.org/rss/1.0/modules/content/"
		
		@parents = %w(item)

		@elems = {
			:encoded => "<em>ATTENTION</em>",
		}

		@content_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})
#{make_channel()}
#{make_image()}
#{make_item(@content_nodes)}
#{make_textinput()}
EOR

		@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, "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)}
EOR
			end
		end

	end
	
	def test_accessor
		
		new_value = {
			:encoded => "<![CDATA[<it>hoge</it>]]>",
		}

		@elems.each do |name, value|
			@parents.each do |parent|
				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))
			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))
			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