Skip to content

Commit

Permalink
Merge branch '5.0' into 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 5, 2023
2 parents 2799ef3 + 7e42058 commit 332898f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -2641,8 +2641,10 @@ public function onAfterRevertToLive()

// Need to update pages linking to this one as no longer broken
foreach ($stageSelf->DependentPages() as $page) {
/** @var SiteTree $page */
$page->writeWithoutVersion();
if ($page->hasExtension(Versioned::class)) {
/** @var Versioned $page */
$page->writeWithoutVersion();
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestController;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild;
use SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject;
use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTest;
use SilverStripe\Control\ContentNegotiator;
use SilverStripe\Control\Controller;
Expand Down Expand Up @@ -67,6 +68,7 @@ class SiteTreeTest extends SapphireTest
SiteTreeTest_DataObject::class,
PageWithChild::class,
BelongsToPage::class,
NotPageObject::class,
];

public function reservedSegmentsProvider()
Expand Down Expand Up @@ -2112,4 +2114,23 @@ public function provideSanitiseExtraMeta(): array
],
];
}

public function testOnAfterRevertToLive()
{
// Create new page and publish it
$page = SiteTree::create();
$page->Content = 'Test content';
$id = $page->write();
$page->publishRecursive();

// Add link to non-page object
/** @var NotPageObject $obj */
$obj = $this->objFromFixture(NotPageObject::class, 'object1');
$obj->Content = '<a href="[sitetree_link,id='. $id .']">Link to Page</a>';
$obj->write();

//Test that method doesn't throw exception
$this->expectNotToPerformAssertions();
$page->onAfterRevertToLive();
}
}
4 changes: 4 additions & 0 deletions tests/php/Model/SiteTreeTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ SilverStripe\CMS\Tests\Model\SiteTreeTest_DataObject:
relations:
Title: 'Linked DataObject'
Pages: =>SilverStripe\CMS\Model\SiteTree.home,=>SilverStripe\CMS\Model\SiteTree.about,=>SilverStripe\CMS\Model\SiteTree.staff

SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject:
object1:
Content: 'Everything will be ok'

0 comments on commit 332898f

Please sign in to comment.