Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ensure no admin routed links are affected by versioning #481

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Comment on lines -75 to +82
Copy link
Member Author

@GuySartorelli GuySartorelli Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using getCombinedClientConfig instead of getClientConfig to expand the breadth of the test. This should have been picked up back in silverstripe/silverstripe-admin#1761 but wasn't because the test wasn't looking wide enough.

Note this expansion is also why we now need a request with a session above.

Versioned::set_stage(Versioned::DRAFT);
$stageClientConfig = $controller->getClientConfig();
$stageClientConfig = $controller->getCombinedClientConfig();

$this->assertEquals(
$liveClientConfig,
Expand Down
Loading