The Webfeed Flutter package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

214 lignes
8.7 KiB

  1. import 'dart:core';
  2. import 'dart:io';
  3. import 'package:test/test.dart';
  4. import 'package:webfeed/webfeed.dart';
  5. void main() {
  6. test("parse Invalid.xml", () {
  7. var xmlString = new File("test/xml/Invalid.xml").readAsStringSync();
  8. try {
  9. new RssFeed.parse(xmlString);
  10. fail("Should throw Argument Error");
  11. } on ArgumentError {}
  12. });
  13. test("parse RSS.xml", () {
  14. var xmlString = new File("test/xml/RSS.xml").readAsStringSync();
  15. var feed = new RssFeed.parse(xmlString);
  16. expect(feed.title, "News - Foo bar News");
  17. expect(feed.description, "Foo bar News and Updates feed provided by Foo bar, Inc.");
  18. expect(feed.link, "https://foo.bar.news/");
  19. expect(feed.language, "en-US");
  20. expect(feed.lastBuildDate, "Mon, 26 Mar 2018 14:00:00 PDT");
  21. expect(feed.generator, "Custom");
  22. expect(feed.copyright, "Copyright 2018, Foo bar Inc.");
  23. expect(feed.docs, "https://foo.bar.news/docs");
  24. expect(feed.managingEditor, "alice@foo.bar.news");
  25. expect(feed.rating, "The PICS rating of the feed");
  26. expect(feed.webMaster, "webmaster@foo.bar.news");
  27. expect(feed.ttl, 60);
  28. expect(feed.image.title, "Foo bar News");
  29. expect(feed.image.url, "https://foo.bar.news/logo.gif");
  30. expect(feed.image.link, "https://foo.bar.news/");
  31. expect(feed.cloud.domain, "radio.foo.bar.news");
  32. expect(feed.cloud.port, "80");
  33. expect(feed.cloud.path, "/RPC2");
  34. expect(feed.cloud.registerProcedure, "foo.bar.rssPleaseNotify");
  35. expect(feed.cloud.protocol, "xml-rpc");
  36. expect(feed.categories.length, 2);
  37. expect(feed.categories[0].domain, null);
  38. expect(feed.categories[0].value, "Ipsum");
  39. expect(feed.categories[1].domain, "news");
  40. expect(feed.categories[1].value, "Lorem Ipsum");
  41. expect(feed.skipDays.length, 3);
  42. expect(feed.skipDays.contains("Monday"), true);
  43. expect(feed.skipDays.contains("Tuesday"), true);
  44. expect(feed.skipDays.contains("Sunday"), true);
  45. expect(feed.skipHours.length, 5);
  46. expect(feed.skipHours.contains(0), true);
  47. expect(feed.skipHours.contains(1), true);
  48. expect(feed.skipHours.contains(2), true);
  49. expect(feed.skipHours.contains(3), true);
  50. expect(feed.skipHours.contains(4), true);
  51. expect(feed.items.length, 2);
  52. expect(feed.items.first.title, "The standard Lorem Ipsum passage, used since the 1500s");
  53. expect(feed.items.first.description, "Lorem ipsum dolor sit amet, consectetur adipiscing elit");
  54. expect(feed.items.first.link, "https://foo.bar.news/1");
  55. expect(feed.items.first.guid, "https://foo.bar.news/1?guid");
  56. expect(feed.items.first.pubDate, "Mon, 26 Mar 2018 14:00:00 PDT");
  57. expect(feed.items.first.categories.first.domain, "news");
  58. expect(feed.items.first.categories.first.value, "Lorem");
  59. expect(feed.items.first.author, "alice@foo.bar.news");
  60. expect(feed.items.first.source.url, "https://foo.bar.news/1?source");
  61. expect(feed.items.first.source.value, "Foo Bar");
  62. expect(feed.items.first.comments, "https://foo.bar.news/1/comments");
  63. expect(feed.items.first.content.value, "<img width=\"1000\" height=\"690\" src=\"https://test.com/image_link\"/> Test content<br />");
  64. expect(feed.items.first.content.images.first, "https://test.com/image_link");
  65. });
  66. test("parse RSS-Media.xml", (){
  67. var xmlString = new File("test/xml/RSS-Media.xml").readAsStringSync();
  68. var feed = new RssFeed.parse(xmlString);
  69. expect(feed.title, "Song Site");
  70. expect(feed.description, "Media RSS example with new fields added in v1.5.0");
  71. expect(feed.items.length, 1);
  72. var item = feed.items.first;
  73. expect(item.title, null);
  74. expect(item.link, "http://www.foo.com");
  75. expect(item.pubDate, "Mon, 27 Aug 2001 16:08:56 PST");
  76. expect(item.media.group.contents.length, 5);
  77. expect(item.media.group.credits.length, 2);
  78. expect(item.media.group.category.value, "music/artist name/album/song");
  79. expect(item.media.group.rating.value, "nonadult");
  80. expect(item.media.contents.length, 2);
  81. var mediaContent = item.media.contents.first;
  82. expect(mediaContent.url, "http://www.foo.com/video.mov");
  83. expect(mediaContent.type, "video/quicktime");
  84. expect(mediaContent.fileSize, 2000);
  85. expect(mediaContent.medium, "video");
  86. expect(mediaContent.isDefault, true);
  87. expect(mediaContent.expression, "full");
  88. expect(mediaContent.bitrate, 128);
  89. expect(mediaContent.framerate, 25);
  90. expect(mediaContent.samplingrate, 44.1);
  91. expect(mediaContent.channels, 2);
  92. expect(item.media.credits.length, 2);
  93. var mediaCredit = item.media.credits.first;
  94. expect(mediaCredit.role, "owner1");
  95. expect(mediaCredit.scheme, "urn:yvs");
  96. expect(mediaCredit.value, "copyright holder of the entity");
  97. expect(item.media.category.scheme, "http://search.yahoo.com/mrss/category_ schema");
  98. expect(item.media.category.label, "Music");
  99. expect(item.media.category.value, "music/artist/album/song");
  100. expect(item.media.rating.scheme, "urn:simple");
  101. expect(item.media.rating.value, "adult");
  102. expect(item.media.title.type, "plain");
  103. expect(item.media.title.value, "The Judy's -- The Moo Song");
  104. expect(item.media.description.type, "plain");
  105. expect(item.media.description.value, "This was some really bizarre band I listened to as a young lad.");
  106. expect(item.media.keywords, "kitty, cat, big dog, yarn, fluffy");
  107. expect(item.media.thumbnails.length, 2);
  108. var mediaThumbnail = item.media.thumbnails.first;
  109. expect(mediaThumbnail.url, "http://www.foo.com/keyframe1.jpg");
  110. expect(mediaThumbnail.width, "75");
  111. expect(mediaThumbnail.height, "50");
  112. expect(mediaThumbnail.time, "12:05:01.123");
  113. expect(item.media.hash.algo, "md5");
  114. expect(item.media.hash.value, "dfdec888b72151965a34b4b59031290a");
  115. expect(item.media.player.url, "http://www.foo.com/player?id=1111");
  116. expect(item.media.player.width, 400);
  117. expect(item.media.player.height, 200);
  118. expect(item.media.player.value, "");
  119. expect(item.media.copyright.url, "http://blah.com/additional-info.html");
  120. expect(item.media.copyright.value, "2005 FooBar Media");
  121. expect(item.media.text.type, "plain");
  122. expect(item.media.text.lang, "en");
  123. expect(item.media.text.start, "00:00:03.000");
  124. expect(item.media.text.end, "00:00:10.000");
  125. expect(item.media.text.value, " Oh, say, can you see");
  126. expect(item.media.restriction.relationship, "allow");
  127. expect(item.media.restriction.type, "country");
  128. expect(item.media.restriction.value, "au us");
  129. expect(item.media.community.starRating.average, 3.5);
  130. expect(item.media.community.starRating.count, 20);
  131. expect(item.media.community.starRating.min, 1);
  132. expect(item.media.community.starRating.max, 10);
  133. expect(item.media.community.statistics.views, 5);
  134. expect(item.media.community.statistics.favorites, 4);
  135. expect(item.media.community.tags.tags, "news: 5, abc:3");
  136. expect(item.media.community.tags.weight, 1);
  137. expect(item.media.comments.length, 2);
  138. expect(item.media.comments.first, "comment1");
  139. expect(item.media.comments.last, "comment2");
  140. expect(item.media.embed.url, "http://www.foo.com/player.swf");
  141. expect(item.media.embed.width, 512);
  142. expect(item.media.embed.height, 323);
  143. expect(item.media.embed.params.length, 5);
  144. expect(item.media.embed.params.first.name, "type");
  145. expect(item.media.embed.params.first.value, "application/x-shockwave-flash");
  146. expect(item.media.responses.length, 2);
  147. expect(item.media.responses.first, "http://www.response1.com");
  148. expect(item.media.responses.last, "http://www.response2.com");
  149. expect(item.media.backLinks.length, 2);
  150. expect(item.media.backLinks.first, "http://www.backlink1.com");
  151. expect(item.media.backLinks.last, "http://www.backlink2.com");
  152. expect(item.media.status.state, "active");
  153. expect(item.media.status.reason, null);
  154. expect(item.media.prices.length, 2);
  155. expect(item.media.prices.first.price, 19.99);
  156. expect(item.media.prices.first.type, "rent");
  157. expect(item.media.prices.first.info, "http://www.dummy.jp/package_info.html");
  158. expect(item.media.prices.first.currency, "EUR");
  159. expect(item.media.license.type, "text/html");
  160. expect(item.media.license.href, "http://www.licensehost.com/license");
  161. expect(item.media.license.value, " Sample license for a video");
  162. expect(item.media.peerLink.type, "application/x-bittorrent");
  163. expect(item.media.peerLink.href, "http://www.foo.org/sampleFile.torrent");
  164. expect(item.media.peerLink.value, "");
  165. expect(item.media.rights.status, "official");
  166. expect(item.media.scenes.length, 2);
  167. expect(item.media.scenes.first.title, "sceneTitle1");
  168. expect(item.media.scenes.first.description, "sceneDesc1");
  169. expect(item.media.scenes.first.startTime, "00:15");
  170. expect(item.media.scenes.first.endTime, "00:45");
  171. });
  172. }