Add missing HTML5 class

This commit is contained in:
Jeremy Benoist
2017-06-30 16:32:37 +02:00
parent 5ac82f3c87
commit 05089bbd03
3 changed files with 13 additions and 9 deletions
+2 -1
View File
@@ -26,7 +26,8 @@
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"ext-mbstring": "*", "ext-mbstring": "*",
"psr/log": "^1.0" "psr/log": "^1.0",
"electrolinux/php-html5lib": "^0.1.0"
}, },
"require-dev": { "require-dev": {
"satooshi/php-coveralls": "~0.6", "satooshi/php-coveralls": "~0.6",
+2 -1
View File
@@ -5,6 +5,7 @@ namespace Readability;
use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use HTML5Lib\Parser;
/** /**
* Arc90's Readability ported to PHP for FiveFilters.org * Arc90's Readability ported to PHP for FiveFilters.org
@@ -284,7 +285,7 @@ class Readability implements LoggerAwareInterface
$this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', 'UTF-8'); $this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', 'UTF-8');
if (!($this->parser === 'html5lib' && ($this->dom = \HTML5_Parser::parse($this->html)))) { if (!($this->parser === 'html5lib' && ($this->dom = Parser::parse($this->html)))) {
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$this->dom = new \DOMDocument(); $this->dom = new \DOMDocument();
+9 -7
View File
@@ -33,6 +33,15 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('DomDocument', $readability->dom); $this->assertInstanceOf('DomDocument', $readability->dom);
} }
public function testConstructHtml5Parser()
{
$readability = $this->getReadability('<html/>', 'http://0.0.0.0', 'html5lib');
$this->assertEquals('http://0.0.0.0', $readability->url);
$this->assertInstanceOf('DomDocument', $readability->dom);
$this->assertEquals('<html/>', $readability->original_html);
}
/** /**
* @requires extension tidy * @requires extension tidy
*/ */
@@ -326,13 +335,6 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML); $this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
} }
// public function testConstructParser()
// {
// $readability = $this->getReadability('<html/>', 'http://0.0.0.0', 'html5lib');
// $this->assertEquals('http://0.0.0.0', $readability->url);
// }
// dummy function to be used to the next test // dummy function to be used to the next test
public function error2Exception($code, $string, $file, $line, $context) public function error2Exception($code, $string, $file, $line, $context)
{ {