|
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; |
@@ -270,12 +272,29 @@ public function testParsesNestedMicroformatsWithClassnamesInAnyOrder() { |
270 | 272 | * @group internet |
271 | 273 | */ |
272 | 274 | public function testFetchMicroformats() { |
273 | | - $mf = Mf2\fetch('http://waterpigs.co.uk/'); |
| 275 | + $server = new MockWebServer(); |
| 276 | + $server->start(); |
| 277 | + |
| 278 | + // Obtained from http://waterpigs.co.uk/ |
| 279 | + $indexUrl = $server->setResponseOfPath( |
| 280 | + '/', |
| 281 | + new MockWebServerResponse(file_get_contents(__DIR__ . '/waterpigs.co.uk_index.html'), [], 200) |
| 282 | + ); |
| 283 | + |
| 284 | + // Obtained from http://waterpigs.co.uk/photo.jpg |
| 285 | + $photoUrl = $server->setResponseOfPath( |
| 286 | + '/photo.jpg', |
| 287 | + new MockWebServerResponse(file_get_contents(__DIR__ . '/waterpigs.co.uk_photo.jpg'), ['content-type: image/jpeg'], 200) |
| 288 | + ); |
| 289 | + |
| 290 | + $mf = Mf2\fetch($indexUrl); |
274 | 291 | $this->assertArrayHasKey('items', $mf); |
275 | 292 |
|
276 | | - $mf = Mf2\fetch('http://waterpigs.co.uk/photo.jpg', null, $curlInfo); |
| 293 | + $mf = Mf2\fetch($photoUrl, null, $curlInfo); |
277 | 294 | $this->assertNull($mf); |
278 | 295 | $this->assertStringContainsString('jpeg', $curlInfo['content_type']); |
| 296 | + |
| 297 | + $server->stop(); |
279 | 298 | } |
280 | 299 |
|
281 | 300 | /** |
@@ -388,15 +407,25 @@ public function testApplyTransformationToSrcset() { |
388 | 407 | * not the full photo URL. |
389 | 408 | */ |
390 | 409 | public function testRelativeURLResolvedWithFinalURL() { |
391 | | - $mf = Mf2\fetch('http://aaron.pk/4Zn5'); |
| 410 | + $server = new MockWebServer(); |
| 411 | + $server->start(); |
| 412 | + |
| 413 | + // Obtained from http://aaron.pk/4Zn5 |
| 414 | + $url = $server->setResponseOfPath( |
| 415 | + '/4Zn5', |
| 416 | + new MockWebServerResponse(file_get_contents(__DIR__ . '/aaron.pk_4Zn5.html'), [], 200) |
| 417 | + ); |
| 418 | + |
| 419 | + $mf = Mf2\fetch($url); |
| 420 | + |
| 421 | + $server->stop(); |
392 | 422 |
|
393 | 423 | $this->assertArrayHasKey('photo', $mf['items'][0]['properties']); |
394 | 424 |
|
395 | 425 | $hostname = parse_url($mf['items'][0]['properties']['photo'][0], PHP_URL_HOST); |
396 | | - $this->assertEquals('aaronparecki.com', $hostname); |
| 426 | + $this->assertEquals('127.0.0.1', $hostname); |
397 | 427 |
|
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]); |
| 428 | + $this->assertEquals($server->getServerRoot() . '/img/1240x,q60/2014/12/23/5/photo.jpeg', $mf['items'][0]['properties']['photo'][0]); |
400 | 429 | } |
401 | 430 |
|
402 | 431 | public function testScriptTagContentsRemovedFromTextValue() { |
|
0 commit comments