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.

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