diff --git a/tests/Behat/features/restore-to-draft.feature b/tests/Behat/features/restore-to-draft.feature new file mode 100644 index 00000000..6abf1cc4 --- /dev/null +++ b/tests/Behat/features/restore-to-draft.feature @@ -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 diff --git a/tests/Extensions/ArchiveRestoreActionTest.php b/tests/Extensions/ArchiveRestoreActionTest.php new file mode 100644 index 00000000..6ea5dc07 --- /dev/null +++ b/tests/Extensions/ArchiveRestoreActionTest.php @@ -0,0 +1,86 @@ +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')); + } +} diff --git a/tests/Extensions/ArchiveRestoreActionTest.yml b/tests/Extensions/ArchiveRestoreActionTest.yml new file mode 100644 index 00000000..5f074df5 --- /dev/null +++ b/tests/Extensions/ArchiveRestoreActionTest.yml @@ -0,0 +1,3 @@ +SilverStripe\VersionedAdmin\Tests\Controllers\HistoryViewerControllerTest\ViewableVersionedObject: + object_1: + Title: My Object diff --git a/tests/Extensions/Controller/TestController.php b/tests/Extensions/Controller/TestController.php new file mode 100644 index 00000000..6afa5ede --- /dev/null +++ b/tests/Extensions/Controller/TestController.php @@ -0,0 +1,18 @@ +modelClass = $modelClass; + } +}