FIX Unsaved SiteTree records now return an empty list for DependentPages

This commit is contained in:
Robbie Averill 2018-11-28 13:44:52 +01:00
parent 309dc97a32
commit 0bb22732c9
2 changed files with 13 additions and 1 deletions

View File

@ -1779,7 +1779,12 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
}
// Content links
$items = new ArrayList();
$items = ArrayList::create();
// If the record hasn't been written yet, it cannot be depended on yet
if (!$this->isInDB()) {
return $items;
}
// We merge all into a regular SS_List, because DataList doesn't support merge
if ($contentLinks = $this->BackLinkTracking()) {

View File

@ -1576,4 +1576,11 @@ class SiteTreeTest extends SapphireTest
$title = $siteTree->getTreeTitle();
$this->assertNotNull($title);
}
public function testDependentPagesOnUnsavedRecord()
{
$record = new SiteTree();
$pages = $record->DependentPages();
$this->assertCount(0, $pages, 'Unsaved pages should have no dependent pages');
}
}