The Webfeed Flutter package for Appeto SDK.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

425 řádky
17 KiB

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