Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Pull requests very welcome, please try to maintain stylistic, structural and nam

### Testing

There are currently two separate test suites: one, in `tests/Mf2`, is written in phpunit, containing many microformats parsing examples as well as internal parser tests and regression tests for specific issues over php-mf2’s history. Run it with `./vendor/bin/phpunit`. If you do not have a live internet connection, you can exclude tests that depend on it: `./vendor/bin/phpunit --exclude-group internet`.
There are currently two separate test suites: one, in `tests/Mf2`, is written in phpunit, containing many microformats parsing examples as well as internal parser tests and regression tests for specific issues over php-mf2’s history. Run it with `./vendor/bin/phpunit`.

The other, in `tests/test-suite`, is a custom test harness which hooks up php-mf2 to the cross-platform [microformats test suite](https://github.com/microformats/tests). To run these tests you must first install the tests with `./composer.phar install`. Each test consists of a HTML file and a corresponding JSON file, and the suite can be run with `php ./tests/test-suite/test-suite.php`.

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"require-dev": {
"donatj/mock-webserver": "^2.10",
"mf2/tests": "dev-master#e9e2b905821ba0a5b59dab1a8eaf40634ce9cd49",
"squizlabs/php_codesniffer": "^3.10.2",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
Expand Down
49 changes: 35 additions & 14 deletions tests/Mf2/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Mf2\Parser\Test;

use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\Response as MockWebServerResponse;
use Mf2\Parser;
use Mf2;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
Expand Down Expand Up @@ -266,16 +268,30 @@ public function testParsesNestedMicroformatsWithClassnamesInAnyOrder() {
$this->assertEquals('Name', $output['items'][0]['properties']['in-reply-to'][0]['properties']['name'][0]);
}

/**
* @group internet
*/
public function testFetchMicroformats() {
$mf = Mf2\fetch('http://waterpigs.co.uk/');
$server = new MockWebServer();
$server->start();

// Obtained from http://waterpigs.co.uk/
$indexUrl = $server->setResponseOfPath(
'/',
new MockWebServerResponse(file_get_contents(__DIR__ . '/waterpigs.co.uk_index.html'), [], 200)
);

// Obtained from http://waterpigs.co.uk/photo.jpg
$photoUrl = $server->setResponseOfPath(
'/photo.jpg',
new MockWebServerResponse(file_get_contents(__DIR__ . '/waterpigs.co.uk_photo.jpg'), ['content-type: image/jpeg'], 200)
);

$mf = Mf2\fetch($indexUrl);
$this->assertArrayHasKey('items', $mf);

$mf = Mf2\fetch('http://waterpigs.co.uk/photo.jpg', null, $curlInfo);
$mf = Mf2\fetch($photoUrl, null, $curlInfo);
$this->assertNull($mf);
$this->assertStringContainsString('jpeg', $curlInfo['content_type']);

$server->stop();
}

/**
Expand Down Expand Up @@ -381,22 +397,27 @@ public function testApplyTransformationToSrcset() {

/**
* @see https://github.com/indieweb/php-mf2/issues/84
* @group internet
*
* 2024-04-07: The final photo URL in this test changed over time.
* Updated it to only check that the final URL's hostname was correct,
* not the full photo URL.
*/
public function testRelativeURLResolvedWithFinalURL() {
$mf = Mf2\fetch('http://aaron.pk/4Zn5');
$server = new MockWebServer();
$server->start();

// Obtained from http://aaron.pk/4Zn5
$url = $server->setResponseOfPath(
'/4Zn5',
new MockWebServerResponse(file_get_contents(__DIR__ . '/aaron.pk_4Zn5.html'), [], 200)
);

$mf = Mf2\fetch($url);

$server->stop();

$this->assertArrayHasKey('photo', $mf['items'][0]['properties']);

$hostname = parse_url($mf['items'][0]['properties']['photo'][0], PHP_URL_HOST);
$this->assertEquals('aaronparecki.com', $hostname);
$this->assertEquals('127.0.0.1', $hostname);

// previous assertion: not the photo URL changed over time
// $this->assertEquals('https://aaronparecki.com/img/1240x0/2014/12/23/5/photo.jpeg', $mf['items'][0]['properties']['photo'][0]);
$this->assertEquals($server->getServerRoot() . '/img/1240x,q60/2014/12/23/5/photo.jpeg', $mf['items'][0]['properties']['photo'][0]);
}

public function testScriptTagContentsRemovedFromTextValue() {
Expand Down
Loading
Loading