Skip to content

Commit

Permalink
FIX Ensure no admin routed links are affected by versioning (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Nov 19, 2024
1 parent a7e5891 commit ed42fa1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/VersionedStateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
17 changes: 12 additions & 5 deletions tests/php/VersionedStateExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ed42fa1

Please sign in to comment.