|
2 | 2 |
|
3 | 3 | namespace Mf2\Parser\Test; |
4 | 4 |
|
| 5 | +use donatj\MockWebServer\MockWebServer; |
| 6 | +use donatj\MockWebServer\Response as MockWebServerResponse; |
5 | 7 | use Mf2\Parser; |
6 | 8 | use Mf2; |
7 | 9 | use Yoast\PHPUnitPolyfills\TestCases\TestCase; |
@@ -266,16 +268,30 @@ public function testParsesNestedMicroformatsWithClassnamesInAnyOrder() { |
266 | 268 | $this->assertEquals('Name', $output['items'][0]['properties']['in-reply-to'][0]['properties']['name'][0]); |
267 | 269 | } |
268 | 270 |
|
269 | | - /** |
270 | | - * @group internet |
271 | | - */ |
272 | 271 | public function testFetchMicroformats() { |
273 | | - $mf = Mf2\fetch('http://waterpigs.co.uk/'); |
| 272 | + $server = new MockWebServer(); |
| 273 | + $server->start(); |
| 274 | + |
| 275 | + // Obtained from http://waterpigs.co.uk/ |
| 276 | + $indexUrl = $server->setResponseOfPath( |
| 277 | + '/', |
| 278 | + new MockWebServerResponse(file_get_contents(__DIR__ . '/waterpigs.co.uk_index.html'), [], 200) |
| 279 | + ); |
| 280 | + |
| 281 | + // Obtained from http://waterpigs.co.uk/photo.jpg |
| 282 | + $photoUrl = $server->setResponseOfPath( |
| 283 | + '/photo.jpg', |
| 284 | + new MockWebServerResponse(file_get_contents(__DIR__ . '/waterpigs.co.uk_photo.jpg'), ['content-type: image/jpeg'], 200) |
| 285 | + ); |
| 286 | + |
| 287 | + $mf = Mf2\fetch($indexUrl); |
274 | 288 | $this->assertArrayHasKey('items', $mf); |
275 | 289 |
|
276 | | - $mf = Mf2\fetch('http://waterpigs.co.uk/photo.jpg', null, $curlInfo); |
| 290 | + $mf = Mf2\fetch($photoUrl, null, $curlInfo); |
277 | 291 | $this->assertNull($mf); |
278 | 292 | $this->assertStringContainsString('jpeg', $curlInfo['content_type']); |
| 293 | + |
| 294 | + $server->stop(); |
279 | 295 | } |
280 | 296 |
|
281 | 297 | /** |
@@ -381,22 +397,27 @@ public function testApplyTransformationToSrcset() { |
381 | 397 |
|
382 | 398 | /** |
383 | 399 | * @see https://github.com/indieweb/php-mf2/issues/84 |
384 | | - * @group internet |
385 | | - * |
386 | | - * 2024-04-07: The final photo URL in this test changed over time. |
387 | | - * Updated it to only check that the final URL's hostname was correct, |
388 | | - * not the full photo URL. |
389 | 400 | */ |
390 | 401 | public function testRelativeURLResolvedWithFinalURL() { |
391 | | - $mf = Mf2\fetch('http://aaron.pk/4Zn5'); |
| 402 | + $server = new MockWebServer(); |
| 403 | + $server->start(); |
| 404 | + |
| 405 | + // Obtained from http://aaron.pk/4Zn5 |
| 406 | + $url = $server->setResponseOfPath( |
| 407 | + '/4Zn5', |
| 408 | + new MockWebServerResponse(file_get_contents(__DIR__ . '/aaron.pk_4Zn5.html'), [], 200) |
| 409 | + ); |
| 410 | + |
| 411 | + $mf = Mf2\fetch($url); |
| 412 | + |
| 413 | + $server->stop(); |
392 | 414 |
|
393 | 415 | $this->assertArrayHasKey('photo', $mf['items'][0]['properties']); |
394 | 416 |
|
395 | 417 | $hostname = parse_url($mf['items'][0]['properties']['photo'][0], PHP_URL_HOST); |
396 | | - $this->assertEquals('aaronparecki.com', $hostname); |
| 418 | + $this->assertEquals('127.0.0.1', $hostname); |
397 | 419 |
|
398 | | - // previous assertion: not the photo URL changed over time |
399 | | - // $this->assertEquals('https://aaronparecki.com/img/1240x0/2014/12/23/5/photo.jpeg', $mf['items'][0]['properties']['photo'][0]); |
| 420 | + $this->assertEquals($server->getServerRoot() . '/img/1240x,q60/2014/12/23/5/photo.jpeg', $mf['items'][0]['properties']['photo'][0]); |
400 | 421 | } |
401 | 422 |
|
402 | 423 | public function testScriptTagContentsRemovedFromTextValue() { |
|
0 commit comments