From 6f9439ebf277b8694d30e1ef76292b5ab1a7e899 Mon Sep 17 00:00:00 2001 From: "FiveFilters.org" Date: Wed, 11 Aug 2021 23:53:31 +0200 Subject: Remove whitespace when comparing expected and actual output --- test/ReadabilityTest.php | 19 +++++++++++++++++-- 1 file 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 ]+\ ', '<', '\\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)]; } } -- cgit v1.2.3