NEW Track broken anchors

This commit is contained in:
Russell Michell 2013-08-23 14:33:36 +12:00 committed by Ingo Schommer
parent c6082827dc
commit 7d7c75414c
3 changed files with 22 additions and 3 deletions

View File

@ -59,6 +59,12 @@ class SiteTreeLinkTracking extends DataExtension {
}
} else if($href == '' || $href[0] == '/') {
$record->HasBrokenLink = true;
} else if(stristr($href, '#')) {
// Deals-to broken anchors (Links with no anchor)
$find = preg_replace("/^(.+)?#(.+)+$/","$2", $href);
if(!preg_match("#(name|id)=\"{$find}\"#", $record->$field)) {
$record->HasBrokenLink = true;
}
}
}
}

View File

@ -153,7 +153,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
public function testRestoreFixesBrokenLinks() {
// Create page and virutal page
// Create page and virtual page
$p = new Page();
$p->Title = "source";
$p->write();
@ -296,5 +296,18 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
//$this->assertFalse($vp->IsModifiedOnStage);
}
public function testBrokenAnchorLinksInAPage() {
$obj = $this->objFromFixture('Page','content');
$origContent = $obj->Content;
$obj->Content = $origContent . '<a href="#no-anchor-here">this links to a non-existent in-page anchor or skiplink</a>';
$obj->syncLinkTracking();
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken anchor/skiplink');
$obj->Content = $origContent . '<a href="#yes-anchor-here">this links to an existent in-page anchor/skiplink</a>';
$obj->syncLinkTracking();
$this->assertFalse($obj->HasBrokenLink, 'Page doesn\'t have a broken anchor or skiplink');
}
}

View File

@ -1,11 +1,11 @@
Page:
content:
Title: ContentPage
Content: This is some happy content.
Content: 'This is some partially happy content. It has one missing a skiplink, but does have another <a name="yes-anchor-here">skiplink here</a>.'
about:
Title: About
URLSegment: about
Content: about us here
Content: 'about us here <a name="yes-anchor-here">about skiplinks here</a>.'
brokenInternalRedirector:
RedirectionType: Internal
Title: RedirectorPageToBrokenInteralPage