create('HTMLValue', $content); $links = $parser->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')); $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('')); $this->assertFalse($this->pageIsBrokenFile('')); } protected function pageIsBrokenFile($content) { $page = new Page(); $page->Content = $content; $page->write(); return $page->HasBrokenFile; } }