The Webfeed Flutter package for Appeto SDK.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

261 righe
9.8 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 = File('test/xml/Invalid.xml').readAsStringSync();
  8. try {
  9. AtomFeed.parse(xmlString);
  10. fail('Should throw Argument Error');
  11. } on ArgumentError {}
  12. });
  13. test('parse Atom.xml', () {
  14. var xmlString = File('test/xml/Atom.xml').readAsStringSync();
  15. var feed = AtomFeed.parse(xmlString);
  16. expect(feed.id, 'foo-bar-id');
  17. expect(feed.title, 'Foo bar news');
  18. expect(feed.updated, DateTime.utc(2018, 4, 6, 13, 2, 46));
  19. expect(feed.links!.length, 2);
  20. expect(feed.links!.first.rel, 'foo');
  21. expect(feed.links!.first.type, 'text/html');
  22. expect(feed.links!.first.hreflang, 'en');
  23. expect(feed.links!.first.href, 'http://foo.bar.news/');
  24. expect(feed.links!.first.title, 'Foo bar news html');
  25. expect(feed.links!.first.length, 1000);
  26. expect(feed.authors!.length, 2);
  27. expect(feed.authors!.first.name, 'Alice');
  28. expect(feed.authors!.first.uri, 'http://foo.bar.news/people/alice');
  29. expect(feed.authors!.first.email, 'alice@foo.bar.news');
  30. expect(feed.contributors!.length, 2);
  31. expect(feed.contributors!.first.name, 'Charlie');
  32. expect(feed.contributors!.first.uri, 'http://foo.bar.news/people/charlie');
  33. expect(feed.contributors!.first.email, 'charlie@foo.bar.news');
  34. expect(feed.categories!.length, 2);
  35. expect(feed.categories!.first.term, 'foo category');
  36. expect(feed.categories!.first.scheme, 'this-is-foo-scheme');
  37. expect(feed.categories!.first.label, 'this is foo label');
  38. expect(feed.generator!.uri, 'http://foo.bar.news/generator');
  39. expect(feed.generator!.version, '1.0');
  40. expect(feed.generator!.value, 'Foo bar generator');
  41. expect(feed.icon, 'http://foo.bar.news/icon.png');
  42. expect(feed.logo, 'http://foo.bar.news/logo.png');
  43. expect(feed.subtitle, 'This is subtitle');
  44. expect(feed.items!.length, 2);
  45. var item = feed.items!.first;
  46. expect(item.id, 'foo-bar-entry-id-1');
  47. expect(item.title, 'Foo bar item 1');
  48. expect(item.updated, DateTime.utc(2018, 4, 6, 13, 2, 40));
  49. expect(item.authors!.length, 2);
  50. expect(item.authors!.first.name, 'Ellie');
  51. expect(item.authors!.first.uri, 'http://foo.bar.news/people/ellie');
  52. expect(item.authors!.first.email, 'ellie@foo.bar.news');
  53. expect(item.links!.length, 2);
  54. expect(item.links!.first.rel, 'foo entry');
  55. expect(item.links!.first.type, 'text/html');
  56. expect(item.links!.first.hreflang, 'en');
  57. expect(item.links!.first.href, 'http://foo.bar.news/entry');
  58. expect(item.links!.first.title, 'Foo bar news html');
  59. expect(item.links!.first.length, 1000);
  60. expect(item.categories!.length, 2);
  61. expect(item.categories!.first.term, 'foo entry category');
  62. expect(item.categories!.first.scheme, 'this-is-foo-entry-scheme');
  63. expect(item.categories!.first.label, 'this is foo entry label');
  64. expect(item.contributors!.length, 2);
  65. expect(item.contributors!.first.name, 'Gin');
  66. expect(item.contributors!.first.uri, 'http://foo.bar.news/people/gin');
  67. expect(item.contributors!.first.email, 'gin@foo.bar.news');
  68. expect(item.published, '2018-04-06T13:02:49Z');
  69. expect(item.summary, 'This is summary 1');
  70. expect(item.content, 'This is content 1');
  71. expect(item.rights, 'This is rights 1');
  72. });
  73. test('parse Atom-Media.xml', () {
  74. var xmlString = File('test/xml/Atom-Media.xml').readAsStringSync();
  75. var feed = AtomFeed.parse(xmlString);
  76. expect(feed.id, 'foo-bar-id');
  77. expect(feed.title, 'Foo bar news');
  78. expect(feed.updated, DateTime.utc(2018, 4, 6, 13, 2, 46));
  79. expect(feed.items!.length, 1);
  80. var item = feed.items!.first;
  81. expect(item.media!.group!.contents!.length, 5);
  82. expect(item.media!.group!.credits!.length, 2);
  83. expect(item.media!.group!.category!.value, 'music/artist name/album/song');
  84. expect(item.media!.group!.rating!.value, 'nonadult');
  85. expect(item.media!.contents!.length, 2);
  86. var mediaContent = item.media!.contents!.first;
  87. expect(mediaContent.url, 'http://www.foo.com/video.mov');
  88. expect(mediaContent.type, 'video/quicktime');
  89. expect(mediaContent.fileSize, 2000);
  90. expect(mediaContent.medium, 'video');
  91. expect(mediaContent.isDefault, true);
  92. expect(mediaContent.expression, 'full');
  93. expect(mediaContent.bitrate, 128);
  94. expect(mediaContent.framerate, 25);
  95. expect(mediaContent.samplingrate, 44.1);
  96. expect(mediaContent.channels, 2);
  97. expect(item.media!.credits!.length, 2);
  98. var mediaCredit = item.media!.credits!.first;
  99. expect(mediaCredit.role, 'owner1');
  100. expect(mediaCredit.scheme, 'urn:yvs');
  101. expect(mediaCredit.value, 'copyright holder of the entity');
  102. expect(item.media!.category!.scheme,
  103. 'http://search.yahoo.com/mrss/category_ schema');
  104. expect(item.media!.category!.label, 'Music');
  105. expect(item.media!.category!.value, 'music/artist/album/song');
  106. expect(item.media!.rating!.scheme, 'urn:simple');
  107. expect(item.media!.rating!.value, 'adult');
  108. expect(item.media!.title!.type, 'plain');
  109. expect(item.media!.title!.value, "The Judy's -- The Moo Song");
  110. expect(item.media!.description!.type, 'plain');
  111. expect(item.media!.description!.value,
  112. 'This was some really bizarre band I listened to as a young lad.');
  113. expect(item.media!.keywords, 'kitty, cat, big dog, yarn, fluffy');
  114. expect(item.media!.thumbnails!.length, 2);
  115. var mediaThumbnail = item.media!.thumbnails!.first;
  116. expect(mediaThumbnail.url, 'http://www.foo.com/keyframe1.jpg');
  117. expect(mediaThumbnail.width, '75');
  118. expect(mediaThumbnail.height, '50');
  119. expect(mediaThumbnail.time, '12:05:01.123');
  120. expect(item.media!.hash!.algo, 'md5');
  121. expect(item.media!.hash!.value, 'dfdec888b72151965a34b4b59031290a');
  122. expect(item.media!.player!.url, 'http://www.foo.com/player?id=1111');
  123. expect(item.media!.player!.width, 400);
  124. expect(item.media!.player!.height, 200);
  125. expect(item.media!.player!.value, '');
  126. expect(item.media!.copyright!.url, 'http://blah.com/additional-info.html');
  127. expect(item.media!.copyright!.value, '2005 FooBar Media');
  128. expect(item.media!.text!.type, 'plain');
  129. expect(item.media!.text!.lang, 'en');
  130. expect(item.media!.text!.start, '00:00:03.000');
  131. expect(item.media!.text!.end, '00:00:10.000');
  132. expect(item.media!.text!.value, ' Oh, say, can you see');
  133. expect(item.media!.restriction!.relationship, 'allow');
  134. expect(item.media!.restriction!.type, 'country');
  135. expect(item.media!.restriction!.value, 'au us');
  136. expect(item.media!.community!.starRating!.average, 3.5);
  137. expect(item.media!.community!.starRating!.count, 20);
  138. expect(item.media!.community!.starRating!.min, 1);
  139. expect(item.media!.community!.starRating!.max, 10);
  140. expect(item.media!.community!.statistics!.views, 5);
  141. expect(item.media!.community!.statistics!.favorites, 4);
  142. expect(item.media!.community!.tags!.tags, 'news: 5, abc:3');
  143. expect(item.media!.community!.tags!.weight, 1);
  144. expect(item.media!.comments!.length, 2);
  145. expect(item.media!.comments!.first, 'comment1');
  146. expect(item.media!.comments!.last, 'comment2');
  147. expect(item.media!.embed!.url, 'http://www.foo.com/player.swf');
  148. expect(item.media!.embed!.width, 512);
  149. expect(item.media!.embed!.height, 323);
  150. expect(item.media!.embed!.params!.length, 5);
  151. expect(item.media!.embed!.params!.first.name, 'type');
  152. expect(item.media!.embed!.params!.first.value,
  153. 'application/x-shockwave-flash');
  154. expect(item.media!.responses!.length, 2);
  155. expect(item.media!.responses!.first, 'http://www.response1.com');
  156. expect(item.media!.responses!.last, 'http://www.response2.com');
  157. expect(item.media!.backLinks!.length, 2);
  158. expect(item.media!.backLinks!.first, 'http://www.backlink1.com');
  159. expect(item.media!.backLinks!.last, 'http://www.backlink2.com');
  160. expect(item.media!.status!.state, 'active');
  161. expect(item.media!.status!.reason, null);
  162. expect(item.media!.prices!.length, 2);
  163. expect(item.media!.prices!.first.price, 19.99);
  164. expect(item.media!.prices!.first.type, 'rent');
  165. expect(item.media!.prices!.first.info,
  166. 'http://www.dummy.jp/package_info.html');
  167. expect(item.media!.prices!.first.currency, 'EUR');
  168. expect(item.media!.license!.type, 'text/html');
  169. expect(item.media!.license!.href, 'http://www.licensehost.com/license');
  170. expect(item.media!.license!.value, ' Sample license for a video');
  171. expect(item.media!.peerLink!.type, 'application/x-bittorrent');
  172. expect(item.media!.peerLink!.href, 'http://www.foo.org/sampleFile.torrent');
  173. expect(item.media!.peerLink!.value, '');
  174. expect(item.media!.rights!.status, 'official');
  175. expect(item.media!.scenes!.length, 2);
  176. expect(item.media!.scenes!.first.title, 'sceneTitle1');
  177. expect(item.media!.scenes!.first.description, 'sceneDesc1');
  178. expect(item.media!.scenes!.first.startTime, '00:15');
  179. expect(item.media!.scenes!.first.endTime, '00:45');
  180. });
  181. test('parse Atom-Empty.xml', () {
  182. var xmlString = File('test/xml/Atom-Empty.xml').readAsStringSync();
  183. var feed = AtomFeed.parse(xmlString);
  184. expect(feed.id, null);
  185. expect(feed.title, null);
  186. expect(feed.updated, null);
  187. expect(feed.links!.length, 0);
  188. expect(feed.authors!.length, 0);
  189. expect(feed.contributors!.length, 0);
  190. expect(feed.categories!.length, 0);
  191. expect(feed.generator, null);
  192. expect(feed.icon, null);
  193. expect(feed.logo, null);
  194. expect(feed.subtitle, null);
  195. expect(feed.items!.length, 1);
  196. var item = feed.items!.first;
  197. expect(item.authors!.length, 0);
  198. expect(item.links!.length, 0);
  199. expect(item.categories!.length, 0);
  200. expect(item.contributors!.length, 0);
  201. expect(item.published, null);
  202. expect(item.summary, null);
  203. expect(item.content, null);
  204. expect(item.rights, null);
  205. });
  206. }