Skip to content

Commit 5cc7160

Browse files
committed
Remove consecutive whitespace when comparing tests
As discussed previously php-mf2 has custom handling of textContent to match with what consumers were expecting to get back. This means all tests around plain text output have a high tendency to fail. This change addresses that a little by ignoring whitespace differences within e-* properties.
1 parent b25e4f0 commit 5cc7160

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/Mf2/MicroformatsTestSuiteTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public function testMixedFromTestSuite($input, $expectedOutput)
4848
* * We sort arrays by key, normalising them, because JSON objects are unordered.
4949
* * We json_encode strings, and cut the starting and ending ", so PHPUnit better
5050
* shows whitespace characters like tabs and newlines.
51+
* * We replace all consecutive whitespace with single space characters in e-* value
52+
* properties, to avoid failing tests only because difference in the handing of
53+
* extracting textContent.
5154
**/
5255
public function makeComparible($array)
5356
{
@@ -56,6 +59,9 @@ public function makeComparible($array)
5659
if (gettype($value) === 'array') {
5760
$array[$key] = $this->makeComparible($value);
5861
} else if (gettype($value) === 'string') {
62+
if ($key === 'value' && array_key_exists('html', $array)) {
63+
$value = preg_replace('/\s+/', ' ', $value);
64+
}
5965
$array[$key] = substr(json_encode($value), 1, -1);
6066
}
6167
}

0 commit comments

Comments
 (0)