[
'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' => '