diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2020-03-07 22:26:59 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2020-03-07 22:26:59 +0100 |
| commit | eca6e9af6dea38f5912c881a5dc05193e1b19848 (patch) | |
| tree | 6db03321e333cc48022d76814728ed5f99269066 /tests/HubUrlExtractorTest.php | |
| parent | f0427f03bde2846e544565571e10542ea7426c4f (diff) | |
| download | phinde-eca6e9af6dea38f5912c881a5dc05193e1b19848.tar.gz phinde-eca6e9af6dea38f5912c881a5dc05193e1b19848.zip | |
Support subscriptions to redirect URLs
Resolves: https://github.com/cweiske/phinde/issues/37
Diffstat (limited to 'tests/HubUrlExtractorTest.php')
| -rw-r--r-- | tests/HubUrlExtractorTest.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/HubUrlExtractorTest.php b/tests/HubUrlExtractorTest.php index 2018467..a4d4651 100644 --- a/tests/HubUrlExtractorTest.php +++ b/tests/HubUrlExtractorTest.php @@ -344,5 +344,82 @@ HTM, } return $response; } + + /** + * It is possible to subscribe to URLs that redirect if + * they have a hub and self links in the HTTP headers. + * If they don't, we need to follow the redirect. + */ + public function testGetUrlsHEADLinksForRedirect() + { + $mock = new HTTP_Request2_Adapter_Mock(); + $this->addResponse( + $mock, + "HTTP/1.0 307 Temporary Redirect\r\n" + . "Content-type: text/html\r\n" + . "Location: http://example.org/redir-target\r\n" + . "Link: <https://hub.example.com/>; rel=\"hub\"\r\n" + . "Link: <http://example.com/feed>; rel=\"self\"\r\n" + . "\r\n", + 'http://example.org/' + ); + $this->addResponse( + $mock, + "HTTP/1.0 200 OK\r\n" + . "Content-type: text/html\r\n" + . "Link: <https://redir-hub.example.com/>; rel=\"hub\"\r\n" + . "Link: <http://example.com/redir-feed>; rel=\"self\"\r\n" + . "\r\n", + 'http://example.org/redir-target' + ); + + $extractor = new phinde\HubUrlExtractor(); + $extractor->setRequestTemplate( + new HTTP_Request2(null, null, ['adapter' => $mock]) + ); + + $this->assertEquals( + [ + 'hub' => ['https://hub.example.com/'], + 'self' => 'http://example.com/feed', + ], + $extractor->getUrls('http://example.org/') + ); + } + + public function testGetUrlsHEADLinksForRedirectNone() + { + $mock = new HTTP_Request2_Adapter_Mock(); + $this->addResponse( + $mock, + "HTTP/1.0 307 Temporary Redirect\r\n" + . "Content-type: text/html\r\n" + . "Location: http://example.org/redir-target\r\n" + . "\r\n", + 'http://example.org/' + ); + $this->addResponse( + $mock, + "HTTP/1.0 200 OK\r\n" + . "Content-type: text/html\r\n" + . "Link: <https://redir-hub.example.com/>; rel=\"hub\"\r\n" + . "Link: <http://example.com/redir-feed>; rel=\"self\"\r\n" + . "\r\n", + 'http://example.org/redir-target' + ); + + $extractor = new phinde\HubUrlExtractor(); + $extractor->setRequestTemplate( + new HTTP_Request2(null, null, ['adapter' => $mock]) + ); + + $this->assertEquals( + [ + 'hub' => ['https://redir-hub.example.com/'], + 'self' => 'http://example.com/redir-feed', + ], + $extractor->getUrls('http://example.org/') + ); + } } ?> |
