-
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.
MNT New test cases for doRestore button
- Loading branch information
Sabina Talipova
committed
Apr 11, 2024
1 parent
4ea609d
commit c2d776f
Showing
4 changed files
with
154 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,47 @@ | ||
@javascript | ||
Feature: Restore to draft | ||
As a CMS author | ||
I want to restore archived version to draft | ||
|
||
Background: | ||
Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class | ||
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 | ||
|
||
Scenario: I can restore archived page to draft version | ||
When I click "More options" in the "#ActionMenus" element | ||
And I press the "Unpublish and archive" button, confirming the dialog | ||
And I go to "/admin/archive" | ||
Then I should see "MyPage" in the "#Form_EditForm" element | ||
And I click "MyPage" in the "#Form_EditForm" element | ||
And 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'].status-addedtodraft" element | ||
|
||
Scenario: I can restore archived elemental block to draft version | ||
When I press the "Add block" button | ||
Then I click on the ".font-icon-block-content" element | ||
Then I should see "Untitled Content block" in the ".element-editor__element" element | ||
And I click on the ".element-editor__element" element | ||
And I fill in "Form_ElementForm_1_Title" with "MyBlock" | ||
When I press the "View actions" button | ||
And I press the "Publish" button | ||
And I wait 1 second | ||
Then I should see a "Published 'Untitled Content block' successfully" success toast | ||
And I press the "View actions" button | ||
And I click on the ".element-editor__actions-archive" element, confirming the dialog | ||
And I go to "/admin/archive" | ||
Then I click "Block" in the ".ui-tabs-nav" element | ||
And I should see "MyBlock" in the "#Form_EditForm" element | ||
Then I click "MyBlock" in the "#Form_EditForm" element | ||
When I press the "Restore to draft" button | ||
Then I should see "Successfully restored the content block" in the "#Form_EditForm" element | ||
And I go to "/admin/pages" | ||
And I click on "MyPage" in the tree | ||
Then I should see "Draft" in the ".element-editor__element" 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; | ||
} | ||
} |