client = new Parse(); $this->client->http = new p3k\HTTPTest(dirname(__FILE__).'/data/'); $this->client->mc = null; } private function parse($params) { $request = new Request($params); $response = new Response(); return $this->client->parse($request, $response); } public function testMissingURL() { $response = $this->parse([]); $body = $response->getContent(); $this->assertEquals(400, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectHasAttribute('error', $data); $this->assertEquals('missing_url', $data->error); } public function testInvalidURL() { $url = 'ftp://example.com/foo'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(400, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectHasAttribute('error', $data); $this->assertEquals('invalid_url', $data->error); } public function testTargetNotFound() { $url = 'http://source.example.com/basictest'; $response = $this->parse(['url' => $url, 'target' => 'http://example.net']); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectHasAttribute('error', $data); $this->assertEquals('no_link_found', $data->error); } public function testTargetFound() { $url = 'http://source.example.com/basictest'; $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com']); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('error', $data); $this->assertObjectNotHasAttribute('error', $data); } public function testHTMLContent() { $url = 'http://source.example.com/html-content'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('name', $data->data); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->html); } public function testFindTargetLinkIsImage() { $url = 'http://source.example.com/link-is-img'; $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/photo.jpg']); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('name', $data->data); $this->assertEquals('This page has an img tag with the target URL.', $data->data->content->text); } public function testFindTargetLinkIsVideo() { $url = 'http://source.example.com/link-is-video'; $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/movie.mp4']); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('name', $data->data); $this->assertEquals('This page has a video tag with the target URL.', $data->data->content->text); } public function testFindTargetLinkIsAudio() { $url = 'http://source.example.com/link-is-audio'; $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/media.mp3']); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('name', $data->data); $this->assertEquals('This page has an audio tag with the target URL.', $data->data->content->text); } public function testTextContent() { $url = 'http://source.example.com/text-content'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('name', $data->data); $this->assertEquals('This page has a link to target.example.com and some formatted text but is in a p-content element so is plaintext.', $data->data->content->text); } public function testContentWithPrefixedName() { $url = 'http://source.example.com/content-with-prefixed-name'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertObjectNotHasAttribute('name', $data->data); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->html); } public function testContentWithDistinctName() { $url = 'http://source.example.com/content-with-distinct-name'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertEquals('Hello World', $data->data->name); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->html); } public function testNameWithNoContent() { $url = 'http://source.example.com/name-no-content'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertEquals('Hello World', $data->data->name); $this->assertObjectNotHasAttribute('content', $data->data); } public function testNoHEntryMarkup() { $url = 'http://source.example.com/no-h-entry'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body); $this->assertEquals('unknown', $data->data->type); } public function testReplyIsURL() { $url = 'http://source.example.com/reply-is-url'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]); } public function testReplyIsHCite() { $url = 'http://source.example.com/reply-is-h-cite'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]); $this->assertArrayHasKey('http://example.com/100', $data['refs']); $this->assertEquals('Example Post', $data['refs']['http://example.com/100']['name']); $this->assertEquals('http://example.com/100', $data['refs']['http://example.com/100']['url']); } public function testPersonTagIsURL() { $url = 'http://source.example.com/person-tag-is-url'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://alice.example.com/', $data['data']['category'][0]); } public function testPersonTagIsHCard() { $url = 'http://source.example.com/person-tag-is-h-card'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://alice.example.com/', $data['data']['category'][0]); $this->assertArrayHasKey('http://alice.example.com/', $data['refs']); $this->assertEquals('card', $data['refs']['http://alice.example.com/']['type']); $this->assertEquals('http://alice.example.com/', $data['refs']['http://alice.example.com/']['url']); $this->assertEquals('Alice', $data['refs']['http://alice.example.com/']['name']); } public function testHEntryIsNotFirstObject() { $url = 'http://source.example.com/h-entry-is-not-first'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('Hello World', $data['data']['content']['text']); } public function testHEntryRSVP() { $url = 'http://source.example.com/h-entry-rsvp'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('I\'ll be there!', $data['data']['name']); $this->assertEquals('yes', $data['data']['rsvp']); } public function testMultipleHEntryOnPermalink() { $url = 'http://source.example.com/multiple-h-entry-on-permalink'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('Primary Post', $data['data']['name']); } public function testHEntryWithHCardSibling() { $url = 'http://source.example.com/h-entry-with-h-card-sibling'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('Hello World', $data['data']['content']['text']); } public function testHEntryRedirectWithHCardSibling() { $url = 'http://source.example.com/h-entry-redirect-with-h-card-sibling'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('Hello World', $data['data']['content']['text']); } public function testSingleHEntryHasNoPermalink() { $url = 'http://source.example.com/single-h-entry-has-no-permalink'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('Hello World', $data['data']['content']['text']); } public function testBridgyExampleWithNoMatchingURL() { $url = 'http://source.example.com/bridgy-example'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); } public function testEventWithHTMLDescription() { $url = 'http://source.example.com/h-event'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('event', $data['data']['type']); $this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals($url, $data['data']['url']); $this->assertEquals('2016-03-09T18:30', $data['data']['start']); $this->assertEquals('2016-03-09T19:30', $data['data']['end']); $this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['description']['text']); $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['description']['text']); $this->assertStringStartsWith("
Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...
", $data['data']['description']['html']); $this->assertStringEndsWith('See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.
', $data['data']['description']['html']); } public function testEventWithTextDescription() { $url = 'http://source.example.com/h-event-text-description'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('event', $data['data']['type']); $this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals($url, $data['data']['url']); $this->assertEquals('2016-03-09T18:30', $data['data']['start']); $this->assertEquals('2016-03-09T19:30', $data['data']['end']); $this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['description']['text']); $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['description']['text']); $this->assertArrayNotHasKey('html', $data['data']['description']); } public function testEventWithHCardLocation() { $url = 'http://source.example.com/h-event-with-h-card-location'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('event', $data['data']['type']); $this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals($url, $data['data']['url']); $this->assertEquals('2016-02-09T18:30', $data['data']['start']); $this->assertEquals('2016-02-09T19:30', $data['data']['end']); $this->assertArrayHasKey('http://source.example.com/venue', $data['refs']); $this->assertEquals('card', $data['refs']['http://source.example.com/venue']['type']); $this->assertEquals('http://source.example.com/venue', $data['refs']['http://source.example.com/venue']['url']); $this->assertEquals('Venue', $data['refs']['http://source.example.com/venue']['name']); } public function testEntryIsAnInvitee() { $url = 'http://source.example.com/bridgy-invitee'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('https://www.facebook.com/555707837940351#tantek', $data['data']['url']); $this->assertContains('https://www.facebook.com/tantek.celik', $data['data']['invitee']); $this->assertArrayHasKey('https://www.facebook.com/tantek.celik', $data['refs']); $this->assertEquals('Tantek Çelik', $data['refs']['https://www.facebook.com/tantek.celik']['name']); } public function testEntryAtFragmentID() { $url = 'http://source.example.com/fragment-id#comment-1000'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://source.example.com/fragment-id#comment-1000', $data['data']['url']); $this->assertTrue($data['info']['found_fragment']); } public function testEntryAtNonExistentFragmentID() { $url = 'http://source.example.com/fragment-id#comment-404'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://source.example.com/fragment-id', $data['data']['url']); $this->assertFalse($data['info']['found_fragment']); } public function testInstagramPhoto() { $url = 'http://www.instagram.com/photo.html'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertContains('planning', $data['data']['category']); $this->assertContains('2017', $data['data']['category']); $this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']); $this->assertEquals(1, count($data['data']['photo'])); $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']); $this->assertEquals('http://aaronparecki.com/', $data['data']['author']['url']); $this->assertEquals('Aaron Parecki', $data['data']['author']['name']); $this->assertEquals('https://scontent.cdninstagram.com/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg', $data['data']['author']['photo']); } public function testInstagramVideo() { $url = 'http://www.instagram.com/video.html'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); $this->assertContains('100daysofmusic', $data['data']['category']); $this->assertEquals('Day 18. Maple and Spruce #100daysofmusic #100daysproject #the100dayproject https://aaronparecki.com/2017/01/07/14/day18', $data['data']['content']['text']); $this->assertEquals(1, count($data['data']['photo'])); $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']); $this->assertEquals(1, count($data['data']['video'])); $this->assertEquals(['https://scontent.cdninstagram.com/t50.2886-16/15921147_1074837002642259_2269307616507199488_n.mp4'], $data['data']['video']); $this->assertEquals('http://aaronparecki.com/', $data['data']['author']['url']); $this->assertEquals('Aaron Parecki', $data['data']['author']['name']); $this->assertEquals('https://scontent.cdninstagram.com/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg', $data['data']['author']['photo']); } public function testInstagramPhotoWithPersonTag() { $url = 'http://www.instagram.com/photo_with_person_tag.html'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals(2, count($data['data']['category'])); $this->assertContains('https://kmikeym.com/', $data['data']['category']); $this->assertArrayHasKey('https://kmikeym.com/', $data['refs']); $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/']); } public function testInstagramPhotoWithVenue() { $url = 'http://www.instagram.com/photo_with_venue.html'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals(1, count($data['data']['location'])); $this->assertContains('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['location']); $this->assertArrayHasKey('https://www.instagram.com/explore/locations/109284789535230/', $data['refs']); $venue = $data['refs']['https://www.instagram.com/explore/locations/109284789535230/']; $this->assertEquals('XOXO Outpost', $venue['name']); $this->assertEquals('45.5261002', $venue['latitude']); $this->assertEquals('-122.6558081', $venue['longitude']); } }