From ae412c1aceddaf4e26cc0d4890f15d574c0b5c04 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 14 Nov 2024 15:11:03 +1300 Subject: [PATCH] FIX Ensure no admin routed links are affected by versioning --- src/VersionedStateExtension.php | 4 ++-- tests/php/VersionedStateExtensionTest.php | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/VersionedStateExtension.php b/src/VersionedStateExtension.php index 98dd1a12..4c6acddb 100644 --- a/src/VersionedStateExtension.php +++ b/src/VersionedStateExtension.php @@ -2,7 +2,7 @@ namespace SilverStripe\Versioned; -use SilverStripe\Admin\LeftAndMain; +use SilverStripe\Admin\AdminController; use SilverStripe\Control\Controller; use SilverStripe\Control\RequestHandler; use SilverStripe\Core\Extension; @@ -51,7 +51,7 @@ protected function updateLink(&$link) } // Don't touch Admin/CMS links - if (class_exists(LeftAndMain::class) && $this->getOwner() instanceof LeftAndMain) { + if (class_exists(AdminController::class) && $this->getOwner() instanceof AdminController) { return; } diff --git a/tests/php/VersionedStateExtensionTest.php b/tests/php/VersionedStateExtensionTest.php index cc53a010..e14c94fc 100644 --- a/tests/php/VersionedStateExtensionTest.php +++ b/tests/php/VersionedStateExtensionTest.php @@ -2,7 +2,11 @@ namespace SilverStripe\Versioned\Tests; +use SilverStripe\Admin\AdminController; use SilverStripe\Admin\LeftAndMain; +use SilverStripe\Control\HTTPRequest; +use SilverStripe\Control\Session; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\VersionedStateExtension; @@ -63,18 +67,21 @@ public function testUpdateLinkRespectsQueryArgs() $this->assertEquals('item/myobject', $obj1Live->Link()); } - public function testDontUpdateLeftAndMainLinks() + public function testDontUpdateAdminLinks() { - if (!class_exists(LeftAndMain::class)) { - $this->markTestSkipped('silverstripe/cms not installed'); + if (!class_exists(AdminController::class)) { + $this->markTestSkipped('silverstripe/admin not installed'); return; } + $request = new HTTPRequest('', ''); + $request->setSession(new Session([])); + Injector::inst()->registerService($request, HTTPRequest::class); $controller = new LeftAndMain(); - $liveClientConfig = $controller->getClientConfig(); + $liveClientConfig = $controller->getCombinedClientConfig(); Versioned::set_stage(Versioned::DRAFT); - $stageClientConfig = $controller->getClientConfig(); + $stageClientConfig = $controller->getCombinedClientConfig(); $this->assertEquals( $liveClientConfig,