summaryrefslogtreecommitdiffstats
path: root/test/rss/test_1.0.rb
blob: 485a8c4e0ec9ee4d48c9a9a5e7c2bf5905c7d658 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
require "test/unit"
require "rexml/document"

require "rss/1.0"
require "test/common"

class TestCore < Test::Unit::TestCase

	include TestRSSMixin

	def setup

		@rdf_prefix = "rdf"
		@rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
		@uri = "http://purl.org/rss/1.0/"

	end

	def test_RDF

		version = "1.0"
		encoding = "UTF-8"
		standalone = "no"

		rdf = RDF.new(version, encoding, standalone)

		doc = REXML::Document.new(rdf.to_s(false))

		xmldecl = doc.xml_decl

		%w(version encoding standalone).each do |x|
			assert_equal(instance_eval(x), xmldecl.send(x))
		end
		
		assert_equal(@rdf_uri, doc.root.namespace)

	end

	def test_channel

		about = "http://hoge.com"
		title = "fugafuga"
		link = "http://hoge.com"
		description = "fugafugafugafuga"
		resource = "http://hoge.com/hoge.png"
		image = RDF::Channel::Image.new(resource)
		items = RDF::Channel::Items.new
		textinput = RDF::Channel::Textinput.new(resource)

		channel = RDF::Channel.new(about)
		%w(title link description image items textinput).each do |x|
			channel.send("#{x}=", instance_eval(x))
		end

		doc = REXML::Document.new(make_RDF(channel.to_s))
		c = doc.root.elements[1]

		assert_equal(about, c.attributes["about"])
		%w(title link description image textinput).each do |x|
			elem = c.elements[x]
			assert_equal(x, elem.name)
			assert_equal(@uri, elem.namespace)
			if x == "image" or x == "textinput"
				excepted = resource
				res = elem.attributes.get_attribute("resource")
				assert_equal(@rdf_uri, res.namespace)
				value = res.value
			else
				excepted = instance_eval(x)
				value = elem.text
			end
			assert_equal(excepted, value)
		end
		assert_equal(@uri, c.elements["items"].namespace)
		assert_equal("items", c.elements["items"].name)

	end
	
	def test_channel_image

		resource = "http://hoge.com/hoge.png"
		image = RDF::Channel::Image.new(resource)

		doc = REXML::Document.new(make_RDF(image.to_s))
		i = doc.root.elements[1]

		assert_equal("image", i.name)
		assert_equal(@uri, i.namespace)

		res = i.attributes.get_attribute("resource")

		assert_equal(@rdf_uri, res.namespace)
		assert_equal(resource, res.value)

	end
	
	def test_channel_textinput

		resource = "http://hoge.com/hoge.png"
		textinput = RDF::Channel::Textinput.new(resource)

		doc = REXML::Document.new(make_RDF(textinput.to_s))
		t = doc.root.elements[1]

		assert_equal("textinput", t.name)
		assert_equal(@uri, t.namespace)

		res = t.attributes.get_attribute("resource")

		assert_equal(@rdf_uri, res.namespace)
		assert_equal(resource, res.value)

	end
	
	def test_items

		items = RDF::Channel::Items.new

		doc = REXML::Document.new(make_RDF(items.to_s))
		i = doc.root.elements[1]

		assert_equal("items", i.name)
		assert_equal(@uri, i.namespace)

		assert_equal(1, i.elements.size)
		assert_equal("Seq", i.elements[1].name)
		assert_equal(@rdf_uri, i.elements[1].namespace)

	end
	
	def test_seq

		seq = RDF::Seq.new

		doc = REXML::Document.new(make_RDF(seq.to_s))
		s = doc.root.elements[1]

		assert_equal("Seq", s.name)
		assert_equal(@rdf_uri, s.namespace)

	end

	def test_li

		resource = "http://hoge.com/"
		li = RDF::Li.new(resource)

		doc = REXML::Document.new(make_RDF(li.to_s))
		l = doc.root.elements[1]

		assert_equal("li", l.name)
		assert_equal(@rdf_uri, l.namespace(l.prefix))

		res = l.attributes.get_attribute("resource")
		
		assert_equal('', res.instance_eval("@prefix"))
		assert_equal(resource, res.value)

	end
	
	def test_image

		about = "http://hoge.com"
		title = "fugafuga"
		url = "http://hoge.com/hoge"
		link = "http://hoge.com/fuga"

		image = RDF::Image.new(about)
		%w(title url link).each do |x|
			image.send("#{x}=", instance_eval(x))
		end

		doc = REXML::Document.new(make_RDF(image.to_s))
		i = doc.root.elements[1]

		assert_equal(about, i.attributes["about"])
		%w(title url link).each do |x|
			elem = i.elements[x]
			assert_equal(x, elem.name)
			assert_equal(@uri, elem.namespace)
			assert_equal(instance_eval(x), elem.text)
		end

	end
	
	def test_item

		about = "http://hoge.com"
		title = "fugafuga"
		link = "http://hoge.com/fuga"
		description = "hogehogehoge"

		item = RDF::Item.new(about)
		%w(title link description).each do |x|
			item.send("#{x}=", instance_eval(x))
		end

		doc = REXML::Document.new(make_RDF(item.to_s))
		i = doc.root.elements[1]

		assert_equal(about, i.attributes["about"])
		%w(title link description).each do |x|
			elem = i.elements[x]
			assert_equal(x, elem.name)
			assert_equal(@uri, elem.namespace)
			assert_equal(instance_eval(x), elem.text)
		end

	end
	
	def test_textinput

		about = "http://hoge.com"
		title = "fugafuga"
		link = "http://hoge.com/fuga"
		name = "foo"
		description = "hogehogehoge"

		textinput = RDF::Textinput.new(about)
		%w(title link name description).each do |x|
			textinput.send("#{x}=", instance_eval(x))
		end

		doc = REXML::Document.new(make_RDF(textinput.to_s))
		t = doc.root.elements[1]

		assert_equal(about, t.attributes["about"])
		%w(title link name description).each do |x|
			elem = t.elements[x]
			assert_equal(x, elem.name)
			assert_equal(@uri, elem.namespace)
			assert_equal(instance_eval(x), elem.text)
		end

	end
	
end