summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2017-11-27 20:50:22 +0000
committerAndres Rey <[email protected]>2017-11-27 20:50:22 +0000
commit2ab37cea53017cf54dbe8c30d731a0249f84347e (patch)
treed0b5f6ac604fb13d0b1c33a1848404824168ac7c /test
parenta0559207f4fcbcfee10588b833779b7f6cb6d860 (diff)
Replace old test class with new one
Diffstat (limited to 'test')
-rw-r--r--test/HTMLParserTest.php77
-rw-r--r--test/ReadabilityTest.php80
2 files changed, 77 insertions, 80 deletions
diff --git a/test/HTMLParserTest.php b/test/HTMLParserTest.php
deleted file mode 100644
index 2aafa65..0000000
--- a/test/HTMLParserTest.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-
-namespace andreskrey\Readability\Test;
-
-use andreskrey\Readability\HTMLParser;
-
-class HTMLParserTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @dataProvider getSamplePages
- */
- public function testHTMLParserParsesHTML($html, $expectedResult, $expectedMetadata, $config, $expectedImages)
- {
- $options = ['originalURL' => 'http://fakehost/test/test.html',
- 'fixRelativeURLs' => true,
- 'substituteEntities' => true,
- ];
-
- if ($config) {
- $options = array_merge($options, $config);
- }
-
- $readability = new HTMLParser($options);
- $result = $readability->parse($html);
-
- $this->assertEquals($expectedResult, $result['html']);
- }
-
- /**
- * @dataProvider getSamplePages
- */
- public function testHTMLParserParsesImages($html, $expectedResult, $expectedMetadata, $config, $expectedImages)
- {
- $options = ['originalURL' => 'http://fakehost/test/test.html',
- 'fixRelativeURLs' => true,
- 'substituteEntities' => true,
- ];
-
- if ($config) {
- $options = array_merge($options, $config);
- }
-
- $readability = new HTMLParser($options);
- $result = $readability->parse($html);
- $this->assertEquals($expectedImages, json_encode($result['images']));
- }
-
- public function getSamplePages()
- {
- $path = pathinfo(__FILE__, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'test-pages';
- $testPages = scandir($path);
- if (in_array('.DS_Store', $testPages)) {
- unset($testPages[array_search('.DS_Store', $testPages)]);
- }
-
- $pages = [];
-
- foreach (array_slice($testPages, 2) as $testPage) {
- $source = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'source.html');
- $expectedHTML = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'expected.html');
- $expectedMetadata = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'expected-metadata.json');
- $expectedImages = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'expected-images.json');
-
- $config = null;
- if (file_exists($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'config.json')) {
- $config = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'config.json');
- if ($config) {
- $config = json_decode($config, true);
- }
- }
-
- $pages[$testPage] = [$source, $expectedHTML, $expectedMetadata, $config, $expectedImages];
- }
-
- return $pages;
- }
-}
diff --git a/test/ReadabilityTest.php b/test/ReadabilityTest.php
index ec96ef4..d019192 100644
--- a/test/ReadabilityTest.php
+++ b/test/ReadabilityTest.php
@@ -2,11 +2,85 @@
namespace andreskrey\Readability\Test;
+
+use andreskrey\Readability\Configuration;
+use andreskrey\Readability\Readability;
+
class ReadabilityTest extends \PHPUnit_Framework_TestCase
{
- public function testDummy()
+ /**
+ * @dataProvider getSamplePages
+ */
+ public function testReadabilityParsesHTML($html, $expectedResult, $expectedMetadata, $config, $expectedImages)
+ {
+ $options = ['originalURL' => 'http://fakehost/test/test.html',
+ 'fixRelativeURLs' => true,
+ 'substituteEntities' => true,
+ ];
+
+ if ($config) {
+ $options = array_merge($options, $config);
+ }
+
+ $configuration = new Configuration();
+
+ foreach($options as $key => $value){
+ $name = 'set' . $key;
+ $configuration->$name($value);
+ }
+
+ $readability = new Readability($configuration);
+ $result = $readability->parse($html);
+
+ $this->assertEquals($expectedResult, $result['html']);
+ }
+
+ /**
+ * @dataProvider getSamplePages
+ */
+ public function testHTMLParserParsesImages($html, $expectedResult, $expectedMetadata, $config, $expectedImages)
{
- //TODO
- $this->assertEquals(true, true);
+ $options = ['originalURL' => 'http://fakehost/test/test.html',
+ 'fixRelativeURLs' => true,
+ 'substituteEntities' => true,
+ ];
+
+ if ($config) {
+ $options = array_merge($options, $config);
+ }
+
+ $readability = new HTMLParser($options);
+ $result = $readability->parse($html);
+ $this->assertEquals($expectedImages, json_encode($result['images']));
+ }
+
+ public function getSamplePages()
+ {
+ $path = pathinfo(__FILE__, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'test-pages';
+ $testPages = scandir($path);
+ if (in_array('.DS_Store', $testPages)) {
+ unset($testPages[array_search('.DS_Store', $testPages)]);
+ }
+
+ $pages = [];
+
+ foreach (array_slice($testPages, 2) as $testPage) {
+ $source = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'source.html');
+ $expectedHTML = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'expected.html');
+ $expectedMetadata = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'expected-metadata.json');
+ $expectedImages = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'expected-images.json');
+
+ $config = null;
+ if (file_exists($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'config.json')) {
+ $config = file_get_contents($path . DIRECTORY_SEPARATOR . $testPage . DIRECTORY_SEPARATOR . 'config.json');
+ if ($config) {
+ $config = json_decode($config, true);
+ }
+ }
+
+ $pages[$testPage] = [$source, $expectedHTML, $expectedMetadata, $config, $expectedImages];
+ }
+
+ return $pages;
}
}