mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCMENT improved reporting around broken links/files (from r88993)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89207 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
dfd45fb7fd
commit
e23023b8a9
@ -92,6 +92,15 @@ class RedirectorPage extends Page {
|
||||
}
|
||||
}
|
||||
|
||||
function syncLinkTracking() {
|
||||
if ($this->RedirectionType == 'Internal') {
|
||||
$this->HasBrokenLink = DataObject::get_by_id('SiteTree', $this->LinkToID) ? false : true;
|
||||
} else {
|
||||
// TODO implement checking of a remote site
|
||||
$this->HasBrokenLink = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/RedirectorPage.js");
|
||||
|
||||
|
@ -1334,7 +1334,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
if($candidateFile) {
|
||||
$linkedFiles[] = $candidateFile->ID;
|
||||
} else {
|
||||
$this->HasBrokenLink = true;
|
||||
$this->HasBrokenFile = true;
|
||||
}
|
||||
} else if($link == '' || $link[0] == '/') {
|
||||
$this->HasBrokenLink = true;
|
||||
|
@ -54,6 +54,10 @@ class VirtualPage extends Page {
|
||||
}
|
||||
}
|
||||
|
||||
function syncLinkTracking() {
|
||||
$this->HasBrokenLink = DataObject::get_by_id('SiteTree', $this->CopyContentFromID) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the CMS fields from the fields from the original page.
|
||||
|
63
tests/SiteTreeBrokenLinksTest.php
Normal file
63
tests/SiteTreeBrokenLinksTest.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
static $fixture_file = 'sapphire/tests/SiteTreeBrokenLinksTest.yml';
|
||||
|
||||
function testBrokenLinksBetweenPages() {
|
||||
$obj = $this->objFromFixture('Page','content');
|
||||
|
||||
$obj->Content = '<a href="no-page-here/">this is a broken link</a>';
|
||||
$obj->syncLinkTracking();
|
||||
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken link');
|
||||
|
||||
$obj->Content = '<a href="about/">this is not a broken link</a>';
|
||||
$obj->syncLinkTracking();
|
||||
$this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link');
|
||||
}
|
||||
|
||||
function testBrokenVirtualPages() {
|
||||
$obj = $this->objFromFixture('Page','content');
|
||||
$vp = new VirtualPage();
|
||||
|
||||
$vp->CopyContentFromID = $obj->ID;
|
||||
$vp->syncLinkTracking();
|
||||
$this->assertFalse($vp->HasBrokenLink, 'Working virtual page is NOT marked as broken');
|
||||
|
||||
$vp->CopyContentFromID = 12345678;
|
||||
$vp->syncLinkTracking();
|
||||
$this->assertTrue($vp->HasBrokenLink, 'Broken virtual page IS marked as such');
|
||||
}
|
||||
|
||||
function testBrokenInternalRedirectorPages() {
|
||||
$obj = $this->objFromFixture('Page','content');
|
||||
$rp = new RedirectorPage();
|
||||
|
||||
$rp->RedirectionType = 'Internal';
|
||||
|
||||
$rp->LinkToID = $obj->ID;
|
||||
$rp->syncLinkTracking();
|
||||
$this->assertFalse($rp->HasBrokenLink, 'Working redirector page is NOT marked as broken');
|
||||
|
||||
$rp->LinkToID = 12345678;
|
||||
$rp->syncLinkTracking();
|
||||
$this->assertTrue($rp->HasBrokenLink, 'Broken redirector page IS marked as such');
|
||||
}
|
||||
|
||||
function testBrokenAssetLinks() {
|
||||
$obj = $this->objFromFixture('Page','content');
|
||||
|
||||
$obj->Content = '<a href="assets/nofilehere.pdf">this is a broken link to a pdf file</a>';
|
||||
$obj->syncLinkTracking();
|
||||
$this->assertTrue($obj->HasBrokenFile, 'Page has a broken file');
|
||||
|
||||
$obj->Content = '<a href="assets/privacypolicy.pdf">this is not a broken file link</a>';
|
||||
$obj->syncLinkTracking();
|
||||
$this->assertFalse($obj->HasBrokenFile, 'Page does NOT have a broken file');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
27
tests/SiteTreeBrokenLinksTest.yml
Normal file
27
tests/SiteTreeBrokenLinksTest.yml
Normal file
@ -0,0 +1,27 @@
|
||||
Page:
|
||||
content:
|
||||
Title: ContentPage
|
||||
Content: This is some happy content.
|
||||
about:
|
||||
Title: About
|
||||
URLSegment: about
|
||||
Content: about us here
|
||||
brokenInternalRedirector:
|
||||
RedirectionType: Internal
|
||||
Title: RedirectorPageToBrokenInteralPage
|
||||
LinkToID: 0
|
||||
workingInternalRedirector:
|
||||
RedirectionType: Internal
|
||||
Title: RedirectorPageToBrokenInteralPage
|
||||
LinkTo: =>Page.content
|
||||
|
||||
File:
|
||||
privacypolicy:
|
||||
Name: privacypolicy.pdf
|
||||
Title: privacypolicy.pdf
|
||||
Filename: assets/privacypolicy.pdf
|
||||
|
||||
ErrorPage:
|
||||
404:
|
||||
Title: Page not Found
|
||||
ErrorCode: 404
|
Loading…
Reference in New Issue
Block a user