|
|
@@ -11,17 +11,6 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
public $logHandler;
|
|
|
|
public $logHandler;
|
|
|
|
public $logger;
|
|
|
|
public $logger;
|
|
|
|
|
|
|
|
|
|
|
|
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$readability = new Readability($html, $url, $parser, $useTidy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->logHandler = new TestHandler();
|
|
|
|
|
|
|
|
$this->logger = new Logger('test', array($this->logHandler));
|
|
|
|
|
|
|
|
$readability->setLogger($this->logger);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $readability;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @requires extension tidy
|
|
|
|
* @requires extension tidy
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@@ -84,8 +73,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertFalse($res);
|
|
|
|
$this->assertFalse($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testInitP()
|
|
|
|
public function testInitP()
|
|
|
@@ -96,9 +85,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testInitDivP()
|
|
|
|
public function testInitDivP()
|
|
|
@@ -109,9 +98,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testInitDiv()
|
|
|
|
public function testInitDiv()
|
|
|
@@ -123,9 +112,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithFootnotes()
|
|
|
|
public function testWithFootnotes()
|
|
|
@@ -138,11 +127,11 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('readabilityFootnoteLink', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('readabilityFootnoteLink', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('readabilityLink-3', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('readabilityLink-3', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testStandardClean()
|
|
|
|
public function testStandardClean()
|
|
|
@@ -155,11 +144,11 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('will NOT be removed', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('will NOT be removed', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertNotContains('<h2>', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertNotContains('<h2>', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithIframe()
|
|
|
|
public function testWithIframe()
|
|
|
@@ -171,10 +160,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('nofollow', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithArticle()
|
|
|
|
public function testWithArticle()
|
|
|
@@ -186,10 +175,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('alt="article"', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('nofollow', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithAside()
|
|
|
|
public function testWithAside()
|
|
|
@@ -201,10 +190,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertNotContains('<aside>', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertNotContains('<aside>', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('<footer readability="4"/>', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<footer readability="4"/>', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithClasses()
|
|
|
|
public function testWithClasses()
|
|
|
@@ -216,10 +205,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('alt="article"', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertNotContains('This text should be removed', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithClassesWithoutLightClean()
|
|
|
|
public function testWithClassesWithoutLightClean()
|
|
|
@@ -232,10 +221,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('alt="article"', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertNotContains('This text should be removed', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithTd()
|
|
|
|
public function testWithTd()
|
|
|
@@ -247,8 +236,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithSameClasses()
|
|
|
|
public function testWithSameClasses()
|
|
|
@@ -260,9 +249,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testWithScript()
|
|
|
|
public function testWithScript()
|
|
|
@@ -274,9 +263,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$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()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testTitle()
|
|
|
|
public function testTitle()
|
|
|
@@ -288,9 +277,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEquals('this is my title', $readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEquals('this is my title', $readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$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()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testTitleWithDash()
|
|
|
|
public function testTitleWithDash()
|
|
|
@@ -302,9 +291,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEquals('title2 - title3', $readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEquals('title2 - title3', $readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$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()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testTitleWithDoubleDot()
|
|
|
|
public function testTitleWithDoubleDot()
|
|
|
@@ -316,9 +305,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEquals('title2 : title3', $readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEquals('title2 : title3', $readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$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()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testTitleTooShortUseH1()
|
|
|
|
public function testTitleTooShortUseH1()
|
|
|
@@ -330,9 +319,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertEquals('this is my h1 title !', $readability->getTitle()->innerHTML);
|
|
|
|
$this->assertEquals('this is my h1 title !', $readability->getTitle()->getInnerHtml());
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
|
|
|
$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()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dummy function to be used to the next test
|
|
|
|
// dummy function to be used to the next test
|
|
|
@@ -345,7 +334,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
error_reporting(E_ALL | E_STRICT);
|
|
|
|
error_reporting(E_ALL | E_STRICT);
|
|
|
|
ini_set('display_errors', true);
|
|
|
|
ini_set('display_errors', true);
|
|
|
|
set_error_handler(array($this, 'error2Exception'), E_ALL | E_STRICT);
|
|
|
|
set_error_handler([$this, 'error2Exception'], E_ALL | E_STRICT);
|
|
|
|
|
|
|
|
|
|
|
|
$data = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
$data = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" prefix="og: http://ogp.me/ns#">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" prefix="og: http://ogp.me/ns#">
|
|
|
@@ -380,8 +369,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
|
|
|
$this->assertContains('<iframe src="https://www.youtube.com/embed/PUep6xNeKjA" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"> </iframe>', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<iframe src="https://www.youtube.com/embed/PUep6xNeKjA" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"> </iframe>', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('3D Touch', $readability->getTitle()->innerHTML);
|
|
|
|
$this->assertContains('3D Touch', $readability->getTitle()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -445,13 +434,13 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
|
|
|
|
|
|
|
|
public function testPostFilters()
|
|
|
|
public function testPostFilters()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$readability = $this->getReadability('<div>' . str_repeat('<p>This <b>is</b> the awesome content :)</p>', 10) . '</div>', 'http://0.0.0.0');
|
|
|
|
$readability = $this->getReadability('<div>' . str_repeat('<p>This <strong>is</strong> the awesome content :)</p>', 10) . '</div>', 'http://0.0.0.0');
|
|
|
|
$readability->addPostFilter('!<strong[^>]*>(.*?)</strong>!is', '');
|
|
|
|
$readability->addPostFilter('!<strong[^>]*>(.*?)</strong>!is', '');
|
|
|
|
|
|
|
|
|
|
|
|
$res = $readability->init();
|
|
|
|
$res = $readability->init();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertContains('This the awesome content :)', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This the awesome content :)', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testPreFilters()
|
|
|
|
public function testPreFilters()
|
|
|
@@ -464,7 +453,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$res = $readability->init();
|
|
|
|
$res = $readability->init();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertContains('This the awesome and WONDERFUL content :)', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('This the awesome and WONDERFUL content :)', $readability->getContent()->getInnerHtml());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testChildNodeGoneNull()
|
|
|
|
public function testChildNodeGoneNull()
|
|
|
@@ -490,7 +479,18 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|
|
|
$res = $readability->init();
|
|
|
|
$res = $readability->init();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertTrue($res);
|
|
|
|
$this->assertContains('<sup id="fnref1:fnfeed_2"><a href="#fn:fnfeed_2" class="footnote-ref">2</a></sup>', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<sup id="fnref1:fnfeed_2"><a href="#fn:fnfeed_2" class="footnote-ref">2</a></sup>', $readability->getContent()->getInnerHtml());
|
|
|
|
$this->assertContains('<a href="#fnref1:fnfeed_2" rev="footnote"', $readability->getContent()->innerHTML);
|
|
|
|
$this->assertContains('<a href="#fnref1:fnfeed_2" rev="footnote"', $readability->getContent()->getInnerHtml());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$readability = new Readability($html, $url, $parser, $useTidy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->logHandler = new TestHandler();
|
|
|
|
|
|
|
|
$this->logger = new Logger('test', [$this->logHandler]);
|
|
|
|
|
|
|
|
$readability->setLogger($this->logger);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $readability;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|