mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
NEW Track broken anchors
This commit is contained in:
parent
c6082827dc
commit
7d7c75414c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user