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.

296 lines
16 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(200, $data['code']);
  24. $this->assertEquals('instagram', $data['source-format']);
  25. $this->assertEquals('entry', $data['data']['type']);
  26. $this->assertEquals('photo', $data['data']['post-type']);
  27. $this->assertEquals('2017-01-05T23:31:32+00:00', $data['data']['published']);
  28. $this->assertContains('planning', $data['data']['category']);
  29. $this->assertContains('2017', $data['data']['category']);
  30. $this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']);
  31. $this->assertEquals(1, count($data['data']['photo']));
  32. $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/af9471f885e6197478d71807a7cbf297/5CBA6E5F/t51.2885-15/e35/15803256_1832278043695907_4846092951052353536_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['photo']);
  33. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  34. $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
  35. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
  36. $this->assertArrayNotHasKey('meta', $data['data']); // make sure this does not include alt text (autogenerated placeholder from instagram)
  37. }
  38. public function testBGDpqNoiMJ0() {
  39. // https://www.instagram.com/p/BGDpqNoiMJ0/
  40. $url = 'http://www.instagram.com/BGDpqNoiMJ0';
  41. $response = $this->parse(['url' => $url]);
  42. $body = $response->getContent();
  43. $this->assertEquals(200, $response->getStatusCode());
  44. $data = json_decode($body, true);
  45. $this->assertEquals(200, $data['code']);
  46. $this->assertEquals('instagram', $data['source-format']);
  47. $this->assertEquals('entry', $data['data']['type']);
  48. $this->assertEquals('photo', $data['data']['post-type']);
  49. $this->assertSame([
  50. 'type' => 'card',
  51. 'name' => 'pk_spam',
  52. 'url' => 'https://aaronparecki.com/',
  53. 'photo' => 'https://scontent-frx5-1.cdninstagram.com/vp/74112f515c64726429c69fedcb927c2d/5CB64CF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-frx5-1.cdninstagram.com',
  54. 'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/'
  55. ], $data['data']['author']);
  56. $this->assertSame([
  57. 'muffins',
  58. 'https://indiewebcat.com/'
  59. ], $data['data']['category']);
  60. $this->assertEquals('Meow #muffins', $data['data']['content']['text']);
  61. $this->assertSame(['https://instagram.fsea1-1.fna.fbcdn.net/vp/9433ea494a8b055bebabf70fd81cfa32/5B51F092/t51.2885-15/e35/13266755_877794672348882_1908663476_n.jpg'], $data['data']['photo']);
  62. $this->assertEquals('2016-05-30T20:46:22-07:00', $data['data']['published']);
  63. $this->assertEquals('https://www.instagram.com/explore/locations/359000003/', $data['data']['location'][0]);
  64. $this->assertSame([
  65. 'type' => 'card',
  66. 'name' => 'Burnside 26',
  67. 'url' => 'https://www.instagram.com/explore/locations/359000003/',
  68. 'latitude' => 45.52322,
  69. 'longitude' => -122.63885
  70. ], $data['data']['refs']['https://www.instagram.com/explore/locations/359000003/']);
  71. }
  72. public function testInstagramVideo() {
  73. // Original URL: https://www.instagram.com/p/BO_RN8AFZSx/
  74. $url = 'https://www.instagram.com/p/BO_RN8AFZSx/';
  75. $response = $this->parse(['url' => $url]);
  76. $body = $response->getContent();
  77. $this->assertEquals(200, $response->getStatusCode());
  78. $data = json_decode($body, true);
  79. $this->assertEquals(200, $data['code']);
  80. $this->assertEquals('instagram', $data['source-format']);
  81. $this->assertEquals('entry', $data['data']['type']);
  82. $this->assertEquals('video', $data['data']['post-type']);
  83. $this->assertContains('100daysofmusic', $data['data']['category']);
  84. $this->assertEquals('Day 18. Maple and Spruce #100daysofmusic #100daysproject #the100dayproject https://aaronparecki.com/2017/01/07/14/day18', $data['data']['content']['text']);
  85. $this->assertEquals(1, count($data['data']['photo']));
  86. $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/a77f8672f977413d2eb5239cd6d5c4cf/5C3A4ADF/t51.2885-15/e15/15624670_548881701986735_8264383763249627136_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['photo']);
  87. $this->assertEquals(1, count($data['data']['video']));
  88. $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/90ed8fe576cba16e258c0f4cfc05299a/5C3A129E/t50.2886-16/15921147_1074837002642259_2269307616507199488_n.mp4?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['video']);
  89. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  90. $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
  91. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
  92. }
  93. public function testInstagramPhotoWithPersonTag() {
  94. // Original URL: https://www.instagram.com/p/BNfqVfVlmkj/
  95. $url = 'https://www.instagram.com/p/BNfqVfVlmkj/';
  96. $response = $this->parse(['url' => $url]);
  97. $body = $response->getContent();
  98. $this->assertEquals(200, $response->getStatusCode());
  99. $data = json_decode($body, true);
  100. $this->assertEquals(200, $data['code']);
  101. $this->assertEquals('instagram', $data['source-format']);
  102. $this->assertEquals(2, count($data['data']['category']));
  103. $this->assertEquals(['type'=>'card','name'=>'KmikeyM™️','url'=>'https://kmikeym.com/','photo'=>'https://instagram.fsjc1-3.fna.fbcdn.net/vp/ea5b988b616dbcc778b3013bf2426d70/5CCAC7FC/t51.2885-19/s320x320/20634957_814691788710973_2275383796935163904_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net','note'=>"The world’s first publicly traded person.\n\nAcct in collaboration with @norbertoinc\n\nBecome a shareholder today!\n"], $data['data']['refs']['https://kmikeym.com/']);
  104. $this->assertContains('https://kmikeym.com/', $data['data']['category']);
  105. $this->assertArrayHasKey('https://kmikeym.com/', $data['data']['refs']);
  106. }
  107. public function testInstagramPhotoWithVenue() {
  108. // Original URL: https://www.instagram.com/p/BN3Z5salSys/
  109. $url = 'https://www.instagram.com/p/BN3Z5salSys/';
  110. $response = $this->parse(['url' => $url]);
  111. $body = $response->getContent();
  112. $this->assertEquals(200, $response->getStatusCode());
  113. $data = json_decode($body, true);
  114. $this->assertEquals(200, $data['code']);
  115. $this->assertEquals('instagram', $data['source-format']);
  116. $this->assertEquals(1, count($data['data']['location']));
  117. $this->assertContains('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['location']);
  118. $this->assertArrayHasKey('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['refs']);
  119. $venue = $data['data']['refs']['https://www.instagram.com/explore/locations/109284789535230/'];
  120. $this->assertEquals('XOXO Outpost', $venue['name']);
  121. $this->assertEquals('45.5261002', $venue['latitude']);
  122. $this->assertEquals('-122.6558081', $venue['longitude']);
  123. // Setting a venue should set the timezone
  124. $this->assertEquals('2016-12-10T21:48:56-08:00', $data['data']['published']);
  125. }
  126. public function testTwoPhotos() {
  127. // Original URL: https://www.instagram.com/p/BZWmUB_DVtp/
  128. $url = 'https://www.instagram.com/p/BZWmUB_DVtp/';
  129. $response = $this->parse(['url' => $url]);
  130. $body = $response->getContent();
  131. $this->assertEquals(200, $response->getStatusCode());
  132. $data = json_decode($body, true);
  133. $this->assertEquals(200, $data['code']);
  134. $this->assertEquals('instagram', $data['source-format']);
  135. $this->assertEquals(2, count($data['data']['photo']));
  136. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/6b09c3d5490ee3efb55849858a9ec014/5CBFBC38/t51.2885-15/e35/21827424_134752690591737_8093088291252862976_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['photo'][0]);
  137. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/8b1b2e6efa86a4856ec37a60f0fa77f5/5CC2D34D/t51.2885-15/e35/21909774_347707439021016_5237540582556958720_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['photo'][1]);
  138. $this->assertArrayNotHasKey('video', $data['data']);
  139. $this->assertEquals(2, count($data['data']['category']));
  140. $this->assertArrayNotHasKey('meta', $data['data']);
  141. }
  142. public function testMixPhotosAndVideos() {
  143. // Original URL: https://www.instagram.com/p/BZWmpecjBwN/
  144. $url = 'https://www.instagram.com/p/BZWmpecjBwN/';
  145. $response = $this->parse(['url' => $url]);
  146. $body = $response->getContent();
  147. $this->assertEquals(200, $response->getStatusCode());
  148. $data = json_decode($body, true);
  149. $this->assertEquals(200, $data['code']);
  150. $this->assertEquals('instagram', $data['source-format']);
  151. $this->assertEquals('photo', $data['data']['post-type']); // we discard videos in this case right now
  152. $this->assertEquals(3, count($data['data']['photo']));
  153. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/ee1a28763918069f3e54dad35be24ad8/5CCFBAB8/t51.2885-15/e35/21878922_686481254874005_8468823712617988096_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['photo'][0]);
  154. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/ddc0ebe969bb1f9e6bf8adada0892c90/5C39EBC9/t51.2885-15/e15/21910026_1507234999368159_6974261907783942144_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['photo'][1]);
  155. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/bfe032af795427443ea448840df1c3a4/5CCC8C88/t51.2885-15/e35/21878800_273567963151023_7672178549897297920_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['photo'][2]);
  156. $this->assertArrayNotHasKey('video', $data['data']);
  157. $this->assertEquals(2, count($data['data']['category']));
  158. }
  159. public function testInstagramProfile() {
  160. $url = 'https://www.instagram.com/aaronpk/';
  161. $response = $this->parse(['url' => $url]);
  162. $body = $response->getContent();
  163. $this->assertEquals(200, $response->getStatusCode());
  164. $data = json_decode($body, true);
  165. $this->assertEquals(200, $data['code']);
  166. $this->assertEquals('instagram', $data['source-format']);
  167. $this->assertSame([
  168. 'type' => 'card',
  169. 'name' => 'Aaron Parecki',
  170. 'url' => 'https://aaronparecki.com/',
  171. 'photo' => 'https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net',
  172. 'note' => '🔒 oauth.net 🎥 backpedal.tv 🎙 streampdx.com 📡 w7apk.com'
  173. ], $data['data']);
  174. }
  175. public function testInstagramProfileWithBio() {
  176. $url = 'https://www.instagram.com/pk_spam/';
  177. $response = $this->parse(['url' => $url]);
  178. $body = $response->getContent();
  179. $this->assertEquals(200, $response->getStatusCode());
  180. $data = json_decode($body, true);
  181. $this->assertEquals(200, $data['code']);
  182. $this->assertEquals('instagram', $data['source-format']);
  183. $this->assertSame([
  184. 'type' => 'card',
  185. 'name' => 'pk_spam',
  186. 'url' => 'https://aaronparecki.com/',
  187. 'photo' => 'https://scontent-frx5-1.cdninstagram.com/vp/74112f515c64726429c69fedcb927c2d/5CB64CF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-frx5-1.cdninstagram.com',
  188. 'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/'
  189. ], $data['data']);
  190. }
  191. public function testInstagramProfileFeed() {
  192. $url = 'https://www.instagram.com/pk_spam/';
  193. $response = $this->parse(['url' => $url, 'expect' => 'feed']);
  194. $body = $response->getContent();
  195. $this->assertEquals(200, $response->getStatusCode());
  196. $data = json_decode($body, true);
  197. $this->assertEquals(200, $data['code']);
  198. $this->assertEquals('instagram', $data['source-format']);
  199. $this->assertEquals('feed', $data['data']['type']);
  200. $this->assertEquals(12, count($data['data']['items']));
  201. $this->assertEquals('https://www.instagram.com/p/BsdlOmLh_IX/', $data['data']['items'][0]['url']);
  202. $this->assertEquals('https://www.instagram.com/p/BGFdtAViMJy/', $data['data']['items'][11]['url']);
  203. }
  204. public function testInstagramPhotoWithAltText() {
  205. $url = 'https://www.instagram.com/p/BsdjKytBZyx/';
  206. $response = $this->parse(['url' => $url]);
  207. $body = $response->getContent();
  208. $this->assertEquals(200, $response->getStatusCode());
  209. $data = json_decode($body, true);
  210. $this->assertEquals(200, $data['code']);
  211. $this->assertEquals('instagram', $data['source-format']);
  212. $this->assertEquals('Pink text on a white background that says "Photo with alt text"', $data['data']['meta']['https://instagram.fsjc1-3.fna.fbcdn.net/vp/a7e61adf3d84f07863ffdb99f0fdcc86/5CD9B7F3/t51.2885-15/e35/47692478_2276538359047529_8318084305806697090_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net']['alt']);
  213. }
  214. public function testInstagramMultiPhotoWithAltText() {
  215. $url = 'https://www.instagram.com/p/BsdlOmLh_IX/';
  216. $response = $this->parse(['url' => $url]);
  217. $body = $response->getContent();
  218. $this->assertEquals(200, $response->getStatusCode());
  219. $data = json_decode($body, true);
  220. $this->assertEquals(200, $data['code']);
  221. $this->assertEquals('instagram', $data['source-format']);
  222. $this->assertEquals('A large pink "1" in a circle with a small green "2" behind it', $data['data']['meta']['https://instagram.fsjc1-3.fna.fbcdn.net/vp/90bf019b7396d7bc2b1ee02170902a2e/5CCC9B87/t51.2885-15/e35/47692921_321791688431421_3314633848293773579_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net']['alt']);
  223. $this->assertEquals('A large green "2" in a circle with a small pink "1" behind it', $data['data']['meta']['https://instagram.fsjc1-3.fna.fbcdn.net/vp/a6c93d8fcd5ad0e3b60f2ac0695eb34e/5CC3898E/t51.2885-15/e35/49663055_349750985612151_2949260446582336214_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net']['alt']);
  224. }
  225. public function testInstagramPhotoAutogeneratedAltText() {
  226. $url = 'https://www.instagram.com/p/Bq8U12UAcdq/';
  227. $response = $this->parse(['url' => $url]);
  228. $body = $response->getContent();
  229. $this->assertEquals(200, $response->getStatusCode());
  230. $data = json_decode($body, true);
  231. $this->assertEquals(200, $data['code']);
  232. $this->assertEquals('instagram', $data['source-format']);
  233. $this->assertEquals('Image may contain: one or more people and hat', $data['data']['meta']['https://instagram.fsjc1-3.fna.fbcdn.net/vp/7f8954f33de897c0c57656b798637f4c/5CC3DF9F/t51.2885-15/e35/45605085_1989380037822519_4707213851165118070_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net']['alt']);
  234. }
  235. }