rss 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +38 -0
- data/README.md +11 -11
- data/lib/rss/itunes.rb +10 -1
- data/lib/rss/maker/itunes.rb +2 -0
- data/lib/rss/rss.rb +43 -15
- data/lib/rss/utils.rb +0 -18
- data/lib/rss/version.rb +1 -1
- data/lib/rss/xml-stylesheet.rb +3 -4
- data/lib/rss/xml.rb +3 -2
- data/lib/rss.rb +11 -11
- metadata +7 -101
- data/Gemfile +0 -6
- data/Rakefile +0 -15
- data/rss.gemspec +0 -30
- data/test/dot.png +0 -0
- data/test/rss-assertions.rb +0 -2116
- data/test/rss-testcase.rb +0 -479
- data/test/run-test.rb +0 -15
- data/test/test_1.0.rb +0 -308
- data/test/test_2.0.rb +0 -412
- data/test/test_accessor.rb +0 -104
- data/test/test_atom.rb +0 -684
- data/test/test_content.rb +0 -105
- data/test/test_dublincore.rb +0 -270
- data/test/test_image.rb +0 -215
- data/test/test_inherit.rb +0 -41
- data/test/test_itunes.rb +0 -360
- data/test/test_maker_0.9.rb +0 -477
- data/test/test_maker_1.0.rb +0 -519
- data/test/test_maker_2.0.rb +0 -758
- data/test/test_maker_atom_entry.rb +0 -394
- data/test/test_maker_atom_feed.rb +0 -455
- data/test/test_maker_content.rb +0 -48
- data/test/test_maker_dc.rb +0 -150
- data/test/test_maker_image.rb +0 -63
- data/test/test_maker_itunes.rb +0 -488
- data/test/test_maker_slash.rb +0 -38
- data/test/test_maker_sy.rb +0 -45
- data/test/test_maker_taxo.rb +0 -82
- data/test/test_maker_trackback.rb +0 -42
- data/test/test_maker_xml-stylesheet.rb +0 -84
- data/test/test_parser.rb +0 -122
- data/test/test_parser_1.0.rb +0 -529
- data/test/test_parser_2.0.rb +0 -123
- data/test/test_parser_atom_entry.rb +0 -164
- data/test/test_parser_atom_feed.rb +0 -277
- data/test/test_setup_maker_0.9.rb +0 -247
- data/test/test_setup_maker_1.0.rb +0 -551
- data/test/test_setup_maker_2.0.rb +0 -309
- data/test/test_setup_maker_atom_entry.rb +0 -410
- data/test/test_setup_maker_atom_feed.rb +0 -446
- data/test/test_setup_maker_itunes.rb +0 -146
- data/test/test_setup_maker_slash.rb +0 -39
- data/test/test_slash.rb +0 -65
- data/test/test_syndication.rb +0 -126
- data/test/test_taxonomy.rb +0 -173
- data/test/test_to_s.rb +0 -701
- data/test/test_trackback.rb +0 -136
- data/test/test_xml-stylesheet.rb +0 -109
data/test/test_content.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require "cgi"
|
3
|
-
require "rexml/document"
|
4
|
-
|
5
|
-
require_relative "rss-testcase"
|
6
|
-
|
7
|
-
require "rss/content"
|
8
|
-
|
9
|
-
module RSS
|
10
|
-
class TestContent < TestCase
|
11
|
-
def setup
|
12
|
-
@prefix = "content"
|
13
|
-
@uri = "http://purl.org/rss/1.0/modules/content/"
|
14
|
-
|
15
|
-
@elems = {
|
16
|
-
:encoded => "<em>ATTENTION</em>",
|
17
|
-
}
|
18
|
-
|
19
|
-
@content_nodes = @elems.collect do |name, value|
|
20
|
-
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
21
|
-
end.join("\n")
|
22
|
-
|
23
|
-
@rss10_source = make_RDF(<<-EOR, {@prefix => @uri})
|
24
|
-
#{make_channel()}
|
25
|
-
#{make_image()}
|
26
|
-
#{make_item(@content_nodes)}
|
27
|
-
#{make_textinput()}
|
28
|
-
EOR
|
29
|
-
|
30
|
-
@rss10 = Parser.parse(@rss10_source)
|
31
|
-
|
32
|
-
|
33
|
-
@rss20_source = make_rss20(<<-EOR, {@prefix => @uri})
|
34
|
-
#{make_channel20(make_item20(@content_nodes))}
|
35
|
-
EOR
|
36
|
-
|
37
|
-
@rss20 = Parser.parse(@rss20_source)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_parser
|
41
|
-
assert_nothing_raised do
|
42
|
-
Parser.parse(@rss10_source)
|
43
|
-
end
|
44
|
-
|
45
|
-
assert_nothing_raised do
|
46
|
-
Parser.parse(@rss20_source)
|
47
|
-
end
|
48
|
-
|
49
|
-
@elems.each do |tag, value|
|
50
|
-
tag_name = "#{@prefix}:#{tag}"
|
51
|
-
content_encodes = make_element(tag_name, {}, value) * 2
|
52
|
-
|
53
|
-
assert_too_much_tag(tag.to_s, "item") do
|
54
|
-
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
55
|
-
#{make_channel}
|
56
|
-
#{make_item(content_encodes)}
|
57
|
-
EOR
|
58
|
-
end
|
59
|
-
|
60
|
-
assert_too_much_tag(tag.to_s, "item") do
|
61
|
-
Parser.parse(make_rss20(<<-EOR, {@prefix => @uri}))
|
62
|
-
#{make_channel20(make_item20(content_encodes))}
|
63
|
-
EOR
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_accessor
|
69
|
-
new_value = {
|
70
|
-
:encoded => "<![CDATA[<it>hoge</it>]]>",
|
71
|
-
}
|
72
|
-
|
73
|
-
@elems.each do |name, value|
|
74
|
-
[@rss10, @rss20].each do |rss|
|
75
|
-
meth = "#{RSS::CONTENT_PREFIX}_#{name}"
|
76
|
-
parent = rss.items.last
|
77
|
-
assert_equal(value, parent.__send__(meth))
|
78
|
-
parent.__send__("#{meth}=", new_value[name].to_s)
|
79
|
-
assert_equal(new_value[name], parent.__send__(meth))
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_to_s
|
85
|
-
@elems.each do |name, value|
|
86
|
-
excepted = make_element("#{@prefix}:#{name}", {}, value)
|
87
|
-
meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
|
88
|
-
[@rss10, @rss20].each do |rss|
|
89
|
-
assert_equal(excepted, rss.items.last.__send__(meth))
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
[@rss10_source, @rss20_source].each do |source|
|
94
|
-
REXML::Document.new(source).root.each_element do |parent|
|
95
|
-
next unless parent.name != "item"
|
96
|
-
parent.each_element do |elem|
|
97
|
-
if elem.namespace == @uri
|
98
|
-
assert_equal(elem.text, @elems[elem.name.intern].to_s)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
data/test/test_dublincore.rb
DELETED
@@ -1,270 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require "cgi"
|
3
|
-
require "rexml/document"
|
4
|
-
|
5
|
-
require_relative "rss-testcase"
|
6
|
-
|
7
|
-
require "rss/1.0"
|
8
|
-
require "rss/dublincore"
|
9
|
-
|
10
|
-
module RSS
|
11
|
-
class TestDublinCore < TestCase
|
12
|
-
def setup
|
13
|
-
@rss10_parents = [%w(channel), %w(image), %w(item), %w(textinput)]
|
14
|
-
|
15
|
-
@rss10_source = make_RDF(<<-EOR, {DC_PREFIX => DC_URI})
|
16
|
-
#{make_channel(DC_NODES)}
|
17
|
-
#{make_image(DC_NODES)}
|
18
|
-
#{make_item(DC_NODES)}
|
19
|
-
#{make_textinput(DC_NODES)}
|
20
|
-
EOR
|
21
|
-
|
22
|
-
@rss20_parents = [%w(channel), %w(items last)]
|
23
|
-
|
24
|
-
@rss20_source = make_rss20(<<-EOR, {DC_PREFIX => DC_URI})
|
25
|
-
#{make_channel20(DC_NODES + make_item20(DC_NODES))}
|
26
|
-
EOR
|
27
|
-
|
28
|
-
@atom_feed_parents = [[], %w(entries last)]
|
29
|
-
|
30
|
-
@atom_feed_source = make_feed(<<-EOR, {DC_PREFIX => DC_URI})
|
31
|
-
#{DC_NODES}
|
32
|
-
#{make_entry(DC_NODES)}
|
33
|
-
EOR
|
34
|
-
|
35
|
-
@atom_entry_parents = [[]]
|
36
|
-
|
37
|
-
@atom_entry_source = make_entry_document(<<-EOR, {DC_PREFIX => DC_URI})
|
38
|
-
#{DC_NODES}
|
39
|
-
EOR
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_parser
|
43
|
-
rss10_maker = Proc.new do |content, xmlns|
|
44
|
-
make_RDF(<<-EOR, xmlns)
|
45
|
-
#{make_channel(content)}
|
46
|
-
#{make_image(content)}
|
47
|
-
#{make_item(content)}
|
48
|
-
#{make_textinput(content)}
|
49
|
-
EOR
|
50
|
-
end
|
51
|
-
assert_dc_parse(@rss10_source, @rss10_parents, false, &rss10_maker)
|
52
|
-
assert_dc_parse(@rss10_source, @rss10_parents, true, &rss10_maker)
|
53
|
-
|
54
|
-
rss20_maker = Proc.new do |content, xmlns|
|
55
|
-
make_rss20(<<-EOR, xmlns)
|
56
|
-
#{make_channel20(content + make_item20(content))}
|
57
|
-
EOR
|
58
|
-
end
|
59
|
-
assert_dc_parse(@rss20_source, @rss20_parents, false, &rss20_maker)
|
60
|
-
assert_dc_parse(@rss20_source, @rss20_parents, true, &rss20_maker)
|
61
|
-
|
62
|
-
atom_feed_maker = Proc.new do |content, xmlns|
|
63
|
-
make_feed(<<-EOR, xmlns)
|
64
|
-
#{content}
|
65
|
-
#{make_entry(content)}
|
66
|
-
EOR
|
67
|
-
end
|
68
|
-
assert_dc_parse(@atom_feed_source, @atom_feed_parents, false,
|
69
|
-
&atom_feed_maker)
|
70
|
-
assert_dc_parse(@atom_feed_source, @atom_feed_parents, true,
|
71
|
-
&atom_feed_maker)
|
72
|
-
|
73
|
-
atom_entry_maker = Proc.new do |content, xmlns|
|
74
|
-
make_entry_document(<<-EOR, xmlns)
|
75
|
-
#{content}
|
76
|
-
EOR
|
77
|
-
end
|
78
|
-
assert_dc_parse(@atom_entry_source, @atom_entry_parents, false,
|
79
|
-
&atom_entry_maker)
|
80
|
-
assert_dc_parse(@atom_entry_source, @atom_entry_parents, true,
|
81
|
-
&atom_entry_maker)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_singular_accessor
|
85
|
-
assert_dc_singular_accessor(@rss10_source, @rss10_parents)
|
86
|
-
assert_dc_singular_accessor(@rss20_source, @rss20_parents)
|
87
|
-
assert_dc_singular_accessor(@atom_feed_source, @atom_feed_parents)
|
88
|
-
assert_dc_singular_accessor(@atom_entry_source, @atom_entry_parents)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_plural_accessor
|
92
|
-
assert_dc_plural_accessor(@rss10_source, @rss10_parents, false)
|
93
|
-
assert_dc_plural_accessor(@rss10_source, @rss10_parents, true)
|
94
|
-
|
95
|
-
assert_dc_plural_accessor(@rss20_source, @rss20_parents, false)
|
96
|
-
assert_dc_plural_accessor(@rss20_source, @rss20_parents, true)
|
97
|
-
|
98
|
-
assert_dc_plural_accessor(@atom_feed_source, @atom_feed_parents, false)
|
99
|
-
assert_dc_plural_accessor(@atom_feed_source, @atom_feed_parents, true)
|
100
|
-
|
101
|
-
assert_dc_plural_accessor(@atom_entry_source, @atom_entry_parents, false)
|
102
|
-
assert_dc_plural_accessor(@atom_entry_source, @atom_entry_parents, true)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_to_s
|
106
|
-
assert_dc_to_s(@rss10_source, @rss10_parents, false)
|
107
|
-
assert_dc_to_s(@rss10_source, @rss10_parents, true)
|
108
|
-
|
109
|
-
targets = ["channel", "channel/item[3]"]
|
110
|
-
assert_dc_to_s(@rss20_source, @rss20_parents, false, targets)
|
111
|
-
assert_dc_to_s(@rss20_source, @rss20_parents, true, targets)
|
112
|
-
|
113
|
-
targets = [".", "entry"]
|
114
|
-
assert_dc_to_s(@atom_feed_source, @atom_feed_parents, false, targets)
|
115
|
-
assert_dc_to_s(@atom_feed_source, @atom_feed_parents, true, targets)
|
116
|
-
|
117
|
-
targets = ["."]
|
118
|
-
assert_dc_to_s(@atom_entry_source, @atom_entry_parents, false, targets)
|
119
|
-
assert_dc_to_s(@atom_entry_source, @atom_entry_parents, true, targets)
|
120
|
-
end
|
121
|
-
|
122
|
-
private
|
123
|
-
def dc_plural_suffix(name, check_backward_compatibility)
|
124
|
-
if name == :rights
|
125
|
-
if check_backward_compatibility
|
126
|
-
"es"
|
127
|
-
else
|
128
|
-
"_list"
|
129
|
-
end
|
130
|
-
else
|
131
|
-
"s"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def assert_dc_parse(source, parents, check_backward_compatibility, &maker)
|
136
|
-
assert_nothing_raised do
|
137
|
-
Parser.parse(source)
|
138
|
-
end
|
139
|
-
|
140
|
-
DC_ELEMENTS.each do |name, value|
|
141
|
-
parents.each do |parent_readers|
|
142
|
-
feed = nil
|
143
|
-
assert_nothing_raised do
|
144
|
-
tag = "#{DC_PREFIX}:#{name}"
|
145
|
-
dc_content = "<#{tag}>#{value}</#{tag}>\n"
|
146
|
-
dc_content *= 2
|
147
|
-
feed = Parser.parse(maker.call(dc_content, {DC_PREFIX => DC_URI}))
|
148
|
-
end
|
149
|
-
parent = chain_reader(feed, parent_readers)
|
150
|
-
|
151
|
-
plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
|
152
|
-
plural_reader = "dc_#{name}#{plural_suffix}"
|
153
|
-
values = parent.__send__(plural_reader).collect(&:value)
|
154
|
-
value = CGI.unescapeHTML(value) if value.kind_of?(String)
|
155
|
-
assert_equal([value, value], values)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def assert_dc_singular_accessor(source, parents)
|
161
|
-
feed = Parser.parse(source)
|
162
|
-
new_value = "hoge"
|
163
|
-
|
164
|
-
parents.each do |parent_readers|
|
165
|
-
parent = chain_reader(feed, parent_readers)
|
166
|
-
DC_ELEMENTS.each do |name, value|
|
167
|
-
parsed_value = parent.__send__("dc_#{name}")
|
168
|
-
value = CGI.unescapeHTML(value) if value.kind_of?(String)
|
169
|
-
assert_equal(value, parsed_value)
|
170
|
-
if name == :date
|
171
|
-
t = Time.iso8601("2003-01-01T02:30:23+09:00")
|
172
|
-
class << t
|
173
|
-
alias_method(:to_s, :iso8601)
|
174
|
-
end
|
175
|
-
parent.__send__("dc_#{name}=", t.iso8601)
|
176
|
-
assert_equal(t, parent.__send__("dc_#{name}"))
|
177
|
-
if parent.class.method_defined?(:date_without_dc_date=)
|
178
|
-
assert_nil(parent.date)
|
179
|
-
else
|
180
|
-
assert_equal(t, parent.date)
|
181
|
-
end
|
182
|
-
|
183
|
-
parent.date = value
|
184
|
-
assert_equal(value, parent.date)
|
185
|
-
assert_equal(value, parent.__send__("dc_#{name}"))
|
186
|
-
else
|
187
|
-
parent.__send__("dc_#{name}=", new_value)
|
188
|
-
assert_equal(new_value, parent.__send__("dc_#{name}"))
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def assert_dc_plural_accessor(source, parents, check_backward_compatibility)
|
195
|
-
feed = Parser.parse(source)
|
196
|
-
new_value = "hoge"
|
197
|
-
|
198
|
-
DC_ELEMENTS.each do |name, value|
|
199
|
-
parents.each do |parent_readers|
|
200
|
-
parent = chain_reader(feed, parent_readers)
|
201
|
-
parsed_value = parent.__send__("dc_#{name}")
|
202
|
-
value = CGI.unescapeHTML(value) if value.kind_of?(String)
|
203
|
-
assert_equal(value, parsed_value)
|
204
|
-
|
205
|
-
plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
|
206
|
-
plural_reader = "dc_#{name}#{plural_suffix}"
|
207
|
-
klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
|
208
|
-
klass = DublinCoreModel.const_get(klass_name)
|
209
|
-
if name == :date
|
210
|
-
t = Time.iso8601("2003-01-01T02:30:23+09:00")
|
211
|
-
class << t
|
212
|
-
alias_method(:to_s, :iso8601)
|
213
|
-
end
|
214
|
-
elems = parent.__send__(plural_reader)
|
215
|
-
elems << klass.new(t.iso8601)
|
216
|
-
new_elems = parent.__send__(plural_reader)
|
217
|
-
values = new_elems.collect{|x| x.value}
|
218
|
-
assert_equal([parent.__send__("dc_#{name}"), t], values)
|
219
|
-
else
|
220
|
-
elems = parent.__send__(plural_reader)
|
221
|
-
elems << klass.new(new_value)
|
222
|
-
new_elems = parent.__send__(plural_reader)
|
223
|
-
values = new_elems.collect{|x| x.value}
|
224
|
-
assert_equal([parent.__send__("dc_#{name}"), new_value],
|
225
|
-
values)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def assert_dc_to_s(source, parents, check_backward_compatibility,
|
232
|
-
targets=nil)
|
233
|
-
feed = Parser.parse(source)
|
234
|
-
|
235
|
-
DC_ELEMENTS.each do |name, value|
|
236
|
-
excepted = "<#{DC_PREFIX}:#{name}>#{value}</#{DC_PREFIX}:#{name}>"
|
237
|
-
parents.each do |parent_readers|
|
238
|
-
parent = chain_reader(feed, parent_readers)
|
239
|
-
assert_equal(excepted, parent.__send__("dc_#{name}_elements"))
|
240
|
-
end
|
241
|
-
|
242
|
-
plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
|
243
|
-
reader = "dc_#{name}#{plural_suffix}"
|
244
|
-
excepted = Array.new(2, excepted).join("\n")
|
245
|
-
parents.each do |parent_readers|
|
246
|
-
parent = chain_reader(feed, parent_readers)
|
247
|
-
elems = parent.__send__(reader)
|
248
|
-
klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
|
249
|
-
klass = DublinCoreModel.const_get(klass_name)
|
250
|
-
elems << klass.new(parent.__send__("dc_#{name}"))
|
251
|
-
assert_equal(excepted, parent.__send__("dc_#{name}_elements"))
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
targets ||= parents.collect do |parent_readers|
|
256
|
-
parent_readers.first
|
257
|
-
end
|
258
|
-
feed_root = REXML::Document.new(source).root
|
259
|
-
targets.each do |target_xpath|
|
260
|
-
parent = feed_root.elements[target_xpath]
|
261
|
-
parent.each_element do |elem|
|
262
|
-
if elem.namespace == DC_URI
|
263
|
-
assert_equal(elem.text,
|
264
|
-
CGI.unescapeHTML(DC_ELEMENTS[elem.name.intern].to_s))
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
data/test/test_image.rb
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require "cgi"
|
3
|
-
require "rexml/document"
|
4
|
-
|
5
|
-
require_relative "rss-testcase"
|
6
|
-
|
7
|
-
require "rss/1.0"
|
8
|
-
require "rss/image"
|
9
|
-
|
10
|
-
module RSS
|
11
|
-
class TestImage < TestCase
|
12
|
-
|
13
|
-
def setup
|
14
|
-
@prefix = "image"
|
15
|
-
@uri = "http://purl.org/rss/1.0/modules/image/"
|
16
|
-
|
17
|
-
@favicon_attrs = {
|
18
|
-
"rdf:about" => "http://www.kuro5hin.org/favicon.ico",
|
19
|
-
"#{@prefix}:size" => "small",
|
20
|
-
}
|
21
|
-
@favicon_contents = {"dc:title" => "Kuro5hin",}
|
22
|
-
@items = [
|
23
|
-
[
|
24
|
-
{
|
25
|
-
"rdf:about" => "http://www.example.org/item.png",
|
26
|
-
"rdf:resource" => "http://www.example.org/item",
|
27
|
-
},
|
28
|
-
{
|
29
|
-
"dc:title" => "Example Image",
|
30
|
-
"#{@prefix}:width" => "100",
|
31
|
-
"#{@prefix}:height" => "65",
|
32
|
-
},
|
33
|
-
],
|
34
|
-
[
|
35
|
-
{
|
36
|
-
"rdf:about" => "http://www.kuro5hin.org/images/topics/culture.jpg",
|
37
|
-
},
|
38
|
-
{
|
39
|
-
"dc:title" => "Culture",
|
40
|
-
"#{@prefix}:width" => "80",
|
41
|
-
"#{@prefix}:height" => "50",
|
42
|
-
},
|
43
|
-
]
|
44
|
-
]
|
45
|
-
|
46
|
-
|
47
|
-
@channel_nodes = make_element("#{@prefix}:favicon",
|
48
|
-
@favicon_attrs,
|
49
|
-
@favicon_contents)
|
50
|
-
items = ""
|
51
|
-
@items.each do |attrs, contents|
|
52
|
-
image_item = make_element("#{@prefix}:item", attrs, contents)
|
53
|
-
items << make_item(image_item)
|
54
|
-
end
|
55
|
-
|
56
|
-
@ns = {
|
57
|
-
@prefix => @uri,
|
58
|
-
DC_PREFIX => DC_URI,
|
59
|
-
}
|
60
|
-
@rss_source = make_RDF(<<-EOR, @ns)
|
61
|
-
#{make_channel(@channel_nodes)}
|
62
|
-
#{make_image}
|
63
|
-
#{items}
|
64
|
-
#{make_textinput}
|
65
|
-
EOR
|
66
|
-
|
67
|
-
@rss = Parser.parse(@rss_source)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_parser
|
71
|
-
assert_nothing_raised do
|
72
|
-
Parser.parse(@rss_source)
|
73
|
-
end
|
74
|
-
|
75
|
-
assert_too_much_tag("favicon", "channel") do
|
76
|
-
Parser.parse(make_RDF(<<-EOR, @ns))
|
77
|
-
#{make_channel(@channel_nodes * 2)}
|
78
|
-
#{make_item}
|
79
|
-
EOR
|
80
|
-
end
|
81
|
-
|
82
|
-
attrs = {"rdf:about" => "http://www.example.org/item.png"}
|
83
|
-
contents = [["#{@prefix}:width", "80"]] * 5
|
84
|
-
image_item = make_element("#{@prefix}:item", attrs, contents)
|
85
|
-
assert_too_much_tag("width", "item") do
|
86
|
-
Parser.parse(make_RDF(<<-EOR, @ns))
|
87
|
-
#{make_channel}
|
88
|
-
#{make_item(image_item)}
|
89
|
-
EOR
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_favicon_accessor
|
94
|
-
favicon = @rss.channel.image_favicon
|
95
|
-
[
|
96
|
-
%w(about rdf:about http://example.com/favicon.ico),
|
97
|
-
%w(size image:size large),
|
98
|
-
%w(image_size image:size medium),
|
99
|
-
].each do |name, full_name, new_value|
|
100
|
-
assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
|
101
|
-
favicon.__send__("#{name}=", new_value)
|
102
|
-
assert_equal(new_value, favicon.__send__(name))
|
103
|
-
favicon.__send__("#{name}=", @favicon_attrs[full_name])
|
104
|
-
assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
|
105
|
-
end
|
106
|
-
|
107
|
-
%w(small medium large).each do |value|
|
108
|
-
assert_nothing_raised do
|
109
|
-
favicon.size = value
|
110
|
-
favicon.image_size = value
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
%w(aaa AAA SMALL MEDIUM LARGE).each do |value|
|
115
|
-
args = ["#{@prefix}:favicon", value, "#{@prefix}:size"]
|
116
|
-
assert_not_available_value(*args) do
|
117
|
-
favicon.size = value
|
118
|
-
end
|
119
|
-
assert_not_available_value(*args) do
|
120
|
-
favicon.image_size = value
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
[
|
125
|
-
%w(dc_title dc:title sample-favicon),
|
126
|
-
].each do |name, full_name, new_value|
|
127
|
-
assert_equal(@favicon_contents[full_name], favicon.__send__(name))
|
128
|
-
favicon.__send__("#{name}=", new_value)
|
129
|
-
assert_equal(new_value, favicon.__send__(name))
|
130
|
-
favicon.__send__("#{name}=", @favicon_contents[full_name])
|
131
|
-
assert_equal(@favicon_contents[full_name], favicon.__send__(name))
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_item_accessor
|
136
|
-
@rss.items.each_with_index do |item, i|
|
137
|
-
image_item = item.image_item
|
138
|
-
attrs, contents = @items[i]
|
139
|
-
[
|
140
|
-
%w(about rdf:about http://example.com/image.png),
|
141
|
-
%w(resource rdf:resource http://example.com/),
|
142
|
-
].each do |name, full_name, new_value|
|
143
|
-
assert_equal(attrs[full_name], image_item.__send__(name))
|
144
|
-
image_item.__send__("#{name}=", new_value)
|
145
|
-
assert_equal(new_value, image_item.__send__(name))
|
146
|
-
image_item.__send__("#{name}=", attrs[full_name])
|
147
|
-
assert_equal(attrs[full_name], image_item.__send__(name))
|
148
|
-
end
|
149
|
-
|
150
|
-
[
|
151
|
-
["width", "image:width", "111"],
|
152
|
-
["image_width", "image:width", "44"],
|
153
|
-
["height", "image:height", "222"],
|
154
|
-
["image_height", "image:height", "88"],
|
155
|
-
].each do |name, full_name, new_value|
|
156
|
-
assert_equal(contents[full_name].to_i, image_item.__send__(name))
|
157
|
-
image_item.__send__("#{name}=", new_value)
|
158
|
-
assert_equal(new_value.to_i, image_item.__send__(name))
|
159
|
-
image_item.__send__("#{name}=", contents[full_name])
|
160
|
-
assert_equal(contents[full_name].to_i, image_item.__send__(name))
|
161
|
-
end
|
162
|
-
|
163
|
-
[
|
164
|
-
["dc_title", "dc:title", "sample-image"],
|
165
|
-
].each do |name, full_name, new_value|
|
166
|
-
assert_equal(contents[full_name], image_item.__send__(name))
|
167
|
-
image_item.__send__("#{name}=", new_value)
|
168
|
-
assert_equal(new_value, image_item.__send__(name))
|
169
|
-
image_item.__send__("#{name}=", contents[full_name])
|
170
|
-
assert_equal(contents[full_name], image_item.__send__(name))
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_favicon_to_s
|
176
|
-
favicon = @rss.channel.image_favicon
|
177
|
-
expected_xml = image_xmlns_container(make_element("#{@prefix}:favicon",
|
178
|
-
@favicon_attrs,
|
179
|
-
@favicon_contents))
|
180
|
-
expected = REXML::Document.new(expected_xml)
|
181
|
-
actual_xml = image_xmlns_container(favicon.to_s(false, ""))
|
182
|
-
actual = REXML::Document.new(actual_xml)
|
183
|
-
assert_equal(expected.to_s, actual.to_s)
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_item_to_s
|
187
|
-
@rss.items.each_with_index do |item, i|
|
188
|
-
attrs, contents = @items[i]
|
189
|
-
expected_xml = make_element("#{@prefix}:item", attrs, contents)
|
190
|
-
expected_xml = image_xmlns_container(expected_xml)
|
191
|
-
expected = REXML::Document.new(expected_xml)
|
192
|
-
actual_xml = image_xmlns_container(item.image_item.to_s(false, ""))
|
193
|
-
actual = REXML::Document.new(actual_xml)
|
194
|
-
|
195
|
-
assert_equal(expected[0].attributes, actual[0].attributes)
|
196
|
-
|
197
|
-
%w(image:height image:width dc:title).each do |name|
|
198
|
-
actual_target = actual.elements["//#{name}"]
|
199
|
-
expected_target = expected.elements["//#{name}"]
|
200
|
-
assert_equal(expected_target.to_s, actual_target.to_s)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
private
|
206
|
-
def image_xmlns_container(content)
|
207
|
-
xmlns_container({
|
208
|
-
@prefix => @uri,
|
209
|
-
"dc" => "http://purl.org/dc/elements/1.1/",
|
210
|
-
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
211
|
-
},
|
212
|
-
content)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
data/test/test_inherit.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative "rss-testcase"
|
3
|
-
|
4
|
-
require "rss/1.0"
|
5
|
-
|
6
|
-
module RSS
|
7
|
-
class TestInherit < TestCase
|
8
|
-
|
9
|
-
class InheritedImage < RSS::RDF::Image
|
10
|
-
def self.indent_size; 1; end
|
11
|
-
def self.tag_name; 'image'; end
|
12
|
-
end
|
13
|
-
|
14
|
-
def setup
|
15
|
-
@rss = make_RDF(<<-EOR)
|
16
|
-
#{make_channel}
|
17
|
-
#{make_image}
|
18
|
-
#{make_item}
|
19
|
-
#{make_textinput}
|
20
|
-
EOR
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_inherit
|
24
|
-
rss = RSS::Parser.parse(@rss)
|
25
|
-
orig_image = rss.image
|
26
|
-
prefix = "[INHERIT]"
|
27
|
-
image = InheritedImage.new("#{prefix} #{orig_image.about}")
|
28
|
-
image.title = "#{prefix} #{orig_image.title}"
|
29
|
-
image.url = "#{prefix} #{orig_image.url}"
|
30
|
-
image.link = "#{prefix} #{orig_image.link}"
|
31
|
-
rss.image = image
|
32
|
-
|
33
|
-
new_rss = RSS::Parser.parse(rss.to_s)
|
34
|
-
new_image = new_rss.image
|
35
|
-
assert_equal("#{prefix} #{orig_image.about}", new_image.about)
|
36
|
-
assert_equal("#{prefix} #{orig_image.title}", new_image.title)
|
37
|
-
assert_equal("#{prefix} #{orig_image.url}", new_image.url)
|
38
|
-
assert_equal("#{prefix} #{orig_image.link}", new_image.link)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|