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.

204 lines
8.8 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class FeedTest extends PHPUnit_Framework_TestCase {
  5. private $http;
  6. public function setUp() {
  7. $this->client = new Parse();
  8. $this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
  9. $this->client->mc = null;
  10. }
  11. private function parse($params) {
  12. $request = new Request($params);
  13. $response = new Response();
  14. return $this->client->parse($request, $response);
  15. }
  16. public function testListOfHEntrys() {
  17. $url = 'http://feed.example.com/list-of-hentrys';
  18. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  19. $body = $response->getContent();
  20. $this->assertEquals(200, $response->getStatusCode());
  21. $data = json_decode($body)->data;
  22. $this->assertEquals('feed', $data->type);
  23. }
  24. public function testListOfHEntrysWithHCard() {
  25. $url = 'http://feed.example.com/list-of-hentrys-with-h-card';
  26. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  27. $body = $response->getContent();
  28. $this->assertEquals(200, $response->getStatusCode());
  29. $data = json_decode($body)->data;
  30. $this->assertEquals('feed', $data->type);
  31. }
  32. public function testShortListOfHEntrysWithHCard() {
  33. $url = 'http://feed.example.com/short-list-of-hentrys-with-h-card';
  34. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  35. $body = $response->getContent();
  36. $this->assertEquals(200, $response->getStatusCode());
  37. $data = json_decode($body)->data;
  38. $this->assertEquals('feed', $data->type);
  39. }
  40. public function testTopLevelHFeed() {
  41. $url = 'http://feed.example.com/top-level-h-feed';
  42. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  43. $body = $response->getContent();
  44. $this->assertEquals(200, $response->getStatusCode());
  45. $data = json_decode($body)->data;
  46. $this->assertEquals('feed', $data->type);
  47. }
  48. public function testHCardWithChildHEntrys() {
  49. $url = 'http://feed.example.com/h-card-with-child-h-entrys';
  50. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  51. $body = $response->getContent();
  52. $this->assertEquals(200, $response->getStatusCode());
  53. $data = json_decode($body)->data;
  54. $this->assertEquals('feed', $data->type);
  55. }
  56. public function testHCardWithChildHFeed() {
  57. $url = 'http://feed.example.com/h-card-with-child-h-feed';
  58. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  59. $body = $response->getContent();
  60. $this->assertEquals(200, $response->getStatusCode());
  61. $data = json_decode($body)->data;
  62. $this->assertEquals('feed', $data->type);
  63. }
  64. public function testJSONFeed() {
  65. $url = 'http://feed.example.com/jsonfeed';
  66. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  67. $body = $response->getContent();
  68. $this->assertEquals(200, $response->getStatusCode());
  69. $data = json_decode($body)->data;
  70. $this->assertEquals(10, count($data->items));
  71. for($i=0; $i<8; $i++) {
  72. $this->assertEquals('entry', $data->items[$i]->type);
  73. $this->assertEquals('manton', $data->items[$i]->author->name);
  74. $this->assertEquals('http://www.manton.org', $data->items[$i]->author->url);
  75. $this->assertNotEmpty($data->items[$i]->url);
  76. $this->assertNotEmpty($data->items[$i]->uid);
  77. $this->assertNotEmpty($data->items[$i]->published);
  78. $this->assertNotEmpty($data->items[$i]->content->html);
  79. $this->assertNotEmpty($data->items[$i]->content->text);
  80. }
  81. $this->assertEquals('<p>Lots of good feedback on <a href="http://help.micro.blog/2017/wordpress-import/">the WordPress import</a>. Made a couple improvements this morning. Overall, pretty good.</p>', $data->items[9]->content->html);
  82. $this->assertEquals('Lots of good feedback on the WordPress import. Made a couple improvements this morning. Overall, pretty good.', $data->items[9]->content->text);
  83. $this->assertEquals('http://www.manton.org/2017/11/5975.html', $data->items[9]->url);
  84. $this->assertEquals('http://www.manton.org/2017/11/5975.html', $data->items[9]->uid);
  85. $this->assertEquals('2017-11-07T15:04:01+00:00', $data->items[9]->published);
  86. $this->assertEquals('feed', $data->type);
  87. }
  88. public function testAtomFeed() {
  89. $url = 'http://feed.example.com/atom';
  90. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  91. $body = $response->getContent();
  92. $this->assertEquals(200, $response->getStatusCode());
  93. $data = json_decode($body)->data;
  94. $this->assertEquals(8, count($data->items));
  95. for($i=0; $i<8; $i++) {
  96. $this->assertEquals('entry', $data->items[$i]->type);
  97. $this->assertEquals('Tantek', $data->items[$i]->author->name);
  98. $this->assertEquals('http://tantek.com/', $data->items[$i]->author->url);
  99. $this->assertNotEmpty($data->items[$i]->url);
  100. $this->assertNotEmpty($data->items[$i]->published);
  101. $this->assertNotEmpty($data->items[$i]->content->html);
  102. $this->assertNotEmpty($data->items[$i]->content->text);
  103. }
  104. $this->assertEquals('2017-11-08T23:53:00-08:00', $data->items[0]->published);
  105. $this->assertEquals('http://tantek.com/2017/312/t3/tam-trail-run-first-trail-half', $data->items[0]->url);
  106. $this->assertEquals('went to MORE Pancakes! this morning @RunJanji pop-up on California st after #NPSF. Picked up a new running shirt.', $data->items[1]->content->text);
  107. $this->assertEquals('went to MORE Pancakes! this morning <a href="https://twitter.com/RunJanji">@RunJanji</a> pop-up on California st after #NPSF. Picked up a new running shirt.', $data->items[1]->content->html);
  108. $this->assertEquals('feed', $data->type);
  109. }
  110. public function testRSSFeed() {
  111. $url = 'http://feed.example.com/rss';
  112. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  113. $body = $response->getContent();
  114. $this->assertEquals(200, $response->getStatusCode());
  115. $data = json_decode($body)->data;
  116. $this->assertEquals(10, count($data->items));
  117. for($i=0; $i<10; $i++) {
  118. $this->assertEquals('entry', $data->items[$i]->type);
  119. $this->assertEquals('Ryan Barrett', $data->items[$i]->author->name);
  120. $this->assertEquals('https://snarfed.org/', $data->items[$i]->author->url);
  121. $this->assertNotEmpty($data->items[$i]->url);
  122. $this->assertNotEmpty($data->items[$i]->published);
  123. $this->assertNotEmpty($data->items[$i]->content->html);
  124. if($i > 1)
  125. $this->assertNotEmpty($data->items[$i]->content->text);
  126. }
  127. $this->assertEquals('2017-09-12T20:09:12+00:00', $data->items[9]->published);
  128. $this->assertEquals('https://snarfed.org/2017-09-12_25492', $data->items[9]->url);
  129. $this->assertEquals('<p>new business cards <img src="https://s.w.org/images/core/emoji/2.3/72x72/1f602.png" alt="😂" /></p>
  130. <p><img src="https://i0.wp.com/snarfed.org/w/wp-content/uploads/2017/09/IMG_20170912_131414_767.jpg?w=696&amp;ssl=1" alt="IMG_20170912_131414_767.jpg?w=696&amp;ssl=1" /></p>', $data->items[9]->content->html);
  131. $this->assertEquals('new business cards', $data->items[9]->content->text);
  132. $this->assertEquals('feed', $data->type);
  133. }
  134. public function testPodcastFeed() {
  135. $url = 'http://feed.example.com/podcast-rss';
  136. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  137. $body = $response->getContent();
  138. $this->assertEquals(200, $response->getStatusCode());
  139. $data = json_decode($body)->data;
  140. $this->assertEquals(12, count($data->items));
  141. for($i=0; $i<12; $i++) {
  142. $this->assertEquals('entry', $data->items[$i]->type);
  143. $this->assertEquals('Aaron Parecki', $data->items[$i]->author->name);
  144. $this->assertEquals('https://percolator.today/', $data->items[$i]->author->url);
  145. $this->assertNotEmpty($data->items[$i]->url);
  146. $this->assertNotEmpty($data->items[$i]->published);
  147. $this->assertNotEmpty($data->items[$i]->name);
  148. $this->assertNotEmpty($data->items[$i]->content->html);
  149. $this->assertNotEmpty($data->items[$i]->content->text);
  150. $this->assertNotEmpty($data->items[$i]->audio);
  151. }
  152. $this->assertEquals('Episode 1: Welcome', $data->items[11]->name);
  153. $this->assertEquals('https://percolator.today/episode/1', $data->items[11]->url);
  154. $this->assertEquals('2017-09-20T07:00:00+00:00', $data->items[11]->published);
  155. $this->assertEquals('https://percolator.today/redirect.php?url=https%3A%2F%2Fpercolator.today%2Fmedia%2FPercolator_Episode_1.mp3', $data->items[11]->audio);
  156. $this->assertContains('What is Percolator? Some thoughts about multi-photos in Instagram.', $data->items[11]->content->text);
  157. $this->assertContains('What is Percolator? Some thoughts about multi-photos in Instagram.', $data->items[11]->content->html);
  158. $this->assertContains('<li><a href="https://indieweb.org/multi-photo_vs_collection">multi-photo vs collection</a></li>', $data->items[11]->content->html);
  159. $this->assertEquals('feed', $data->type);
  160. }
  161. }