summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFiveFilters.org <[email protected]>2021-08-11 23:53:31 +0200
committerFiveFilters.org <[email protected]>2021-08-11 23:53:31 +0200
commit6f9439ebf277b8694d30e1ef76292b5ab1a7e899 (patch)
tree547d036c16ab7a0040fd93459b3210122dad7da5 /test
parent85afc0e5488dcb1db442ea2232ca1e347419129b (diff)
Remove whitespace when comparing expected and actual output
Diffstat (limited to 'test')
-rw-r--r--test/ReadabilityTest.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/ReadabilityTest.php b/test/ReadabilityTest.php
index ca208e8..4ca71cf 100644
--- a/test/ReadabilityTest.php
+++ b/test/ReadabilityTest.php
@@ -33,7 +33,21 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
$readability = new Readability($configuration);
$readability->parse($testPage->getSourceHTML());
- $this->assertSame($testPage->getExpectedHTML(), $readability->getContent(), 'Parsed text does not match the expected one.');
+ // Let's (crudely) remove whitespace between tags here to simplify comparison.
+ // This isn't used for output.
+ $from = ['/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', '/> </s'];
+ $to = ['>', '<', '\\1', '><'];
+ $expected_no_whitespace = preg_replace($from, $to, $testPage->getExpectedHTML());
+ $readability_no_whitespace = preg_replace($from, $to, $readability->getContent());
+
+ $this->assertSame(
+ preg_replace($from, $to, $expected_no_whitespace),
+ preg_replace($from, $to, $readability_no_whitespace),
+ 'Parsed text does not match the expected one.'
+ );
+
+ //$this->assertSame($testPage->getExpectedHTML(), $readability->getContent(), 'Parsed text does not match the expected one.');
+ //$this->assertXmlStringEqualsXmlString($testPage->getExpectedHTML(), $readability->getContent(), 'Parsed text does not match the expected one.');
}
/**
@@ -101,13 +115,14 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
foreach (array_slice($testPages, 2) as $testPage) {
$testCasePath = $path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR;
+ $slug = $testPage;
$source = file_get_contents($testCasePath . 'source.html');
$expectedHTML = file_get_contents($testCasePath . 'expected.html');
$expectedImages = json_decode(file_get_contents($testCasePath . 'expected-images.json'), true);
$expectedMetadata = json_decode(file_get_contents($testCasePath . 'expected-metadata.json'));
$configuration = file_exists($testCasePath . 'config.json') ? json_decode(file_get_contents($testCasePath . 'config.json'), true) : [];
- yield $testPage => [new TestPage($configuration, $source, $expectedHTML, $expectedImages, $expectedMetadata)];
+ yield $testPage => [new TestPage($slug, $configuration, $source, $expectedHTML, $expectedImages, $expectedMetadata)];
}
}