diff --git a/code/Model/SiteTreeLinkTracking_Parser.php b/code/Model/SiteTreeLinkTracking_Parser.php
index 7066ad7f..c4321303 100644
--- a/code/Model/SiteTreeLinkTracking_Parser.php
+++ b/code/Model/SiteTreeLinkTracking_Parser.php
@@ -1,6 +1,7 @@
hasAttribute('href')) {
continue;
}
- $href = Director::makeRelative($link->getAttribute('href'));
+ $href = $link->getAttribute('href');
+ if (Director::is_site_url($href)) {
+ $href = Director::makeRelative($href);
+ }
// Definitely broken links.
if ($href == '' || $href[0] == '/') {
diff --git a/tests/php/Model/SiteTreeLinkTrackingTest.php b/tests/php/Model/SiteTreeLinkTrackingTest.php
index 8363af52..8507e644 100644
--- a/tests/php/Model/SiteTreeLinkTrackingTest.php
+++ b/tests/php/Model/SiteTreeLinkTrackingTest.php
@@ -4,12 +4,18 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\CMS\Model\SiteTreeLinkTracking_Parser;
use SilverStripe\Assets\File;
+use SilverStripe\Control\Director;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\Parsers\HTMLValue;
use Page;
class SiteTreeLinkTrackingTest extends SapphireTest
{
+ protected function setUp()
+ {
+ parent::setUp();
+ Director::config()->set('alternate_base_url', 'http://www.mysite.com/');
+ }
protected function isBroken($content)
{
@@ -25,12 +31,24 @@ class SiteTreeLinkTrackingTest extends SapphireTest
public function testParser()
{
+ // Shortcodes
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
+
+ // Relative urls
$this->assertTrue($this->isBroken('link'));
$this->assertTrue($this->isBroken('link'));
+ // Non-shortcodes, assume non-broken without due reason
+ $this->assertFalse($this->isBroken('link'));
+ $this->assertFalse($this->isBroken('link'));
+
+ // Absolute urls
+ $this->assertFalse($this->isBroken('link'));
+ $this->assertFalse($this->isBroken('link'));
+
+ // Anchors
$this->assertFalse($this->isBroken('anchor'));
$this->assertFalse($this->isBroken('anchor'));
$this->assertTrue($this->isBroken('anchor'));