[ 'headers' => ['Content-Type' => 'text/html; charset=utf-8'], 'rels' => [ 'hub' => ['https://hub.example/'], 'self' => ['https://example.com/'], ], ], ]); $client = new Client($http); $result = $client->discover('https://example.com/'); $this->assertSame([ 'hub' => 'https://hub.example/', 'hub_source' => 'http', 'self' => 'https://example.com/', 'self_source' => 'http', 'type' => 'html', ], $result); // Everything was in the HEAD response, so no GET is needed $this->assertCount(1, $http->requests); $this->assertSame('HEAD', $http->requests[0]['method']); } public function testFallsBackToGetWhenHeadHasNoLinks() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'text/html'], 'rels' => [ 'hub' => ['https://hub.example/'], 'self' => ['https://example.com/'], ], ], ]); $client = new Client($http); $result = $client->discover('https://example.com/'); $this->assertSame('https://hub.example/', $result['hub']); $this->assertSame('http', $result['hub_source']); $this->assertSame(['HEAD', 'GET'], array_column($http->requests, 'method')); } public function testSkipsHeadRequestWhenHeadfirstIsFalse() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'text/html'], 'rels' => [ 'hub' => ['https://hub.example/'], 'self' => ['https://example.com/'], ], ], ]); $client = new Client($http); $client->discover('https://example.com/', false); $this->assertSame(['GET'], array_column($http->requests, 'method')); } public function testDetectsRssFromHeadContentType() { $http = new FakeHTTP([ 'HEAD' => [ 'headers' => ['Content-Type' => 'application/rss+xml; charset=utf-8'], 'rels' => [ 'hub' => ['https://hub.example/'], 'self' => ['https://example.com/feed.rss'], ], ], ]); $client = new Client($http); $result = $client->discover('https://example.com/feed.rss'); $this->assertSame('rss', $result['type']); $this->assertCount(1, $http->requests); } public function testFindsLinksInAtomFeedBody() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'application/atom+xml'], 'body' => ' Example ', ], ]); $client = new Client($http); $result = $client->discover('https://example.com/feed.atom'); $this->assertSame([ 'hub' => 'https://hub.example/', 'hub_source' => 'body', 'self' => 'https://example.com/feed.atom', 'self_source' => 'body', 'type' => 'atom', ], $result); } public function testFindsAtomLinksInRssFeedBody() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'application/rss+xml'], 'body' => ' Example ', ], ]); $client = new Client($http); $result = $client->discover('https://example.com/feed.rss'); $this->assertSame('https://hub.example/', $result['hub']); $this->assertSame('https://example.com/feed.rss', $result['self']); $this->assertSame('body', $result['self_source']); $this->assertSame('rss', $result['type']); } public function testFindsLinkElementsInHtmlBody() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'text/html'], 'body' => ' Example ', ], ]); $client = new Client($http); $result = $client->discover('https://example.com/'); $this->assertSame('https://hub.example/', $result['hub']); $this->assertSame('body', $result['hub_source']); $this->assertSame('https://example.com/', $result['self']); $this->assertSame('html', $result['type']); } public function testLinkHeadersTakePriorityOverBody() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'application/atom+xml'], 'rels' => ['hub' => ['https://header-hub.example/']], 'body' => ' ', ], ]); $client = new Client($http); $result = $client->discover('https://example.com/feed.atom'); $this->assertSame('https://header-hub.example/', $result['hub']); $this->assertSame('http', $result['hub_source']); $this->assertSame('https://example.com/feed.atom', $result['self']); $this->assertSame('body', $result['self_source']); } public function testReturnsFalseWithoutHub() { $http = new FakeHTTP([ 'GET' => [ 'headers' => ['Content-Type' => 'text/html'], 'rels' => ['self' => ['https://example.com/']], ], ]); $client = new Client($http); $this->assertFalse($client->discover('https://example.com/')); } public function testVerboseIncludesDetails() { $http = new FakeHTTP([ 'HEAD' => [ 'headers' => ['Content-Type' => 'text/html'], 'rels' => [ 'hub' => ['https://hub.example/'], 'self' => ['https://example.com/'], ], ], ]); $client = new Client($http); $result = $client->discover('https://example.com/', true, true); $this->assertSame(['https://hub.example/'], $result['details']['http']['hub']); $this->assertSame([], $result['details']['body']['hub']); } }