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.

175 lines
7.2 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 testAtomFeed() {
  65. $url = 'http://feed.example.com/atom';
  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(8, count($data->items));
  71. for($i=0; $i<8; $i++) {
  72. $this->assertEquals('entry', $data->items[$i]->type);
  73. $this->assertEquals('Tantek', $data->items[$i]->author->name);
  74. $this->assertEquals('http://tantek.com/', $data->items[$i]->author->url);
  75. $this->assertNotEmpty($data->items[$i]->url);
  76. $this->assertNotEmpty($data->items[$i]->published);
  77. $this->assertNotEmpty($data->items[$i]->content->html);
  78. $this->assertNotEmpty($data->items[$i]->content->text);
  79. }
  80. $this->assertEquals('2017-11-08T23:53:00-08:00', $data->items[0]->published);
  81. $this->assertEquals('http://tantek.com/2017/312/t3/tam-trail-run-first-trail-half', $data->items[0]->url);
  82. $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);
  83. $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);
  84. $this->assertEquals('feed', $data->type);
  85. }
  86. public function testRSSFeed() {
  87. $url = 'http://feed.example.com/rss';
  88. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  89. $body = $response->getContent();
  90. $this->assertEquals(200, $response->getStatusCode());
  91. $data = json_decode($body)->data;
  92. $this->assertEquals(10, count($data->items));
  93. for($i=0; $i<10; $i++) {
  94. $this->assertEquals('entry', $data->items[$i]->type);
  95. $this->assertEquals('Ryan Barrett', $data->items[$i]->author->name);
  96. $this->assertEquals('https://snarfed.org/', $data->items[$i]->author->url);
  97. $this->assertNotEmpty($data->items[$i]->url);
  98. $this->assertNotEmpty($data->items[$i]->published);
  99. $this->assertNotEmpty($data->items[$i]->content->html);
  100. if($i > 1)
  101. $this->assertNotEmpty($data->items[$i]->content->text);
  102. }
  103. $this->assertEquals('2017-09-12T20:09:12+00:00', $data->items[9]->published);
  104. $this->assertEquals('https://snarfed.org/2017-09-12_25492', $data->items[9]->url);
  105. $this->assertEquals('<p>new business cards <img src="https://s.w.org/images/core/emoji/2.3/72x72/1f602.png" alt="😂" /></p>
  106. <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);
  107. $this->assertEquals('new business cards', $data->items[9]->content->text);
  108. $this->assertEquals('feed', $data->type);
  109. }
  110. public function testPodcastFeed() {
  111. $url = 'http://feed.example.com/podcast-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(12, count($data->items));
  117. for($i=0; $i<12; $i++) {
  118. $this->assertEquals('entry', $data->items[$i]->type);
  119. $this->assertEquals('Aaron Parecki', $data->items[$i]->author->name);
  120. $this->assertEquals('https://percolator.today/', $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]->name);
  124. $this->assertNotEmpty($data->items[$i]->content->html);
  125. $this->assertNotEmpty($data->items[$i]->content->text);
  126. $this->assertNotEmpty($data->items[$i]->audio);
  127. }
  128. $this->assertEquals('Episode 1: Welcome', $data->items[11]->name);
  129. $this->assertEquals('https://percolator.today/episode/1', $data->items[11]->url);
  130. $this->assertEquals('2017-09-20T07:00:00+00:00', $data->items[11]->published);
  131. $this->assertEquals('https://percolator.today/redirect.php?url=https%3A%2F%2Fpercolator.today%2Fmedia%2FPercolator_Episode_1.mp3', $data->items[11]->audio);
  132. $this->assertContains('What is Percolator? Some thoughts about multi-photos in Instagram.', $data->items[11]->content->text);
  133. $this->assertContains('What is Percolator? Some thoughts about multi-photos in Instagram.', $data->items[11]->content->html);
  134. $this->assertContains('<li><a href="https://indieweb.org/multi-photo_vs_collection">multi-photo vs collection</a></li>', $data->items[11]->content->html);
  135. $this->assertEquals('feed', $data->type);
  136. }
  137. }