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.

221 lines
11 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class InstagramTest 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 testInstagramPhoto() {
  17. // Original URL: https://www.instagram.com/p/BO5rYVElvJq/
  18. $url = 'https://www.instagram.com/p/BO5rYVElvJq/';
  19. $response = $this->parse(['url' => $url]);
  20. $body = $response->getContent();
  21. $this->assertEquals(200, $response->getStatusCode());
  22. $data = json_decode($body, true);
  23. $this->assertEquals('entry', $data['data']['type']);
  24. $this->assertEquals('photo', $data['data']['post-type']);
  25. $this->assertEquals('2017-01-05T23:31:32+00:00', $data['data']['published']);
  26. $this->assertContains('planning', $data['data']['category']);
  27. $this->assertContains('2017', $data['data']['category']);
  28. $this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']);
  29. $this->assertEquals(1, count($data['data']['photo']));
  30. $this->assertEquals(['https://instagram.fsea1-1.fna.fbcdn.net/vp/214e719b6026ef54e0545f2ed70d4c83/5B56795F/t51.2885-15/e35/15803256_1832278043695907_4846092951052353536_n.jpg'], $data['data']['photo']);
  31. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  32. $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
  33. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/0dc6166cbd4ec6782453d36cd07fec06/5B67568E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg', $data['data']['author']['photo']);
  34. }
  35. public function testBGDpqNoiMJ0() {
  36. // https://www.instagram.com/p/BGDpqNoiMJ0/
  37. $url = 'http://www.instagram.com/BGDpqNoiMJ0';
  38. $response = $this->parse(['url' => $url]);
  39. $body = $response->getContent();
  40. $this->assertEquals(200, $response->getStatusCode());
  41. $data = json_decode($body, true);
  42. $this->assertEquals('entry', $data['data']['type']);
  43. $this->assertEquals('photo', $data['data']['post-type']);
  44. $this->assertSame([
  45. 'type' => 'card',
  46. 'name' => 'pk_spam',
  47. 'url' => 'https://aaronparecki.com/',
  48. 'photo' => 'https://instagram.fhel2-1.fna.fbcdn.net/vp/f17e1275a70fc32e93cbf434ddc32bcd/5B6CCC7A/t51.2885-19/11906329_960233084022564_1448528159_a.jpg',
  49. 'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/'
  50. ], $data['data']['author']);
  51. $this->assertSame([
  52. 'muffins',
  53. 'https://indiewebcat.com/'
  54. ], $data['data']['category']);
  55. $this->assertEquals('Meow #muffins', $data['data']['content']['text']);
  56. $this->assertSame(['https://instagram.fsea1-1.fna.fbcdn.net/vp/9433ea494a8b055bebabf70fd81cfa32/5B51F092/t51.2885-15/e35/13266755_877794672348882_1908663476_n.jpg'], $data['data']['photo']);
  57. $this->assertEquals('2016-05-30T20:46:22-07:00', $data['data']['published']);
  58. $this->assertEquals('https://www.instagram.com/explore/locations/359000003/', $data['data']['location'][0]);
  59. $this->assertSame([
  60. 'type' => 'card',
  61. 'name' => 'Burnside 26',
  62. 'url' => 'https://www.instagram.com/explore/locations/359000003/',
  63. 'latitude' => 45.5228640678,
  64. 'longitude' => -122.6389405085
  65. ], $data['data']['refs']['https://www.instagram.com/explore/locations/359000003/']);
  66. }
  67. public function testInstagramVideo() {
  68. // Original URL: https://www.instagram.com/p/BO_RN8AFZSx/
  69. $url = 'https://www.instagram.com/p/BO_RN8AFZSx/';
  70. $response = $this->parse(['url' => $url]);
  71. $body = $response->getContent();
  72. $this->assertEquals(200, $response->getStatusCode());
  73. $data = json_decode($body, true);
  74. $this->assertEquals('entry', $data['data']['type']);
  75. $this->assertEquals('video', $data['data']['post-type']);
  76. $this->assertContains('100daysofmusic', $data['data']['category']);
  77. $this->assertEquals('Day 18. Maple and Spruce #100daysofmusic #100daysproject #the100dayproject https://aaronparecki.com/2017/01/07/14/day18', $data['data']['content']['text']);
  78. $this->assertEquals(1, count($data['data']['photo']));
  79. $this->assertEquals(['https://instagram.fsea1-1.fna.fbcdn.net/vp/32890db04701c4ab4fa7da05a6e9de93/5ADB9BDF/t51.2885-15/e15/15624670_548881701986735_8264383763249627136_n.jpg'], $data['data']['photo']);
  80. $this->assertEquals(1, count($data['data']['video']));
  81. $this->assertEquals(['https://instagram.fsea1-1.fna.fbcdn.net/vp/46c7118509146b978fb7bfc497eeb16f/5ADB639E/t50.2886-16/15921147_1074837002642259_2269307616507199488_n.mp4'], $data['data']['video']);
  82. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  83. $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
  84. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/0dc6166cbd4ec6782453d36cd07fec06/5B67568E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg', $data['data']['author']['photo']);
  85. }
  86. public function testInstagramPhotoWithPersonTag() {
  87. // Original URL: https://www.instagram.com/p/BNfqVfVlmkj/
  88. $url = 'https://www.instagram.com/p/BNfqVfVlmkj/';
  89. $response = $this->parse(['url' => $url]);
  90. $body = $response->getContent();
  91. $this->assertEquals(200, $response->getStatusCode());
  92. $data = json_decode($body, true);
  93. $this->assertEquals(2, count($data['data']['category']));
  94. $this->assertContains('http://www.kmikeym.com/', $data['data']['category']);
  95. $this->assertArrayHasKey('http://www.kmikeym.com/', $data['data']['refs']);
  96. $this->assertEquals(['type'=>'card','name'=>'Mike Merrill','url'=>'http://www.kmikeym.com/','photo'=>'https://instagram.fsea1-1.fna.fbcdn.net/vp/dea521b3000a53d2d9a6845f5b066256/5B66D2FC/t51.2885-19/s320x320/20634957_814691788710973_2275383796935163904_a.jpg','note'=>'The world’s first Publicly Traded Person and working on things at @sandwichvideo'], $data['data']['refs']['http://www.kmikeym.com/']);
  97. }
  98. public function testInstagramPhotoWithVenue() {
  99. // Original URL: https://www.instagram.com/p/BN3Z5salSys/
  100. $url = 'https://www.instagram.com/p/BN3Z5salSys/';
  101. $response = $this->parse(['url' => $url]);
  102. $body = $response->getContent();
  103. $this->assertEquals(200, $response->getStatusCode());
  104. $data = json_decode($body, true);
  105. $this->assertEquals(1, count($data['data']['location']));
  106. $this->assertContains('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['location']);
  107. $this->assertArrayHasKey('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['refs']);
  108. $venue = $data['data']['refs']['https://www.instagram.com/explore/locations/109284789535230/'];
  109. $this->assertEquals('XOXO Outpost', $venue['name']);
  110. $this->assertEquals('45.5261002', $venue['latitude']);
  111. $this->assertEquals('-122.6558081', $venue['longitude']);
  112. // Setting a venue should set the timezone
  113. $this->assertEquals('2016-12-10T21:48:56-08:00', $data['data']['published']);
  114. }
  115. public function testTwoPhotos() {
  116. // Original URL: https://www.instagram.com/p/BZWmUB_DVtp/
  117. $url = 'https://www.instagram.com/p/BZWmUB_DVtp/';
  118. $response = $this->parse(['url' => $url]);
  119. $body = $response->getContent();
  120. $this->assertEquals(200, $response->getStatusCode());
  121. $data = json_decode($body, true);
  122. $this->assertEquals(2, count($data['data']['photo']));
  123. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/406101ff9601ab78147e121b65ce3eea/5B5BC738/t51.2885-15/e35/21827424_134752690591737_8093088291252862976_n.jpg', $data['data']['photo'][0]);
  124. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/03ddc8c03c8708439dae29663b8c2305/5B5EDE4D/t51.2885-15/e35/21909774_347707439021016_5237540582556958720_n.jpg', $data['data']['photo'][1]);
  125. $this->assertArrayNotHasKey('video', $data['data']);
  126. $this->assertEquals(2, count($data['data']['category']));
  127. }
  128. public function testMixPhotosAndVideos() {
  129. // Original URL: https://www.instagram.com/p/BZWmpecjBwN/
  130. $url = 'https://www.instagram.com/p/BZWmpecjBwN/';
  131. $response = $this->parse(['url' => $url]);
  132. $body = $response->getContent();
  133. $this->assertEquals(200, $response->getStatusCode());
  134. $data = json_decode($body, true);
  135. $this->assertEquals('photo', $data['data']['post-type']); // we discard videos in this case right now
  136. $this->assertEquals(3, count($data['data']['photo']));
  137. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/b0f6cd9dc4d5c3371efe9f412a0d7f0b/5B6BC5B8/t51.2885-15/e35/21878922_686481254874005_8468823712617988096_n.jpg', $data['data']['photo'][0]);
  138. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/f8939cca504f97931fd4768b77d2c152/5ADB3CC9/t51.2885-15/e15/21910026_1507234999368159_6974261907783942144_n.jpg', $data['data']['photo'][1]);
  139. $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/254c313bdcac37c19da5e10be8222a88/5B689788/t51.2885-15/e35/21878800_273567963151023_7672178549897297920_n.jpg', $data['data']['photo'][2]);
  140. $this->assertArrayNotHasKey('video', $data['data']);
  141. $this->assertEquals(2, count($data['data']['category']));
  142. }
  143. public function testInstagramProfile() {
  144. $url = 'https://www.instagram.com/aaronpk/';
  145. $response = $this->parse(['url' => $url]);
  146. $body = $response->getContent();
  147. $this->assertEquals(200, $response->getStatusCode());
  148. $data = json_decode($body, true);
  149. $this->assertSame([
  150. 'type' => 'card',
  151. 'name' => 'Aaron Parecki',
  152. 'url' => 'https://aaronparecki.com/',
  153. 'photo' => 'https://instagram.fsea1-1.fna.fbcdn.net/vp/0dc6166cbd4ec6782453d36cd07fec06/5B67568E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg',
  154. 'note' => '📡 w7apk.com 🔒 oauth.net 🎥 backpedal.tv 🎙 streampdx.com'
  155. ], $data['data']);
  156. }
  157. public function testInstagramProfileWithBio() {
  158. $url = 'https://www.instagram.com/pk_spam/';
  159. $response = $this->parse(['url' => $url]);
  160. $body = $response->getContent();
  161. $this->assertEquals(200, $response->getStatusCode());
  162. $data = json_decode($body, true);
  163. $this->assertSame([
  164. 'type' => 'card',
  165. 'name' => 'pk_spam',
  166. 'url' => 'https://aaronparecki.com/',
  167. 'photo' => 'https://instagram.fhel2-1.fna.fbcdn.net/vp/f17e1275a70fc32e93cbf434ddc32bcd/5B6CCC7A/t51.2885-19/11906329_960233084022564_1448528159_a.jpg',
  168. 'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/'
  169. ], $data['data']);
  170. }
  171. public function testInstagramProfileFeed() {
  172. $url = 'https://www.instagram.com/pk_spam/';
  173. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  174. $body = $response->getContent();
  175. $this->assertEquals(200, $response->getStatusCode());
  176. $data = json_decode($body, true);
  177. $this->assertEquals('feed', $data['data']['type']);
  178. $this->assertEquals(12, count($data['data']['items']));
  179. $this->assertEquals('https://www.instagram.com/p/Be0lBpGDncI/', $data['data']['items'][0]['url']);
  180. $this->assertEquals('https://www.instagram.com/p/BGC8l_ZCMKb/', $data['data']['items'][11]['url']);
  181. }
  182. }