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')); $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")); } function highlight($content) { $field = new SiteTreeLinkTrackingTest_Field('Test'); $field->setValue($content); $newContent = html_entity_decode($field->Field(), ENT_COMPAT, 'UTF-8'); return $newContent; } 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.'); $page = new Page(); $page->Content = ''; $page->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.'); } } class SiteTreeLinkTrackingTest_Field extends HtmlEditorField implements TestOnly { private static $extensions = array( 'SiteTreeLinkTracking_Highlighter' ); }