-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Use get_one_by_stage when fetching SiteTree for a specific stage
- Loading branch information
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
namespace SilverStripe\VersionedAdmin\Tests\Controllers; | ||
|
||
use SilverStripe\VersionedAdmin\Tests\Controller\HistoryControllerFactory\HistoryControllerFactoryExtension; | ||
use SilverStripe\CMS\Controllers\CMSPageHistoryController; | ||
use SilverStripe\CMS\Model\SiteTree; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\VersionedAdmin\Controllers\CMSPageHistoryViewerController; | ||
use SilverStripe\VersionedAdmin\Controllers\HistoryControllerFactory; | ||
|
||
class HistoryControllerFactoryTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'HistoryControllerFactoryTest.yml'; | ||
|
||
protected static $illegal_extensions = [ | ||
HistoryControllerFactory::class => '*' | ||
]; | ||
|
||
protected static $required_extensions = [ | ||
HistoryControllerFactory::class => [HistoryControllerFactoryExtension::class] | ||
]; | ||
|
||
public function testCreateController() | ||
{ | ||
$factory = new HistoryControllerFactory; | ||
|
||
$controller = $factory->create(null); | ||
$this->assertInstanceOf(CMSPageHistoryController::class, $controller); | ||
|
||
$id = $this->idFromFixture(SiteTree::class, 'page_one'); | ||
|
||
$mockRequest = new HTTPRequest('GET', ''); | ||
$mockRequest->setRouteParams(['ID' => $id]); | ||
Injector::inst()->registerService($mockRequest); | ||
|
||
$controller = $factory->create(null); | ||
$this->assertInstanceOf(CMSPageHistoryController::class, $controller); | ||
|
||
$id = $this->idFromFixture(SiteTree::class, 'page_two'); | ||
|
||
$mockRequest = new HTTPRequest('GET', ''); | ||
$mockRequest->setRouteParams(['ID' => $id]); | ||
Injector::inst()->registerService($mockRequest); | ||
|
||
$controller = $factory->create(null); | ||
$this->assertInstanceOf(CMSPageHistoryViewerController::class, $controller); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SilverStripe\CMS\Model\SiteTree: | ||
page_one: | ||
Title: 1 | ||
URLSegment: page-one | ||
Content: <p>Hello world!</p> | ||
page_two: | ||
Title: 2 | ||
URLSegment: page-two | ||
Content: <p>Hello world!</p> |
14 changes: 14 additions & 0 deletions
14
tests/Controllers/HistoryControllerFactoryTest/HistoryControllerFactoryExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace SilverStripe\VersionedAdmin\Tests\Controller\HistoryControllerFactory; | ||
|
||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Dev\TestOnly; | ||
|
||
class HistoryControllerFactoryExtension extends Extension implements TestOnly | ||
{ | ||
public function updateIsEnabled($record) | ||
{ | ||
// Only "enable" for the second fixture (from HistoryControllerFactoryTest.yml) | ||
return $record->Title === '2'; | ||
} | ||
} |