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
7 changes: 0 additions & 7 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ function nestedMfPropertyNamesFromElement(\DOMElement $e) {
* @return string
*/
function convertTimeFormat($time) {
$hh = $mm = $ss = '';
preg_match('/(\d{1,2}):?(\d{2})?:?(\d{2})?(a\.?m\.?|p\.?m\.?)?/i', $time, $matches);

// If no am/pm is specified:
Expand Down Expand Up @@ -943,12 +942,6 @@ public function parseE(\DOMElement $e) {
return $return;
}

private function removeTags(\DOMElement &$e, $tagName) {
while(($r = $e->getElementsByTagName($tagName)) && $r->length) {
$r->item(0)->parentNode->removeChild($r->item(0));
}
}

/**
* Recursively parse microformats
*
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,13 @@ Pull requests very welcome, please try to maintain stylistic, structural and nam

Run `composer install` and `composer check-and-tests`. This will run `phpcs`, the php-mf2 tests, and the cross-platform [microformats/tests](https://github.com/microformats/tests) (excluding mf1; more details below).

The php-mf2 tests are in `/tests/Mf2` and contain many parsing examples, internal parser tests, and regression tests for specific issues over its history. If you need to run tests without an internet connection, run `composer tests-no-internet`.
The php-mf2 tests are in `/tests/Mf2` and contain many parsing examples, internal parser tests, and regression tests for specific issues over its history.

`microformats/tests` are included via `MicroformatsTestSuiteTest.php`. It has tests for mf2 and mf1. php-mf2 will fail some of the mf1 tests, so the `check-and-tests` script will skip them currently. It **is** a goal to pass those mf1 tests, so you can run them with `composer microformats-tests-mf1`. There are additional composer scripts listed below for running parts of this test suite on their own.

**Composer scripts**
- phpcs: run with `composer cs-check`
- php-mf2 tests + microformats/tests, except mf1: run with `composer tests`
- same, but exclude tests that require internet: `composer tests-no-internet`
- microformats/tests suite:
- run mf1 tests with `composer microformats-tests-mf1`
- run mf2 tests with `composer microformats-tests-mf2`
Expand Down
2 changes: 1 addition & 1 deletion 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 All @@ -30,7 +31,6 @@
"scripts": {
"cs-check": "phpcs",
"tests": "XDEBUG_MODE=coverage ./vendor/bin/phpunit tests --coverage-text --whitelist Mf2",
"tests-no-internet": "@tests --exclude-group internet,microformats/tests/mf1",
"microformats-tests-mf1": "./vendor/bin/phpunit --group microformats/tests/mf1",
"microformats-tests-mf2": "./vendor/bin/phpunit --group microformats/tests/mf2",
"microformats-tests-mixed": "./vendor/bin/phpunit --group microformats/tests/mixed",
Expand Down
51 changes: 36 additions & 15 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 @@ -267,16 +269,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('https://microformats.org/');
$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('https://microformats.org/microformats-logo.png', null, $curlInfo);
$mf = Mf2\fetch($photoUrl, null, $curlInfo);
$this->assertNull($mf);
$this->assertStringContainsString('image/png', $curlInfo['content_type']);
$this->assertStringContainsString('jpeg', $curlInfo['content_type']);

$server->stop();
}

/**
Expand Down Expand Up @@ -382,22 +398,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