create('HTMLValue', $content); $links = $parser->process($htmlValue); if (empty($links[0])) return false; return $links[0]['Broken']; } 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\">")); } function highlight($content) { $page = new Page(); $page->Content = $content; $page->write(); return $page->Content; } 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.'); } }