The Webfeed Flutter package for Appeto SDK.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 rivejä
14 KiB

  1. import 'dart:core';
  2. import 'dart:io';
  3. import 'package:test/test.dart';
  4. import 'package:webfeed/webfeed.dart';
  5. import 'package:webfeed/domain/rss_itunes_type.dart';
  6. import 'package:webfeed/domain/rss_itunes_episode_type.dart';
  7. void main() {
  8. test("parse Invalid.xml", () {
  9. var xmlString = new File("test/xml/Invalid.xml").readAsStringSync();
  10. try {
  11. new RssFeed.parse(xmlString);
  12. fail("Should throw Argument Error");
  13. } on ArgumentError {}
  14. });
  15. test("parse RSS.xml", () {
  16. var xmlString = new File("test/xml/RSS.xml").readAsStringSync();
  17. var feed = new RssFeed.parse(xmlString);
  18. expect(feed.title, "News - Foo bar News");
  19. expect(feed.description,
  20. "Foo bar News and Updates feed provided by Foo bar, Inc.");
  21. expect(feed.link, "https://foo.bar.news/");
  22. expect(feed.author, "hello@world.net");
  23. expect(feed.language, "en-US");
  24. expect(feed.lastBuildDate, "Mon, 26 Mar 2018 14:00:00 PDT");
  25. expect(feed.generator, "Custom");
  26. expect(feed.copyright, "Copyright 2018, Foo bar Inc.");
  27. expect(feed.docs, "https://foo.bar.news/docs");
  28. expect(feed.managingEditor, "alice@foo.bar.news");
  29. expect(feed.rating, "The PICS rating of the feed");
  30. expect(feed.webMaster, "webmaster@foo.bar.news");
  31. expect(feed.ttl, 60);
  32. expect(feed.image.title, "Foo bar News");
  33. expect(feed.image.url, "https://foo.bar.news/logo.gif");
  34. expect(feed.image.link, "https://foo.bar.news/");
  35. expect(feed.cloud.domain, "radio.foo.bar.news");
  36. expect(feed.cloud.port, "80");
  37. expect(feed.cloud.path, "/RPC2");
  38. expect(feed.cloud.registerProcedure, "foo.bar.rssPleaseNotify");
  39. expect(feed.cloud.protocol, "xml-rpc");
  40. expect(feed.categories.length, 2);
  41. expect(feed.categories[0].domain, null);
  42. expect(feed.categories[0].value, "Ipsum");
  43. expect(feed.categories[1].domain, "news");
  44. expect(feed.categories[1].value, "Lorem Ipsum");
  45. expect(feed.skipDays.length, 3);
  46. expect(feed.skipDays.contains("Monday"), true);
  47. expect(feed.skipDays.contains("Tuesday"), true);
  48. expect(feed.skipDays.contains("Sunday"), true);
  49. expect(feed.skipHours.length, 5);
  50. expect(feed.skipHours.contains(0), true);
  51. expect(feed.skipHours.contains(1), true);
  52. expect(feed.skipHours.contains(2), true);
  53. expect(feed.skipHours.contains(3), true);
  54. expect(feed.skipHours.contains(4), true);
  55. expect(feed.items.length, 2);
  56. expect(feed.items.first.title,
  57. "The standard Lorem Ipsum passage, used since the 1500s");
  58. expect(feed.items.first.description,
  59. "Lorem ipsum dolor sit amet, consectetur adipiscing elit");
  60. expect(feed.items.first.link, "https://foo.bar.news/1");
  61. expect(feed.items.first.guid, "https://foo.bar.news/1?guid");
  62. expect(feed.items.first.pubDate, DateTime(2018, 03, 26, 14)); //Mon, 26 Mar 2018 14:00:00 PDT
  63. expect(feed.items.first.categories.first.domain, "news");
  64. expect(feed.items.first.categories.first.value, "Lorem");
  65. expect(feed.items.first.author, "alice@foo.bar.news");
  66. expect(feed.items.first.source.url, "https://foo.bar.news/1?source");
  67. expect(feed.items.first.source.value, "Foo Bar");
  68. expect(feed.items.first.comments, "https://foo.bar.news/1/comments");
  69. expect(feed.items.first.enclosure.url,
  70. "http://www.scripting.com/mp3s/weatherReportSuite.mp3");
  71. expect(feed.items.first.enclosure.length, 12216320);
  72. expect(feed.items.first.enclosure.type, "audio/mpeg");
  73. expect(feed.items.first.content.value,
  74. "<img width=\"1000\" height=\"690\" src=\"https://test.com/image_link\"/> Test content<br />");
  75. expect(
  76. feed.items.first.content.images.first, "https://test.com/image_link");
  77. });
  78. test("parse RSS-Media.xml", () {
  79. var xmlString = new File("test/xml/RSS-Media.xml").readAsStringSync();
  80. var feed = new RssFeed.parse(xmlString);
  81. expect(feed.title, "Song Site");
  82. expect(
  83. feed.description, "Media RSS example with new fields added in v1.5.0");
  84. expect(feed.items.length, 1);
  85. var item = feed.items.first;
  86. expect(item.title, null);
  87. expect(item.link, "http://www.foo.com");
  88. expect(item.pubDate, DateTime(2001, 08, 27, 16, 08, 56)); //Mon, 27 Aug 2001 16:08:56 PST
  89. expect(item.media.group.contents.length, 5);
  90. expect(item.media.group.credits.length, 2);
  91. expect(item.media.group.category.value, "music/artist name/album/song");
  92. expect(item.media.group.rating.value, "nonadult");
  93. expect(item.media.contents.length, 2);
  94. var mediaContent = item.media.contents.first;
  95. expect(mediaContent.url, "http://www.foo.com/video.mov");
  96. expect(mediaContent.type, "video/quicktime");
  97. expect(mediaContent.fileSize, 2000);
  98. expect(mediaContent.medium, "video");
  99. expect(mediaContent.isDefault, true);
  100. expect(mediaContent.expression, "full");
  101. expect(mediaContent.bitrate, 128);
  102. expect(mediaContent.framerate, 25);
  103. expect(mediaContent.samplingrate, 44.1);
  104. expect(mediaContent.channels, 2);
  105. expect(item.media.credits.length, 2);
  106. var mediaCredit = item.media.credits.first;
  107. expect(mediaCredit.role, "owner1");
  108. expect(mediaCredit.scheme, "urn:yvs");
  109. expect(mediaCredit.value, "copyright holder of the entity");
  110. expect(item.media.category.scheme,
  111. "http://search.yahoo.com/mrss/category_ schema");
  112. expect(item.media.category.label, "Music");
  113. expect(item.media.category.value, "music/artist/album/song");
  114. expect(item.media.rating.scheme, "urn:simple");
  115. expect(item.media.rating.value, "adult");
  116. expect(item.media.title.type, "plain");
  117. expect(item.media.title.value, "The Judy's -- The Moo Song");
  118. expect(item.media.description.type, "plain");
  119. expect(item.media.description.value,
  120. "This was some really bizarre band I listened to as a young lad.");
  121. expect(item.media.keywords, "kitty, cat, big dog, yarn, fluffy");
  122. expect(item.media.thumbnails.length, 2);
  123. var mediaThumbnail = item.media.thumbnails.first;
  124. expect(mediaThumbnail.url, "http://www.foo.com/keyframe1.jpg");
  125. expect(mediaThumbnail.width, "75");
  126. expect(mediaThumbnail.height, "50");
  127. expect(mediaThumbnail.time, "12:05:01.123");
  128. expect(item.media.hash.algo, "md5");
  129. expect(item.media.hash.value, "dfdec888b72151965a34b4b59031290a");
  130. expect(item.media.player.url, "http://www.foo.com/player?id=1111");
  131. expect(item.media.player.width, 400);
  132. expect(item.media.player.height, 200);
  133. expect(item.media.player.value, "");
  134. expect(item.media.copyright.url, "http://blah.com/additional-info.html");
  135. expect(item.media.copyright.value, "2005 FooBar Media");
  136. expect(item.media.text.type, "plain");
  137. expect(item.media.text.lang, "en");
  138. expect(item.media.text.start, "00:00:03.000");
  139. expect(item.media.text.end, "00:00:10.000");
  140. expect(item.media.text.value, " Oh, say, can you see");
  141. expect(item.media.restriction.relationship, "allow");
  142. expect(item.media.restriction.type, "country");
  143. expect(item.media.restriction.value, "au us");
  144. expect(item.media.community.starRating.average, 3.5);
  145. expect(item.media.community.starRating.count, 20);
  146. expect(item.media.community.starRating.min, 1);
  147. expect(item.media.community.starRating.max, 10);
  148. expect(item.media.community.statistics.views, 5);
  149. expect(item.media.community.statistics.favorites, 4);
  150. expect(item.media.community.tags.tags, "news: 5, abc:3");
  151. expect(item.media.community.tags.weight, 1);
  152. expect(item.media.comments.length, 2);
  153. expect(item.media.comments.first, "comment1");
  154. expect(item.media.comments.last, "comment2");
  155. expect(item.media.embed.url, "http://www.foo.com/player.swf");
  156. expect(item.media.embed.width, 512);
  157. expect(item.media.embed.height, 323);
  158. expect(item.media.embed.params.length, 5);
  159. expect(item.media.embed.params.first.name, "type");
  160. expect(
  161. item.media.embed.params.first.value, "application/x-shockwave-flash");
  162. expect(item.media.responses.length, 2);
  163. expect(item.media.responses.first, "http://www.response1.com");
  164. expect(item.media.responses.last, "http://www.response2.com");
  165. expect(item.media.backLinks.length, 2);
  166. expect(item.media.backLinks.first, "http://www.backlink1.com");
  167. expect(item.media.backLinks.last, "http://www.backlink2.com");
  168. expect(item.media.status.state, "active");
  169. expect(item.media.status.reason, null);
  170. expect(item.media.prices.length, 2);
  171. expect(item.media.prices.first.price, 19.99);
  172. expect(item.media.prices.first.type, "rent");
  173. expect(
  174. item.media.prices.first.info, "http://www.dummy.jp/package_info.html");
  175. expect(item.media.prices.first.currency, "EUR");
  176. expect(item.media.license.type, "text/html");
  177. expect(item.media.license.href, "http://www.licensehost.com/license");
  178. expect(item.media.license.value, " Sample license for a video");
  179. expect(item.media.peerLink.type, "application/x-bittorrent");
  180. expect(item.media.peerLink.href, "http://www.foo.org/sampleFile.torrent");
  181. expect(item.media.peerLink.value, "");
  182. expect(item.media.rights.status, "official");
  183. expect(item.media.scenes.length, 2);
  184. expect(item.media.scenes.first.title, "sceneTitle1");
  185. expect(item.media.scenes.first.description, "sceneDesc1");
  186. expect(item.media.scenes.first.startTime, "00:15");
  187. expect(item.media.scenes.first.endTime, "00:45");
  188. });
  189. test("parse RSS-DC.xml", () {
  190. var xmlString = File("test/xml/RSS-DC.xml").readAsStringSync();
  191. var feed = RssFeed.parse(xmlString);
  192. expect(feed.dc.title, "title");
  193. expect(feed.dc.creator, "creator");
  194. expect(feed.dc.subject, "subject");
  195. expect(feed.dc.description, "description");
  196. expect(feed.dc.publisher, "publisher");
  197. expect(feed.dc.contributor, "contributor");
  198. expect(feed.dc.date, "2000-01-01T12:00+00:00");
  199. expect(feed.dc.type, "type");
  200. expect(feed.dc.format, "format");
  201. expect(feed.dc.identifier, "identifier");
  202. expect(feed.dc.source, "source");
  203. expect(feed.dc.language, "language");
  204. expect(feed.dc.relation, "relation");
  205. expect(feed.dc.coverage, "coverage");
  206. expect(feed.dc.rights, "rights");
  207. expect(feed.items.first.dc.title, "title");
  208. expect(feed.items.first.dc.creator, "creator");
  209. expect(feed.items.first.dc.subject, "subject");
  210. expect(feed.items.first.dc.description, "description");
  211. expect(feed.items.first.dc.publisher, "publisher");
  212. expect(feed.items.first.dc.contributor, "contributor");
  213. expect(feed.items.first.dc.date, "2000-01-01T12:00+00:00");
  214. expect(feed.items.first.dc.type, "type");
  215. expect(feed.items.first.dc.format, "format");
  216. expect(feed.items.first.dc.identifier, "identifier");
  217. expect(feed.items.first.dc.source, "source");
  218. expect(feed.items.first.dc.language, "language");
  219. expect(feed.items.first.dc.relation, "relation");
  220. expect(feed.items.first.dc.coverage, "coverage");
  221. expect(feed.items.first.dc.rights, "rights");
  222. });
  223. test("parse RSS-Empty.xml", () {
  224. var xmlString = File("test/xml/RSS-Empty.xml").readAsStringSync();
  225. var feed = RssFeed.parse(xmlString);
  226. expect(feed.title, null);
  227. expect(feed.description, null);
  228. expect(feed.link, null);
  229. expect(feed.language, null);
  230. expect(feed.lastBuildDate, null);
  231. expect(feed.generator, null);
  232. expect(feed.copyright, null);
  233. expect(feed.docs, null);
  234. expect(feed.managingEditor, null);
  235. expect(feed.rating, null);
  236. expect(feed.webMaster, null);
  237. expect(feed.ttl, 0);
  238. expect(feed.image, null);
  239. expect(feed.cloud, null);
  240. expect(feed.categories.length, 0);
  241. expect(feed.skipDays.length, 0);
  242. expect(feed.skipHours.length, 0);
  243. expect(feed.items.length, 1);
  244. expect(feed.items.first.title, null);
  245. expect(feed.items.first.description, null);
  246. expect(feed.items.first.link, null);
  247. expect(feed.items.first.guid, null);
  248. expect(feed.items.first.pubDate, null);
  249. expect(feed.items.first.categories.length, 0);
  250. expect(feed.items.first.author, null);
  251. expect(feed.items.first.source, null);
  252. expect(feed.items.first.comments, null);
  253. expect(feed.items.first.enclosure, null);
  254. expect(feed.items.first.content, null);
  255. });
  256. test("parse RSS-Itunes.xml", () {
  257. var xmlString = File("test/xml/RSS-Itunes.xml").readAsStringSync();
  258. var feed = RssFeed.parse(xmlString);
  259. expect(feed.itunes.author, "Changelog Media");
  260. expect(feed.itunes.summary, "Foo");
  261. expect(feed.itunes.explicit, false);
  262. expect(feed.itunes.image.href,
  263. "https://cdn.changelog.com/uploads/covers/go-time-original.png?v=63725770357");
  264. expect(feed.itunes.keywords,
  265. "go,golang,open source,software,development".split(","));
  266. expect(feed.itunes.owner.name, "Changelog Media");
  267. expect(feed.itunes.owner.email, "editors@changelog.com");
  268. expect(
  269. Set.from([
  270. feed.itunes.categories[0].category,
  271. feed.itunes.categories[1].category
  272. ]),
  273. ["Technology", "Foo"]);
  274. for (var category in feed.itunes.categories) {
  275. switch (category.category) {
  276. case "Foo":
  277. expect(category.subCategories, ["Bar", "Baz"]);
  278. break;
  279. case "Technology":
  280. expect(category.subCategories, ["Software How-To", "Tech News"]);
  281. break;
  282. }
  283. }
  284. expect(feed.itunes.title, "Go Time");
  285. expect(feed.itunes.type, RssItunesType.serial);
  286. expect(feed.itunes.newFeedUrl, "wubawuba");
  287. expect(feed.itunes.block, true);
  288. expect(feed.itunes.complete, true);
  289. var item = feed.items[0];
  290. expect(item.itunes.episodeType, RssItunesEpisodeType.full);
  291. expect(item.itunes.episode, 1);
  292. expect(item.itunes.season, 1);
  293. expect(item.itunes.image.href,
  294. "https://cdn.changelog.com/uploads/covers/go-time-original.png?v=63725770357");
  295. expect(item.itunes.duration, Duration(minutes: 32, seconds: 30));
  296. expect(item.itunes.explicit, false);
  297. expect(item.itunes.keywords,
  298. "go,golang,open source,software,development".split(","));
  299. expect(item.itunes.subtitle, "with Erik, Carlisia, and Brian");
  300. expect(item.itunes.summary, "Foo");
  301. expect(item.itunes.author,
  302. "Erik St. Martin, Carlisia Pinto, and Brian Ketelsen");
  303. expect(item.itunes.explicit, false);
  304. expect(item.itunes.title, "awesome title");
  305. expect(item.itunes.block, false);
  306. });
  307. }