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.

98 lines
5.0 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 = 'http://www.instagram.com/photo.html';
  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('2017-01-05T23:31:32+00:00', $data['data']['published']);
  25. $this->assertContains('planning', $data['data']['category']);
  26. $this->assertContains('2017', $data['data']['category']);
  27. $this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']);
  28. $this->assertEquals(1, count($data['data']['photo']));
  29. $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/t51.2885-15/e35/15803256_1832278043695907_4846092951052353536_n.jpg'], $data['data']['photo']);
  30. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  31. $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
  32. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg', $data['data']['author']['photo']);
  33. }
  34. public function testInstagramVideo() {
  35. // Original URL: https://www.instagram.com/p/BO_RN8AFZSx/
  36. $url = 'http://www.instagram.com/video.html';
  37. $response = $this->parse(['url' => $url]);
  38. $body = $response->getContent();
  39. $this->assertEquals(200, $response->getStatusCode());
  40. $data = json_decode($body, true);
  41. $this->assertEquals('entry', $data['data']['type']);
  42. $this->assertContains('100daysofmusic', $data['data']['category']);
  43. $this->assertEquals('Day 18. Maple and Spruce #100daysofmusic #100daysproject #the100dayproject https://aaronparecki.com/2017/01/07/14/day18', $data['data']['content']['text']);
  44. $this->assertEquals(1, count($data['data']['photo']));
  45. $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/t51.2885-15/s640x640/e15/15624670_548881701986735_8264383763249627136_n.jpg'], $data['data']['photo']);
  46. $this->assertEquals(1, count($data['data']['video']));
  47. $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/t50.2886-16/15921147_1074837002642259_2269307616507199488_n.mp4'], $data['data']['video']);
  48. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  49. $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
  50. $this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg', $data['data']['author']['photo']);
  51. }
  52. public function testInstagramPhotoWithPersonTag() {
  53. // Original URL: https://www.instagram.com/p/BNfqVfVlmkj/
  54. $url = 'http://www.instagram.com/photo_with_person_tag.html';
  55. $response = $this->parse(['url' => $url]);
  56. $body = $response->getContent();
  57. $this->assertEquals(200, $response->getStatusCode());
  58. $data = json_decode($body, true);
  59. $this->assertEquals(2, count($data['data']['category']));
  60. $this->assertContains('http://tinyletter.com/kmikeym', $data['data']['category']);
  61. $this->assertArrayHasKey('http://tinyletter.com/kmikeym', $data['data']['refs']);
  62. $this->assertEquals(['type'=>'card','name'=>'Mike Merrill','url'=>'http://tinyletter.com/kmikeym','photo'=>'https://instagram.fsjc1-3.fna.fbcdn.net/t51.2885-19/s320x320/12627953_686238411518831_1544976311_a.jpg'], $data['data']['refs']['http://tinyletter.com/kmikeym']);
  63. }
  64. public function testInstagramPhotoWithVenue() {
  65. // Original URL: https://www.instagram.com/p/BN3Z5salSys/
  66. $url = 'http://www.instagram.com/photo_with_venue.html';
  67. $response = $this->parse(['url' => $url]);
  68. $body = $response->getContent();
  69. $this->assertEquals(200, $response->getStatusCode());
  70. $data = json_decode($body, true);
  71. $this->assertEquals(1, count($data['data']['location']));
  72. $this->assertContains('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['location']);
  73. $this->assertArrayHasKey('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['refs']);
  74. $venue = $data['data']['refs']['https://www.instagram.com/explore/locations/109284789535230/'];
  75. $this->assertEquals('XOXO Outpost', $venue['name']);
  76. $this->assertEquals('45.5261002', $venue['latitude']);
  77. $this->assertEquals('-122.6558081', $venue['longitude']);
  78. // Setting a venue should set the timezone
  79. $this->assertEquals('2016-12-10T21:48:56-08:00', $data['data']['published']);
  80. }
  81. }