logHandler = new TestHandler(); $this->logger = new Logger('test', array($this->logHandler)); $readability->setLogger($this->logger); return $readability; } public function testConstructSimple() { $readability = $this->getReadability('', 'http://0.0.0.0'); $readability->init(); $this->assertEquals('http://0.0.0.0', $readability->url); $this->assertEquals('', $readability->original_html); $this->assertTrue($readability->tidied); $this->assertTrue($this->logHandler->hasDebugThatContains('Parsing URL: http://0.0.0.0')); $this->assertTrue($this->logHandler->hasDebugThatContains('Tidying document')); $this->assertTrue($this->logHandler->hasDebugThatContains('Light clean enabled.')); } public function testConstructDefaultWithoutTidy() { $readability = $this->getReadability('', null, 'libxml', false); $readability->init(); $this->assertNull($readability->url); $this->assertEquals('', $readability->original_html); $this->assertFalse($readability->tidied); $this->assertTrue($this->logHandler->hasDebugThatContains('Parsing URL: ')); $this->assertFalse($this->logHandler->hasDebugThatContains('Tidying document')); $this->assertTrue($this->logHandler->hasDebugThatContains('Light clean enabled.')); } public function testConstructSimpleWithoutTidy() { $readability = $this->getReadability('', 'http://0.0.0.0', 'libxml', false); $readability->init(); $this->assertEquals('http://0.0.0.0', $readability->url); $this->assertEquals('', $readability->original_html); $this->assertFalse($readability->tidied); } public function testInitNoContent() { $readability = $this->getReadability('', 'http://0.0.0.0'); $res = $readability->init(); $this->assertFalse($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertEmpty($readability->getTitle()->innerHTML); $this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->innerHTML); } public function testInitP() { $readability = $this->getReadability(str_repeat('

This is the awesome content :)

', 7), 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('
getContent()->innerHTML); } public function testInitDivP() { $readability = $this->getReadability('
'.str_repeat('

This is the awesome content :)

', 7).'
', 'http://0.0.0.0'); $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('
getContent()->innerHTML); } public function testInitDiv() { $readability = $this->getReadability('
'.str_repeat('This is the awesome content :)', 7).'
', 'http://0.0.0.0'); $readability->debug = true; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('
getContent()->innerHTML); } public function testWithFootnotes() { $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->debug = true; $readability->convertLinksToFootnotes = true; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('
getContent()->innerHTML); $this->assertContains('readabilityFootnoteLink', $readability->getContent()->innerHTML); $this->assertContains('readabilityLink-3', $readability->getContent()->innerHTML); } public function testStandardClean() { $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->debug = true; $readability->lightClean = false; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('
getContent()->innerHTML); $this->assertContains('will NOT be removed', $readability->getContent()->innerHTML); $this->assertNotContains('

', $readability->getContent()->innerHTML); } public function testWithIframe() { $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'); $readability->debug = true; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('
getContent()->innerHTML); $this->assertContains('nofollow', $readability->getContent()->innerHTML); } public function testWithArticle() { $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'); $readability->debug = true; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertContains('alt="article"', $readability->getContent()->innerHTML); $this->assertEmpty($readability->getTitle()->innerHTML); $this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML); $this->assertContains('nofollow', $readability->getContent()->innerHTML); } public function testWithAside() { $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->debug = true; $res = $readability->init(); $this->assertTrue($res); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent()); $this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle()); $this->assertEmpty($readability->getTitle()->innerHTML); $this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML); $this->assertNotContains('