summaryrefslogtreecommitdiff
path: root/plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php')
-rw-r--r--plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php75
1 files changed, 65 insertions, 10 deletions
diff --git a/plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php b/plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php
index ca208e894..dafd54021 100644
--- a/plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php
+++ b/plugins/af_readability/vendor/fivefilters/readability.php/test/ReadabilityTest.php
@@ -1,10 +1,10 @@
<?php
-namespace andreskrey\Readability\Test;
+namespace fivefilters\Readability\Test;
-use andreskrey\Readability\Configuration;
-use andreskrey\Readability\ParseException;
-use andreskrey\Readability\Readability;
+use fivefilters\Readability\Configuration;
+use fivefilters\Readability\ParseException;
+use fivefilters\Readability\Readability;
/**
* Class ReadabilityTest.
@@ -33,7 +33,30 @@ 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());
+
+ if (getenv('output-changes') && $expected_no_whitespace !== $readability_no_whitespace) {
+ @mkdir(__DIR__.'/changed/'.$testPage->getSlug());
+ $new_expected = __DIR__.'/changed/'.$testPage->getSlug().'/expected.html';
+ $old_expected = __DIR__.'/test-pages/'.$testPage->getSlug().'/expected.html';
+ //file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/readability.html', $readability_no_whitespace);
+ //file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/expected-current.html', $expected_no_whitespace);
+ file_put_contents($new_expected, $readability->getContent());
+ if (getenv('output-diff')) {
+ file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/diff-expected.txt', shell_exec(sprintf('diff -u -d %s %s', $old_expected, $new_expected)));
+ }
+
+ }
+
+ $this->assertSame($expected_no_whitespace, $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.');
}
/**
@@ -58,6 +81,26 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
$readability = new Readability($configuration);
$readability->parse($testPage->getSourceHTML());
+ $metadata = [
+ 'Author' => $readability->getAuthor(),
+ 'Direction' => $readability->getDirection(),
+ 'Excerpt' => $readability->getExcerpt(),
+ 'Image' => $readability->getImage(),
+ 'Title' => $readability->getTitle(),
+ 'SiteName' => $readability->getSiteName()
+ ];
+
+ if (getenv('output-changes') && (array)$testPage->getExpectedMetadata() !== $metadata) {
+ @mkdir(__DIR__.'/changed/'.$testPage->getSlug());
+ $new_expected = __DIR__.'/changed/'.$testPage->getSlug().'/expected-metadata.json';
+ $old_expected = __DIR__.'/test-pages/'.$testPage->getSlug().'/expected-metadata.json';
+ //file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/expected-metadata-current.json', json_encode($testPage->getExpectedMetadata(), JSON_PRETTY_PRINT));
+ file_put_contents($new_expected, json_encode((object)$metadata, JSON_PRETTY_PRINT));
+ if (getenv('output-diff')) {
+ file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/diff-expected-metadata.txt', shell_exec(sprintf('diff -u -d %s %s', $old_expected, $new_expected)));
+ }
+ }
+
$this->assertSame($testPage->getExpectedMetadata()->Author, $readability->getAuthor(), 'Parsed Author does not match expected value.');
$this->assertSame($testPage->getExpectedMetadata()->Direction, $readability->getDirection(), 'Parsed Direction does not match expected value.');
$this->assertSame($testPage->getExpectedMetadata()->Excerpt, $readability->getExcerpt(), 'Parsed Excerpt does not match expected value.');
@@ -85,7 +128,18 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
$readability = new Readability($configuration);
$readability->parse($testPage->getSourceHTML());
- $this->assertSame($testPage->getExpectedImages(), $readability->getImages());
+ if (getenv('output-changes') && $testPage->getExpectedImages() !== array_values($readability->getImages())) {
+ @mkdir(__DIR__.'/changed/'.$testPage->getSlug());
+ $new_expected = __DIR__.'/changed/'.$testPage->getSlug().'/expected-images.json';
+ $old_expected = __DIR__.'/test-pages/'.$testPage->getSlug().'/expected-images.json';
+ //file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/expected-images-current.json', json_encode($testPage->getExpectedImages(), JSON_PRETTY_PRINT));
+ file_put_contents($new_expected, json_encode(array_values($readability->getImages()), JSON_PRETTY_PRINT));
+ if (getenv('output-diff')) {
+ file_put_contents(__DIR__.'/changed/'.$testPage->getSlug().'/diff-expected-images.txt', shell_exec(sprintf('diff -u -d %s %s', $old_expected, $new_expected)));
+ }
+ }
+
+ $this->assertSame($testPage->getExpectedImages(), array_values($readability->getImages()));
}
/**
@@ -101,13 +155,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'));
+ $expectedHTML = file_exists($testCasePath . 'expected.html') ? file_get_contents($testCasePath . 'expected.html') : '';
+ $expectedImages = file_exists($testCasePath . 'expected-images.json') ? json_decode(file_get_contents($testCasePath . 'expected-images.json'), true) : [];
+ $expectedMetadata = file_exists($testCasePath . 'expected-metadata.json') ? json_decode(file_get_contents($testCasePath . 'expected-metadata.json')) : (object)[];
$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)];
}
}