-
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.
Merge pull request #334 from creative-commoners/pulls/2.2/add-tests-d…
…orestore MNT New test cases for doRestore button
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@javascript | ||
Feature: Restore to draft | ||
As a CMS author | ||
I want to restore archived version to draft | ||
|
||
Background: | ||
Given a "page" "Home" | ||
And a "page" "MyPage" | ||
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Archive' section" | ||
And I am logged in as a member of "EDITOR" group | ||
And I go to "/admin/pages" | ||
And I should see "MyPage" | ||
And I click on "MyPage" in the tree | ||
And I press the "Publish" button | ||
And I click "More options" in the "#ActionMenus" element | ||
And I press the "Unpublish and archive" button, confirming the dialog | ||
|
||
Scenario: I can restore archived version to draft | ||
When I go to "/admin/archive" | ||
Then I should see "MyPage" in the "#Form_EditForm" element | ||
Then I click "MyPage" in the "#Form_EditForm" element | ||
Then I press the "Restore to draft" button | ||
Then I should see "Successfully restored the page" in the "#Form_EditForm" element | ||
When I go to "/admin/pages" | ||
And I should see "MyPage" in the ".cms-tree [data-pagetype='Page']:nth-of-type(2).status-addedtodraft" element |
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,86 @@ | ||
<?php | ||
|
||
namespace SilverStripe\VersionedAdmin\Tests\Extensions; | ||
|
||
use SilverStripe\VersionedAdmin\Tests\Extensions\Controller\TestController; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Control\HTTPResponse; | ||
use SilverStripe\Control\Session; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Forms\FormAction; | ||
use SilverStripe\Forms\GridField\GridField; | ||
use SilverStripe\Forms\GridField\GridFieldConfig_Base; | ||
use SilverStripe\Forms\GridField\GridFieldDetailForm; | ||
use SilverStripe\ORM\ArrayList; | ||
use SilverStripe\View\ArrayData; | ||
use SilverStripe\Versioned\VersionedGridFieldItemRequest; | ||
use SilverStripe\VersionedAdmin\ArchiveAdmin; | ||
use SilverStripe\VersionedAdmin\Tests\Controllers\HistoryViewerControllerTest\ViewableVersionedObject; | ||
|
||
class ArchiveRestoreActionTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'ArchiveRestoreActionTest.yml'; | ||
|
||
protected static $extra_dataobjects = [ | ||
ViewableVersionedObject::class, | ||
]; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->logInWithPermission('ADMIN'); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$this->logOut(); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testDoRestore() | ||
{ | ||
$object = $this->objFromFixture(ViewableVersionedObject::class, 'object_1'); | ||
$gridField = GridField::create('Test', 'Test', ArrayList::create(), GridFieldConfig_Base::create()); | ||
$gridField->setModelClass(ViewableVersionedObject::class); | ||
$controller = TestController::create(ViewableVersionedObject::class); | ||
$controller->setRequest(new HTTPRequest('GET', '/')); | ||
$controller->getRequest()->setSession(new Session([])); | ||
$form = Form::create($controller, 'TestForm', FieldList::create()); | ||
|
||
$itemRequest = VersionedGridFieldItemRequest::create( | ||
$gridField, | ||
$form, | ||
$object, | ||
$controller, | ||
'test' | ||
); | ||
$object->doArchive(); | ||
|
||
$response = $itemRequest->doRestore([], $form); | ||
$this->assertEquals($response->getStatusCode(), '302', 'Redirect status code should be 302'); | ||
} | ||
|
||
public function testUpdateItemEditForm() | ||
{ | ||
$object = $this->objFromFixture(ViewableVersionedObject::class, 'object_1'); | ||
$gridField = GridField::create('Test', 'Test', ArrayList::create(), GridFieldConfig_Base::create()); | ||
$controller = TestController::create(ViewableVersionedObject::class); | ||
$controller->setRequest(new HTTPRequest('GET', '/')); | ||
$controller->getRequest()->setSession(new Session([])); | ||
$form = Form::create($controller, 'TestForm', FieldList::create()); | ||
|
||
$itemRequest = VersionedGridFieldItemRequest::create( | ||
$gridField, | ||
$form, | ||
$object, | ||
$controller, | ||
'test' | ||
); | ||
|
||
$itemRequest->updateItemEditForm($form); | ||
$actions = $form->Actions(); | ||
$this->assertInstanceOf(FormAction::class, $actions->fieldByName('action_doRestore')); | ||
} | ||
} |
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,3 @@ | ||
SilverStripe\VersionedAdmin\Tests\Controllers\HistoryViewerControllerTest\ViewableVersionedObject: | ||
object_1: | ||
Title: My Object |
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,18 @@ | ||
<?php | ||
|
||
namespace SilverStripe\VersionedAdmin\Tests\Extensions\Controller; | ||
|
||
use SilverStripe\VersionedAdmin\ArchiveAdmin; | ||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\VersionedAdmin\Tests\Controllers\HistoryViewerControllerTest\ViewableVersionedObject; | ||
|
||
class TestController extends ArchiveAdmin implements TestOnly | ||
{ | ||
private static $url_segment = 'test-archive'; | ||
|
||
public function __construct($modelClass) | ||
{ | ||
parent::__construct(); | ||
$this->modelClass = $modelClass; | ||
} | ||
} |