diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 4bf70e73c..56a6f2791 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -1391,9 +1391,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $this->HasBrokenLink = false; $this->HasBrokenFile = false; - $formFields = $this->getCMSFields(null); foreach($htmlFields as $field) { - $formField = $formFields->dataFieldByName($field); + $formField = new HTMLEditorField($field); $formField->setValue($this->$field); $formField->saveInto($this); } @@ -2040,7 +2039,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @uses SiteTreeDecorator->onAfterUnpublish() */ function doUnpublish() { - if(!$this->canDeleteFromLive()) return false; + if(!$this->canDeleteFromLive()) return false; if(!$this->ID) return false; $this->extend('onBeforeUnpublish'); diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index 2b50bda16..6960aea90 100755 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -71,9 +71,6 @@ class HtmlEditorField extends TextareaField { $linkedPages = array(); $linkedFiles = array(); - $record->HasBrokenFile = false; - $record->HasBrokenLink = false; - $htmlValue = new SS_HTMLValue($this->value); // Populate link tracking for internal links & links to asset files. @@ -89,13 +86,18 @@ class HtmlEditorField extends TextareaField { $link->setAttribute('class', preg_replace('/(^ss-broken|ss-broken$| ss-broken )/', null, $class)); } - if($page = DataObject::get_by_id('SiteTree', $ID)) { - $linkedPages[] = $page->ID; + $linkedPages[] = $ID; + if(!DataObject::get_by_id('SiteTree', $ID)) $record->HasBrokenLink = true; + + } else if(substr($href, 0, strlen(ASSETS_DIR) + 1) == ASSETS_DIR.'/') { + $candidateFile = File::find(Convert::raw2sql(urldecode($href))); + if($candidateFile) { + $linkedFiles[] = $candidateFile->ID; } else { - $record->HasBrokenLink = true; + $record->HasBrokenFile = true; } - } elseif($href[0] != '/' && $file = File::find($href)) { - $linkedFiles[] = $file->ID; + } else if($href == '' || $href[0] == '/') { + $record->HasBrokenLink = true; } } } @@ -142,7 +144,9 @@ class HtmlEditorField extends TextareaField { DB::query("DELETE FROM \"$tracker->tableName\" WHERE $filter"); if($linkedPages) foreach($linkedPages as $item) { - $tracker->add($item, array('FieldName' => $this->name)); + $SQL_fieldName = Convert::raw2sql($this->name); + DB::query("INSERT INTO \"SiteTree_LinkTracking\" (\"SiteTreeID\",\"ChildID\", \"FieldName\") + VALUES ($record->ID, $item, '$SQL_fieldName')"); } } diff --git a/tests/ClassInfoTest.php b/tests/ClassInfoTest.php index 73307b9f3..81ba1dd8f 100644 --- a/tests/ClassInfoTest.php +++ b/tests/ClassInfoTest.php @@ -23,7 +23,7 @@ class ClassInfoTest extends SapphireTest { $classes = ClassInfo::classes_for_folder('sapphire/tests'); $this->assertContains( - 'ClassInfoTest', + 'classinfotest', $classes, 'ClassInfo::classes_for_folder() returns classes matching the filename' ); diff --git a/tests/ManifestBuilderTest.php b/tests/ManifestBuilderTest.php index 5702917fa..88587daa3 100644 --- a/tests/ManifestBuilderTest.php +++ b/tests/ManifestBuilderTest.php @@ -9,8 +9,8 @@ class ManifestBuilderTest extends SapphireTest { $manifestInfo = ManifestBuilder::get_manifest_info($baseFolder); global $project; - $this->assertEquals("$baseFolder/sapphire/MyClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['MyClass']); - $this->assertEquals("$baseFolder/sapphire/subdir/SubDirClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['SubDirClass']); + $this->assertEquals("$baseFolder/sapphire/MyClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['myclass']); + $this->assertEquals("$baseFolder/sapphire/subdir/SubDirClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['subdirclass']); $this->assertNotContains('OtherFile', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertContains('MyClass', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); @@ -38,12 +38,12 @@ class ManifestBuilderTest extends SapphireTest { $manifestInfo = ManifestBuilder::get_manifest_info($baseFolder); /* Our fixture defines the class MyClass_InComment inside a comment, so it shouldn't be included in the class manifest. */ - $this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); + $this->assertNotContains('myclass_incomment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); $this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents'])); /* Our fixture defines the class MyClass_InSlashSlashComment inside a //-style comment, so it shouldn't be included in the class manifest. */ - $this->assertNotContains('MyClass_InSlashSlashComment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); + $this->assertNotContains('myclass_inslashslashcomment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InSlashSlashComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); $this->assertNotContains('MyClass_InSlashSlashComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents'])); } @@ -53,17 +53,17 @@ class ManifestBuilderTest extends SapphireTest { $manifestInfo = ManifestBuilder::get_manifest_info($baseFolder); /* If a class defintion is listed in a single quote string, then it shouldn't be inlcuded. Here we have put a class definition for MyClass_InSingleQuoteString inside a single-quoted string */ - $this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); + $this->assertNotContains('myclass_insinglequotestring', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); $this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents'])); /* Ditto for double quotes. Here we have put a class definition for MyClass_InDoubleQuoteString inside a double-quoted string. */ - $this->assertNotContains('MyClass_InDoubleQuoteString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); + $this->assertNotContains('myclass_indoublequotestring', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InDoubleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); $this->assertNotContains('MyClass_InDoubleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents'])); /* Finally, we need to ensure that class definitions inside heredoc strings aren't included. Here, we have defined the class MyClass_InHeredocString inside a heredoc string. */ - $this->assertNotContains('MyClass_InHeredocString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); + $this->assertNotContains('myclass_inheredocstring', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InHeredocString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); $this->assertNotContains('MyClass_InHeredocString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents'])); } diff --git a/tests/SiteTreeBrokenLinksTest.php b/tests/SiteTreeBrokenLinksTest.php index 9e0416c36..20d744963 100644 --- a/tests/SiteTreeBrokenLinksTest.php +++ b/tests/SiteTreeBrokenLinksTest.php @@ -21,11 +21,11 @@ class SiteTreeBrokenLinksTest extends SapphireTest { function testBrokenLinksBetweenPages() { $obj = $this->objFromFixture('Page','content'); - $obj->Content = 'this is a broken link'; + $obj->Content = 'this is a broken link'; $obj->syncLinkTracking(); $this->assertTrue($obj->HasBrokenLink, 'Page has a broken link'); - $obj->Content = 'this is not a broken link'; + $obj->Content = 'this is not a broken link'; $obj->syncLinkTracking(); $this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link'); } @@ -107,10 +107,11 @@ class SiteTreeBrokenLinksTest extends SapphireTest { $linkDest->doPublish(); $linkSrc = $this->objFromFixture('Page','content'); - $linkSrc->Content = "
"; + $linkSrc->Content = ""; $linkSrc->write(); + $linkSrc->doPublish(); - + // Confirm no broken link $this->assertEquals(0, (int)$linkSrc->HasBrokenLink); $this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" @@ -150,7 +151,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest { $linkDest->doDeleteFromLive(); $linkSrc = $this->objFromFixture('Page','content'); - $linkSrc->Content = ""; + $linkSrc->Content = ""; $linkSrc->write(); // Publish the source of the link, while the dest is still unpublished. @@ -174,7 +175,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest { // Content links are one kind of link to pages $p2 = new Page(); $p2->Title = "regular link"; - $p2->Content = "Link()) . "\">test"; + $p2->Content = "ID]\">test"; $p2->write(); $this->assertTrue($p2->doPublish()); @@ -249,7 +250,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest { // Content links are one kind of link to pages $p2 = new Page(); $p2->Title = "regular link"; - $p2->Content = "Link()) . "\">test"; + $p2->Content = "ID]\">test"; $p2->write(); $this->assertTrue($p2->doPublish()); diff --git a/tests/forms/HtmlEditorFieldTest.php b/tests/forms/HtmlEditorFieldTest.php index b11df51f2..3e07fc03c 100755 --- a/tests/forms/HtmlEditorFieldTest.php +++ b/tests/forms/HtmlEditorFieldTest.php @@ -151,6 +151,7 @@ class HtmlEditorFieldTest extends FunctionalTest { '', $this->idFromFixture('SiteTree', 'home') )); + $sitetree->HasBrokenLink = false; $editor->saveInto($sitetree); $this->assertFalse((bool) $sitetree->HasBrokenLink);