2 class HubUrlExtractorTest extends \PHPUnit\Framework\TestCase
4 public function testGetUrlsHEAD()
6 $mock = new HTTP_Request2_Adapter_Mock();
10 . "Content-type: text/html\r\n"
11 . "Link: <https://hub.example.com/>; rel=\"hub\"\r\n"
12 . "Link: <http://example.com/feed>; rel=\"self\"\r\n"
17 $extractor = new phinde\HubUrlExtractor();
18 $extractor->setRequestTemplate(
19 new HTTP_Request2(null, null, ['adapter' => $mock])
24 'hub' => 'https://hub.example.com/',
25 'self' => 'http://example.com/feed',
27 $extractor->getUrls('http://example.org/')
31 public function testGetUrlsHtml()
33 $mock = new HTTP_Request2_Adapter_Mock();
38 . "Content-type: text/html\r\n"
46 . "Content-type: text/html\r\n"
51 <link rel='hub' href='https://hub.example.com/'/>
52 <link rel='self' href='http://example.com/feed'/>
59 $extractor = new phinde\HubUrlExtractor();
60 $extractor->setRequestTemplate(
61 new HTTP_Request2(null, null, ['adapter' => $mock])
66 'hub' => 'https://hub.example.com/',
67 'self' => 'http://example.com/feed',
69 $extractor->getUrls('http://example.org/')
73 public function testGetUrlsXHtml()
75 $mock = new HTTP_Request2_Adapter_Mock();
80 . "Content-type: application/xhtml+xml\r\n"
88 . "Content-type: application/xhtml+xml\r\n"
93 <link rel='hub' href='https://hub.example.com/'/>
94 <link rel='self' href='http://example.com/feed'/>
101 $extractor = new phinde\HubUrlExtractor();
102 $extractor->setRequestTemplate(
103 new HTTP_Request2(null, null, ['adapter' => $mock])
108 'hub' => 'https://hub.example.com/',
109 'self' => 'http://example.com/feed',
111 $extractor->getUrls('http://example.org/')
115 public function testGetUrlsAtom()
117 $mock = new HTTP_Request2_Adapter_Mock();
121 "HTTP/1.0 200 OK\r\n"
122 . "Content-type: application/atom+xml\r\n"
124 'http://example.org/'
129 "HTTP/1.0 200 OK\r\n"
130 . "Content-type: application/atom+xml\r\n"
133 <?xml version="1.0" encoding="utf-8"?>
134 <feed xmlns="http://www.w3.org/2005/Atom">
135 <link href="http://example.org/"/>
136 <link rel="self" href="http://example.com/feed"/>
137 <link rel="hub" href="https://hub.example.com/"/>
140 'http://example.org/'
143 $extractor = new phinde\HubUrlExtractor();
144 $extractor->setRequestTemplate(
145 new HTTP_Request2(null, null, ['adapter' => $mock])
150 'hub' => 'https://hub.example.com/',
151 'self' => 'http://example.com/feed',
153 $extractor->getUrls('http://example.org/')
157 public function testGetUrlsRss2()
159 $mock = new HTTP_Request2_Adapter_Mock();
163 "HTTP/1.0 200 OK\r\n"
164 . "Content-type: application/rss+xml\r\n"
166 'http://example.org/'
171 "HTTP/1.0 200 OK\r\n"
172 . "Content-type: application/rss+xml\r\n"
175 <?xml version="1.0" encoding="utf-8"?>
178 <link>http://www.example.com/main.html</link>
179 <link rel="self" href="http://example.com/feed"/>
180 <link rel="hub" href="https://hub.example.com/"/>
184 'http://example.org/'
187 $extractor = new phinde\HubUrlExtractor();
188 $extractor->setRequestTemplate(
189 new HTTP_Request2(null, null, ['adapter' => $mock])
194 'hub' => 'https://hub.example.com/',
195 'self' => 'http://example.com/feed',
197 $extractor->getUrls('http://example.org/')
201 protected function addResponse($mock, $responseContent, $effectiveUrl)
204 static::createResponseFromString($responseContent, $effectiveUrl)
208 public static function createResponseFromString($str, $effectiveUrl)
210 $parts = preg_split('!(\r?\n){2}!m', $str, 2);
211 $headerLines = explode("\n", $parts[0]);
212 $response = new HTTP_Request2_Response(
213 array_shift($headerLines), true, $effectiveUrl
215 foreach ($headerLines as $headerLine) {
216 $response->parseHeaderLine($headerLine);
218 $response->parseHeaderLine('');
219 if (isset($parts[1])) {
220 $response->appendBody($parts[1]);