156
def assert_channel10(attrs, channel)
158
n_attrs = normalized_attrs(attrs)
160
names = %w(about title link description)
161
assert_attributes(attrs, names, channel)
163
%w(image items textinput).each do |name|
164
value = n_attrs[name]
166
target = channel.__send__(name)
167
__send__("assert_channel10_#{name}", value, target)
173
def assert_channel10_image(attrs, image)
175
assert_attributes(attrs, %w(resource), image)
179
def assert_channel10_textinput(attrs, textinput)
181
assert_attributes(attrs, %w(resource), textinput)
185
def assert_channel10_items(attrs, items)
187
assert_equal(items.resources, items.Seq.lis.collect {|x| x.resource})
188
items.Seq.lis.each_with_index do |li, i|
189
assert_attributes(attrs[i], %w(resource), li)
194
def assert_image10(attrs, image)
196
names = %w(about title url link)
197
assert_attributes(attrs, names, image)
201
def assert_items10(attrs, items)
203
names = %w(about title link description)
204
items.each_with_index do |item, i|
205
assert_attributes(attrs[i], names, item)
210
def assert_textinput10(attrs, textinput)
212
names = %w(about title description name link)
213
assert_attributes(attrs, names, textinput)
218
def assert_channel09(attrs, channel)
220
n_attrs = normalized_attrs(attrs)
222
names = %w(title description link language rating
223
copyright pubDate lastBuildDate docs
224
managingEditor webMaster)
225
assert_attributes(attrs, names, channel)
227
%w(skipHours skipDays).each do |name|
228
value = n_attrs[name]
230
target = channel.__send__(name)
231
__send__("assert_channel09_#{name}", value, target)
237
def assert_channel09_skipDays(contents, skipDays)
240
contents.each_with_index do |content, i|
241
assert_equal(content, days[i].content)
246
def assert_channel09_skipHours(contents, skipHours)
248
hours = skipHours.hours
249
contents.each_with_index do |content, i|
250
assert_equal(content.to_i, hours[i].content)
255
def assert_image09(attrs, image)
257
names = %w(url link title description)
258
names << ["width", :integer]
259
names << ["height", :integer]
260
assert_attributes(attrs, names, image)
264
def assert_items09(attrs, items)
266
names = %w(title link description)
267
items.each_with_index do |item, i|
268
assert_attributes(attrs[i], names, item)
273
def assert_textinput09(attrs, textinput)
275
names = %w(title description name link)
276
assert_attributes(attrs, names, textinput)
281
def assert_channel20(attrs, channel)
283
n_attrs = normalized_attrs(attrs)
285
names = %w(title link description language copyright
286
managingEditor webMaster pubDate
287
lastBuildDate generator docs rating)
288
names << ["ttl", :integer]
289
assert_attributes(attrs, names, channel)
291
%w(cloud categories skipHours skipDays).each do |name|
292
value = n_attrs[name]
294
target = channel.__send__(name)
295
__send__("assert_channel20_#{name}", value, target)
301
def assert_channel20_skipDays(contents, skipDays)
302
assert_channel09_skipDays(contents, skipDays)
305
def assert_channel20_skipHours(contents, skipHours)
306
assert_channel09_skipHours(contents, skipHours)
309
def assert_channel20_cloud(attrs, cloud)
311
names = %w(domain path registerProcedure protocol)
312
names << ["port", :integer]
313
assert_attributes(attrs, names, cloud)
317
def assert_channel20_categories(attrs, categories)
319
names = %w(domain content)
320
categories.each_with_index do |category, i|
321
assert_attributes(attrs[i], names, category)
326
def assert_image20(attrs, image)
328
names = %w(url link title description)
329
names << ["width", :integer]
330
names << ["height", :integer]
331
assert_attributes(attrs, names, image)
335
def assert_items20(attrs, items)
337
names = %w(about title link description)
338
items.each_with_index do |item, i|
339
assert_attributes(attrs[i], names, item)
341
n_attrs = normalized_attrs(attrs[i])
343
%w(source enclosure categories guid).each do |name|
344
value = n_attrs[name]
346
target = item.__send__(name)
347
__send__("assert_items20_#{name}", value, target)
354
def assert_items20_source(attrs, source)
356
assert_attributes(attrs, %w(url content), source)
360
def assert_items20_enclosure(attrs, enclosure)
362
names = ["url", ["length", :integer], "type"]
363
assert_attributes(attrs, names, enclosure)
367
def assert_items20_categories(attrs, categories)
369
assert_channel20_categories(attrs, categories)
373
def assert_items20_guid(attrs, guid)
375
names = [["isPermaLink", :boolean], ["content"]]
376
assert_attributes(attrs, names, guid)
380
def assert_textinput20(attrs, textinput)
382
names = %w(title description name link)
383
assert_attributes(attrs, names, textinput)
387
159
def assert_atom_person(tag_name, generator)
388
160
_wrap_assertion do
1150
def assert_atom_person_to_s(target_class)
1153
uri = "http://example.com/person/"
1154
email = "person@example.com"
1156
target = target_class.new
1157
assert_equal("", target.to_s)
1159
target = target_class.new
1160
person_name = target_class::Name.new
1161
person_name.content = name
1162
target.name = person_name
1163
xml_target = REXML::Document.new(target.to_s).root
1164
assert_equal(["name"], xml_target.elements.collect {|e| e.name})
1165
assert_equal([name], xml_target.elements.collect {|e| e.text})
1167
person_uri = target_class::Uri.new
1168
person_uri.content = uri
1169
target.uri = person_uri
1170
xml_target = REXML::Document.new(target.to_s).root
1171
assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
1172
assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
1174
person_email = target_class::Email.new
1175
person_email.content = email
1176
target.email = person_email
1177
xml_target = REXML::Document.new(target.to_s).root
1178
assert_equal(["name", "uri", "email"],
1179
xml_target.elements.collect {|e| e.name})
1180
assert_equal([name, uri, email],
1181
xml_target.elements.collect {|e| e.text})
1185
def assert_atom_category_to_s(target_class)
1188
scheme = "http://example.com/music"
1191
category = target_class.new
1192
assert_equal("", category.to_s)
1194
category = target_class.new
1195
category.scheme = scheme
1196
assert_equal("", category.to_s)
1198
category = target_class.new
1199
category.label = label
1200
assert_equal("", category.to_s)
1202
category = target_class.new
1203
category.scheme = scheme
1204
category.label = label
1205
assert_equal("", category.to_s)
1207
category = target_class.new
1208
category.term = term
1209
xml = REXML::Document.new(category.to_s).root
1210
assert_rexml_element([], {"term" => term}, nil, xml)
1212
category = target_class.new
1213
category.term = term
1214
category.scheme = scheme
1215
xml = REXML::Document.new(category.to_s).root
1216
assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
1218
category = target_class.new
1219
category.term = term
1220
category.label = label
1221
xml = REXML::Document.new(category.to_s).root
1222
assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
1224
category = target_class.new
1225
category.term = term
1226
category.scheme = scheme
1227
category.label = label
1228
xml = REXML::Document.new(category.to_s).root
1229
attrs = {"term" => term, "scheme" => scheme, "label" => label}
1230
assert_rexml_element([], attrs, nil, xml)
1234
def assert_atom_generator_to_s(target_class)
1236
content = "Feed generator"
1237
uri = "http://example.com/generator"
1240
generator = target_class.new
1241
assert_equal("", generator.to_s)
1243
generator = target_class.new
1245
assert_equal("", generator.to_s)
1247
generator = target_class.new
1248
generator.version = version
1249
assert_equal("", generator.to_s)
1251
generator = target_class.new
1253
generator.version = version
1254
assert_equal("", generator.to_s)
1256
generator = target_class.new
1257
generator.content = content
1258
xml = REXML::Document.new(generator.to_s).root
1259
assert_rexml_element([], {}, content, xml)
1261
generator = target_class.new
1262
generator.content = content
1264
xml = REXML::Document.new(generator.to_s).root
1265
assert_rexml_element([], {"uri" => uri}, content, xml)
1267
generator = target_class.new
1268
generator.content = content
1269
generator.version = version
1270
xml = REXML::Document.new(generator.to_s).root
1271
assert_rexml_element([], {"version" => version}, content, xml)
1273
generator = target_class.new
1274
generator.content = content
1276
generator.version = version
1277
xml = REXML::Document.new(generator.to_s).root
1278
assert_rexml_element([], {"uri" => uri, "version" => version},
1283
def assert_atom_icon_to_s(target_class)
1285
content = "http://example.com/icon.png"
1287
icon = target_class.new
1288
assert_equal("", icon.to_s)
1290
icon = target_class.new
1291
icon.content = content
1292
xml = REXML::Document.new(icon.to_s).root
1293
assert_rexml_element([], {}, content, xml)
1297
def assert_atom_id_to_s(target_class)
1299
content = "http://example.com/1"
1301
id = target_class.new
1302
assert_equal("", id.to_s)
1304
id = target_class.new
1305
id.content = content
1306
xml = REXML::Document.new(id.to_s).root
1307
assert_rexml_element([], {}, content, xml)
1311
def assert_atom_link_to_s(target_class)
1313
href = "http://example.com/atom.xml"
1315
type = "application/atom+xml"
1320
link = target_class.new
1321
assert_equal("", link.to_s)
1323
link = target_class.new
1325
xml = REXML::Document.new(link.to_s).root
1326
assert_rexml_element([], {"href" => href}, nil, xml)
1328
optional_arguments = %w(rel type hreflang title length)
1329
optional_arguments.each do |name|
1330
rest = optional_arguments.reject {|x| x == name}
1332
link = target_class.new
1333
link.__send__("#{name}=", eval(name))
1334
assert_equal("", link.to_s)
1337
link.__send__("#{n}=", eval(n))
1338
assert_equal("", link.to_s)
1341
link = target_class.new
1343
link.__send__("#{name}=", eval(name))
1344
attrs = [["href", href], [name, eval(name)]]
1345
xml = REXML::Document.new(link.to_s).root
1346
assert_rexml_element([], attrs, nil, xml)
1349
link.__send__("#{n}=", eval(n))
1350
attrs << [n, eval(n)]
1351
xml = REXML::Document.new(link.to_s).root
1352
assert_rexml_element([], attrs, nil, xml)
1358
def assert_atom_logo_to_s(target_class)
1360
content = "http://example.com/logo.png"
1362
logo = target_class.new
1363
assert_equal("", logo.to_s)
1365
logo = target_class.new
1366
logo.content = content
1367
xml = REXML::Document.new(logo.to_s).root
1368
assert_rexml_element([], {}, content, xml)
1372
def assert_atom_text_construct_to_s(target_class)
1374
text_content = "plain text"
1375
html_content = "<em>#{text_content}</em>"
1376
xhtml_uri = "http://www.w3.org/1999/xhtml"
1377
xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
1378
xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
1379
{"xmlns" => xhtml_uri},
1382
text = target_class.new
1383
assert_equal("", text.to_s)
1385
text = target_class.new
1387
assert_equal("", text.to_s)
1389
text = target_class.new
1390
text.content = text_content
1391
xml = REXML::Document.new(text.to_s).root
1392
assert_rexml_element([], {}, text_content, xml)
1394
text = target_class.new
1396
text.content = text_content
1397
xml = REXML::Document.new(text.to_s).root
1398
assert_rexml_element([], {"type" => "text"}, text_content, xml)
1400
text = target_class.new
1402
text.content = html_content
1403
xml = REXML::Document.new(text.to_s).root
1404
assert_rexml_element([], {"type" => "html"}, html_content, xml)
1406
text = target_class.new
1408
text.content = xhtml_content
1409
assert_equal("", text.to_s)
1411
text = target_class.new
1413
text.__send__(target_class.xml_setter, xhtml_content)
1414
xml = REXML::Document.new(text.to_s).root
1415
assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
1417
assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
1418
assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
1420
text = target_class.new
1422
text.__send__(target_class.xml_setter, xhtml_em)
1423
xml = REXML::Document.new(text.to_s).root
1424
assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
1426
assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
1427
assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
1431
def assert_atom_date_construct_to_s(target_class)
1433
date = target_class.new
1434
assert_equal("", date.to_s)
1437
"2003-12-13T18:30:02Z",
1438
"2003-12-13T18:30:02.25Z",
1439
"2003-12-13T18:30:02+01:00",
1440
"2003-12-13T18:30:02.25+01:00",
1442
date = target_class.new
1443
date.content = content
1444
xml = REXML::Document.new(date.to_s).root
1445
assert_rexml_element([], {}, content, xml, :time)
1447
date = target_class.new
1448
date.content = Time.parse(content)
1449
xml = REXML::Document.new(date.to_s).root
1450
assert_rexml_element([], {}, content, xml, :time)
1455
def assert_atom_content_to_s(target_class)
1457
assert_atom_text_construct_to_s(target_class)
1458
assert_atom_content_inline_other_xml_to_s(target_class)
1459
assert_atom_content_inline_other_text_to_s(target_class)
1460
assert_atom_content_inline_other_base64_to_s(target_class)
1461
assert_atom_content_out_of_line_to_s(target_class)
1465
def assert_atom_content_inline_other_xml_to_s(target_class)
1467
content = target_class.new
1468
content.type = "text/xml"
1469
assert_equal("", content.to_s)
1471
content = target_class.new
1472
content.type = "text/xml"
1473
content.xml = RSS::XML::Element.new("em")
1474
xml = REXML::Document.new(content.to_s).root
1475
assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
1479
def assert_atom_content_inline_other_text_to_s(target_class)
1481
content = target_class.new
1482
content.type = "text/plain"
1483
assert_equal("", content.to_s)
1485
content = target_class.new
1486
content.type = "text/plain"
1487
content.xml = RSS::XML::Element.new("em")
1488
assert_equal("", content.to_s)
1490
content = target_class.new
1491
content.type = "text/plain"
1492
content.content = "content"
1493
xml = REXML::Document.new(content.to_s).root
1494
assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
1498
def assert_atom_content_inline_other_base64_to_s(target_class)
1509
type = "application/zip"
1510
original_content = Zlib::Deflate.deflate(text)
1512
content = target_class.new
1514
content.content = original_content
1515
xml = REXML::Document.new(content.to_s).root
1516
assert_rexml_element([], {"type" => type},
1517
Base64.encode64(original_content), xml)
1521
def assert_atom_content_out_of_line_to_s(target_class)
1523
type = "application/zip"
1524
src = "http://example.com/xxx.zip"
1526
content = target_class.new
1527
assert(!content.out_of_line?)
1529
assert(content.out_of_line?)
1530
xml = REXML::Document.new(content.to_s).root
1531
assert_rexml_element([], {"src" => src}, nil, xml)
1533
content = target_class.new
1534
assert(!content.out_of_line?)
1536
assert(!content.out_of_line?)
1538
assert(content.out_of_line?)
1539
xml = REXML::Document.new(content.to_s).root
1540
assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
1544
921
def _assert_maker_atom_persons(feed_type, maker_readers, feed_readers)
1545
922
_wrap_assertion do