From f0427f03bde2846e544565571e10542ea7426c4f Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 7 Mar 2020 21:42:45 +0100 Subject: Support multiple hub links for WebSub --- tests/HubUrlExtractorTest.php | 91 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 6 deletions(-) (limited to 'tests/HubUrlExtractorTest.php') diff --git a/tests/HubUrlExtractorTest.php b/tests/HubUrlExtractorTest.php index 418185e..2018467 100644 --- a/tests/HubUrlExtractorTest.php +++ b/tests/HubUrlExtractorTest.php @@ -21,7 +21,40 @@ class HubUrlExtractorTest extends \PHPUnit\Framework\TestCase $this->assertEquals( [ - 'hub' => 'https://hub.example.com/', + 'hub' => ['https://hub.example.com/'], + 'self' => 'http://example.com/feed', + ], + $extractor->getUrls('http://example.org/') + ); + } + + public function testGetUrlsMultipleHubsHEAD() + { + $mock = new HTTP_Request2_Adapter_Mock(); + $this->addResponse( + $mock, + "HTTP/1.0 200 OK\r\n" + . "Content-type: text/html\r\n" + . "Link: ; rel=\"hub\"\r\n" + . "Link: ; rel=\"hub\"\r\n" + . "Link: ; rel=\"self\"\r\n" + . "Link: ; rel=\"hub\"\r\n" + . "\r\n", + 'http://example.org/' + ); + + $extractor = new phinde\HubUrlExtractor(); + $extractor->setRequestTemplate( + new HTTP_Request2(null, null, ['adapter' => $mock]) + ); + + $this->assertEquals( + [ + 'hub' => [ + 'https://hub.example.com/', + 'https://hub2.example.com/', + 'https://hub3.example.com/', + ], 'self' => 'http://example.com/feed', ], $extractor->getUrls('http://example.org/') @@ -63,7 +96,53 @@ HTM, $this->assertEquals( [ - 'hub' => 'https://hub.example.com/', + 'hub' => ['https://hub.example.com/'], + 'self' => 'http://example.com/feed', + ], + $extractor->getUrls('http://example.org/') + ); + } + + public function testGetUrlsHtmlMultipleHubs() + { + $mock = new HTTP_Request2_Adapter_Mock(); + //HEAD + $this->addResponse( + $mock, + "HTTP/1.0 200 OK\r\n" + . "Content-type: text/html\r\n" + . "\r\n", + 'http://example.org/' + ); + //HEAD + $this->addResponse( + $mock, + "HTTP/1.0 200 OK\r\n" + . "Content-type: text/html\r\n" + . "\r\n" + . << + + + + + + +HTM, + 'http://example.org/' + ); + + $extractor = new phinde\HubUrlExtractor(); + $extractor->setRequestTemplate( + new HTTP_Request2(null, null, ['adapter' => $mock]) + ); + + $this->assertEquals( + [ + 'hub' => [ + 'https://hub.example.com/', + 'https://hub2.example.com/', + ], 'self' => 'http://example.com/feed', ], $extractor->getUrls('http://example.org/') @@ -105,7 +184,7 @@ HTM, $this->assertEquals( [ - 'hub' => 'https://hub.example.com/', + 'hub' => ['https://hub.example.com/'], 'self' => 'http://example.com/feed', ], $extractor->getUrls('http://example.org/') @@ -147,7 +226,7 @@ HTM, $this->assertEquals( [ - 'hub' => 'https://hub.example.com/', + 'hub' => ['https://hub.example.com/'], 'self' => 'http://example.com/feed', ], $extractor->getUrls('http://example.org/') @@ -191,7 +270,7 @@ HTM, $this->assertEquals( [ - 'hub' => 'https://hub.example.com/', + 'hub' => ['https://hub.example.com/'], 'self' => 'http://example.com/feed', ], $extractor->getUrls('http://example.org/') @@ -235,7 +314,7 @@ HTM, $this->assertEquals( [ - 'hub' => 'https://hub.example.com/', + 'hub' => ['https://hub.example.com/'], 'self' => 'http://example.com/feed', ], $extractor->getUrls('http://example.org/') -- cgit v1.2.3