getReadability(''); $this->assertSame('utf8', $readability->tidy_config['input-encoding']); $readability->init(); $this->assertNull($readability->url); $this->assertInstanceOf(\DOMDocument::class, $readability->dom); } public function testConstructHtml5Parser(): void { $readability = $this->getReadability('', 'http://0.0.0.0', 'html5lib'); $readability->init(); $this->assertSame('http://0.0.0.0', $readability->url); $this->assertInstanceOf(\DOMDocument::class, $readability->dom); $this->assertSame('', $readability->original_html); } /** * @requires extension tidy */ public function testConstructSimple(): void { $readability = $this->getReadability('', 'http://0.0.0.0'); $readability->init(); $this->assertSame('http://0.0.0.0', $readability->url); $this->assertInstanceOf(\DOMDocument::class, $readability->dom); $this->assertSame('', $readability->original_html); $this->assertTrue($readability->tidied); } public function testConstructDefaultWithoutTidy(): void { $readability = $this->getReadability('', null, 'libxml', false); $readability->init(); $this->assertNull($readability->url); $this->assertSame('', $readability->original_html); $this->assertFalse($readability->tidied); $this->assertInstanceOf(\DOMDocument::class, $readability->dom); } public function testConstructSimpleWithoutTidy(): void { $readability = $this->getReadability('', 'http://0.0.0.0', 'libxml', false); $readability->init(); $this->assertSame('http://0.0.0.0', $readability->url); $this->assertInstanceOf(\DOMDocument::class, $readability->dom); $this->assertSame('', $readability->original_html); $this->assertFalse($readability->tidied); } public function testInitNoContent(): void { $readability = $this->getReadability('', 'http://0.0.0.0'); $res = $readability->init(); $this->assertFalse($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertEmpty($readability->getTitle()->getInnerHtml()); $this->assertStringContainsString('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->getInnerHtml()); } public function testInitP(): void { $readability = $this->getReadability(str_repeat('

This is the awesome content :)

', 7), 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('
getContent()->getInnerHtml()); } public function testInitDivP(): void { $readability = $this->getReadability('
' . str_repeat('

This is the awesome content :)

', 7) . '
', 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('
getContent()->getInnerHtml()); } public function testInitDiv(): void { $readability = $this->getReadability('
' . str_repeat('This is the awesome content :)', 7) . '
', 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('
getContent()->getInnerHtml()); } public function testWithFootnotes(): void { $readability = $this->getReadability('
' . str_repeat('

This is an awesome text with some links, here there are: the awesome

', 7) . '
', 'http://0.0.0.0'); $readability->convertLinksToFootnotes = true; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('
getContent()->getInnerHtml()); $this->assertStringContainsString('readabilityFootnoteLink', $readability->getContent()->getInnerHtml()); $this->assertStringContainsString('readabilityLink-3', $readability->getContent()->getInnerHtml()); } public function testStandardClean(): void { $readability = $this->getReadability('

Title

' . str_repeat('

This is an awesome text with some links, here there are: the awesome

', 7) . 'will NOT be removed
', 'http://0.0.0.0'); $readability->lightClean = false; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('
getContent()->getInnerHtml()); $this->assertStringContainsString('will NOT be removed', $readability->getContent()->getInnerHtml()); $this->assertStringNotContainsString('

', $readability->getContent()->getInnerHtml()); } public function testWithIframe(): void { $readability = $this->getReadability('

Title

' . str_repeat('

This is an awesome text with some links, here there are: the awesome

', 7) . '

This is an awesome text with some links, here there are

', 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('
getContent()->getInnerHtml()); $this->assertStringContainsString('nofollow', $readability->getContent()->getInnerHtml()); } public function testWithArticle(): void { $readability = $this->getReadability('

' . str_repeat('This is an awesome text with some links, here there are: the awesome', 20) . '

This is an awesome text with some links, here there are

', 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertStringContainsString('alt="article"', $readability->getContent()->getInnerHtml()); $this->assertEmpty($readability->getTitle()->getInnerHtml()); $this->assertStringContainsString('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml()); $this->assertStringContainsString('nofollow', $readability->getContent()->getInnerHtml()); } public function testWithAside(): void { $readability = $this->getReadability('
' . str_repeat('

This is an awesome text with some links, here there are: the awesome

', 7) . '
', 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getContent()); $this->assertInstanceOf(JSLikeHTMLElement::class, $readability->getTitle()); $this->assertEmpty($readability->getTitle()->getInnerHtml()); $this->assertStringContainsString('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml()); $this->assertStringNotContainsString('