process($htmlValue);
if (empty($links[0])) {
return false;
}
return $links[0]['Broken'];
}
public function testParser()
{
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
$this->assertFalse($this->isBroken('anchor'));
$this->assertFalse($this->isBroken('anchor'));
$this->assertTrue($this->isBroken('anchor'));
$page = new Page();
$page->Content = 'nameid';
$page->write();
$file = new File();
$file->write();
$this->assertFalse($this->isBroken("ID]\">link"));
$this->assertFalse($this->isBroken("ID]#yes-name-anchor\">link"));
$this->assertFalse($this->isBroken("ID]#yes-id-anchor\">link"));
$this->assertFalse($this->isBroken("ID]\">link"));
$this->assertTrue($this->isBroken("ID]#http://invalid-anchor.com\">"));
}
protected function highlight($content)
{
$page = new Page();
$page->Content = $content;
$page->write();
return $page->Content;
}
public function testHighlighter()
{
$content = $this->highlight('link');
$this->assertEquals(substr_count($content, 'ss-broken'), 1, 'A ss-broken class is added to the broken link.');
$this->assertEquals(substr_count($content, 'existing-class'), 1, 'Existing class is not removed.');
$content = $this->highlight('link');
$this->assertEquals(substr_count($content, 'ss-broken'), 1, 'ss-broken class is added to the broken link.');
$otherPage = new Page();
$otherPage->Content = '';
$otherPage->write();
$content = $this->highlight(
"ID]\" class=\"existing-class ss-broken ss-broken\">link"
);
$this->assertEquals(substr_count($content, 'ss-broken'), 0, 'All ss-broken classes are removed from good link');
$this->assertEquals(substr_count($content, 'existing-class'), 1, 'Existing class is not removed.');
}
public function testHasBrokenFile()
{
$this->assertTrue($this->pageIsBrokenFile('[image src="someurl.jpg" id="99999999"]'));
$this->assertFalse($this->pageIsBrokenFile('[image src="someurl.jpg"]'));
}
protected function pageIsBrokenFile($content)
{
$page = new Page();
$page->Content = $content;
$page->write();
return $page->HasBrokenFile;
}
}