mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-09-30 05:09:07 +02:00
Merge pull request #1297 from patricknelson/issue-586-delete-validation-3.2
FIX for #586 and possible fix for #736 and relates to #2449: Don't perform validation upon deletion, since it isn't necessary.
This commit is contained in:
commit
bc669311dd
@ -593,7 +593,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @param FieldList $fields
|
* @param FieldList $fields
|
||||||
* @return Form
|
* @return CMSForm
|
||||||
*/
|
*/
|
||||||
public function getEditForm($id = null, $fields = null) {
|
public function getEditForm($id = null, $fields = null) {
|
||||||
|
|
||||||
@ -676,7 +676,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
// if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
// if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
||||||
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
|
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
|
||||||
// Set validation exemptions for specific actions
|
// Set validation exemptions for specific actions
|
||||||
$form->setValidationExemptActions(array('restore', 'revert', 'deletefromlive', 'rollback'));
|
$form->setValidationExemptActions(array('restore', 'revert', 'deletefromlive', 'delete', 'unpublish', 'rollback'));
|
||||||
|
|
||||||
// Announce the capability so the frontend can decide whether to allow preview or not.
|
// Announce the capability so the frontend can decide whether to allow preview or not.
|
||||||
if(in_array('CMSPreviewable', class_implements($record))) {
|
if(in_array('CMSPreviewable', class_implements($record))) {
|
||||||
|
@ -62,7 +62,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$pageB->write();
|
$pageB->write();
|
||||||
|
|
||||||
// Check query
|
// Check query
|
||||||
$response = $this->get('CMSMain/childfilter?ParentID='.$pageA->ID);
|
$response = $this->get('CMSMain/childfilter?ParentID=' . $pageA->ID);
|
||||||
$children = json_decode($response->getBody());
|
$children = json_decode($response->getBody());
|
||||||
$this->assertFalse($response->isError());
|
$this->assertFalse($response->isError());
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
|
|
||||||
// Some modules (e.g., cmsworkflow) will remove this action
|
// Some modules (e.g., cmsworkflow) will remove this action
|
||||||
$actions = CMSBatchActionHandler::config()->batch_actions;
|
$actions = CMSBatchActionHandler::config()->batch_actions;
|
||||||
if(isset($actions['publish'])) {
|
if (isset($actions['publish'])) {
|
||||||
$response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', array($page1->ID, $page2->ID)));
|
$response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', array($page1->ID, $page2->ID)));
|
||||||
$responseData = Convert::json2array($response->getBody());
|
$responseData = Convert::json2array($response->getBody());
|
||||||
$this->assertArrayHasKey($page1->ID, $responseData['modified']);
|
$this->assertArrayHasKey($page1->ID, $responseData['modified']);
|
||||||
@ -160,10 +160,10 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$classes = ClassInfo::subclassesFor("SiteTree");
|
$classes = ClassInfo::subclassesFor("SiteTree");
|
||||||
array_shift($classes);
|
array_shift($classes);
|
||||||
|
|
||||||
foreach($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
$page = new $class();
|
$page = new $class();
|
||||||
if($page instanceof TestOnly) continue;
|
if ($page instanceof TestOnly) continue;
|
||||||
if(!$page->stat('can_be_root')) continue;
|
if (!$page->stat('can_be_root')) continue;
|
||||||
|
|
||||||
$page->Title = "Test $class page";
|
$page->Title = "Test $class page";
|
||||||
$page->write();
|
$page->write();
|
||||||
@ -178,8 +178,8 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
|
|
||||||
Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true);
|
Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true);
|
||||||
$parentPage = $this->objFromFixture('Page','page3');
|
$parentPage = $this->objFromFixture('Page', 'page3');
|
||||||
$childPage = $this->objFromFixture('Page','page1');
|
$childPage = $this->objFromFixture('Page', 'page1');
|
||||||
|
|
||||||
$parentPage->doUnpublish();
|
$parentPage->doUnpublish();
|
||||||
$childPage->doUnpublish();
|
$childPage->doUnpublish();
|
||||||
@ -200,7 +200,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
||||||
|
|
||||||
// Set up a page that is delete from live
|
// Set up a page that is delete from live
|
||||||
$page = $this->objFromFixture('Page','page1');
|
$page = $this->objFromFixture('Page', 'page1');
|
||||||
$pageID = $page->ID;
|
$pageID = $page->ID;
|
||||||
$page->doPublish();
|
$page->doPublish();
|
||||||
$page->delete();
|
$page->delete();
|
||||||
@ -222,7 +222,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
*/
|
*/
|
||||||
public function testGetRecord() {
|
public function testGetRecord() {
|
||||||
// Set up a page that is delete from live
|
// Set up a page that is delete from live
|
||||||
$page1 = $this->objFromFixture('Page','page1');
|
$page1 = $this->objFromFixture('Page', 'page1');
|
||||||
$page1ID = $page1->ID;
|
$page1ID = $page1->ID;
|
||||||
$page1->doPublish();
|
$page1->doPublish();
|
||||||
$page1->delete();
|
$page1->delete();
|
||||||
@ -235,7 +235,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
|
|
||||||
// Pages that are on draft and aren't on draft should both work
|
// Pages that are on draft and aren't on draft should both work
|
||||||
$this->assertInstanceOf('Page', $cmsMain->getRecord($page1ID));
|
$this->assertInstanceOf('Page', $cmsMain->getRecord($page1ID));
|
||||||
$this->assertInstanceOf('Page', $cmsMain->getRecord($this->idFromFixture('Page','page2')));
|
$this->assertInstanceOf('Page', $cmsMain->getRecord($this->idFromFixture('Page', 'page2')));
|
||||||
|
|
||||||
// This functionality isn't actually used any more.
|
// This functionality isn't actually used any more.
|
||||||
$newPage = $cmsMain->getRecord('new-Page-5');
|
$newPage = $cmsMain->getRecord('new-Page-5');
|
||||||
@ -251,7 +251,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$this->assertEquals(200, $result->getStatusCode());
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreationOfTopLevelPage(){
|
public function testCreationOfTopLevelPage() {
|
||||||
$origFollow = $this->autoFollowRedirection;
|
$origFollow = $this->autoFollowRedirection;
|
||||||
$this->autoFollowRedirection = false;
|
$this->autoFollowRedirection = false;
|
||||||
|
|
||||||
@ -295,14 +295,14 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
|
|
||||||
$location = $response->getHeader('X-ControllerURL');
|
$location = $response->getHeader('X-ControllerURL');
|
||||||
$this->assertNotEmpty($location, 'Must be a redirect on success');
|
$this->assertNotEmpty($location, 'Must be a redirect on success');
|
||||||
$this->assertContains('/show/',$location, 'Must redirect to /show/ the new page');
|
$this->assertContains('/show/', $location, 'Must redirect to /show/ the new page');
|
||||||
// TODO Logout
|
// TODO Logout
|
||||||
$this->session()->inst_set('loggedInAs', NULL);
|
$this->session()->inst_set('loggedInAs', NULL);
|
||||||
|
|
||||||
$this->autoFollowRedirection = $origFollow;
|
$this->autoFollowRedirection = $origFollow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreationOfRestrictedPage(){
|
public function testCreationOfRestrictedPage() {
|
||||||
$origFollow = $this->autoFollowRedirection;
|
$origFollow = $this->autoFollowRedirection;
|
||||||
$this->autoFollowRedirection = false;
|
$this->autoFollowRedirection = false;
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$id = 'new-Member-0';
|
$id = 'new-Member-0';
|
||||||
$member = $controller->getNewItem($id, false);
|
$member = $controller->getNewItem($id, false);
|
||||||
$this->fail('Should not be able to create a Member object');
|
$this->fail('Should not be able to create a Member object');
|
||||||
} catch(SS_HTTPResponse_Exception $e) {
|
} catch (SS_HTTPResponse_Exception $e) {
|
||||||
$this->assertEquals($controller->getResponse()->getStatusCode(), 302);
|
$this->assertEquals($controller->getResponse()->getStatusCode(), 302);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -465,6 +465,25 @@ class CMSMainTest extends FunctionalTest {
|
|||||||
$pages->column('Title')
|
$pages->column('Title')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing retrieval and type of CMS edit form.
|
||||||
|
*/
|
||||||
|
public function testGetEditForm() {
|
||||||
|
// Login is required prior to accessing a CMS form.
|
||||||
|
$this->loginWithPermission('ADMIN');
|
||||||
|
|
||||||
|
// Get a associated with a fixture page.
|
||||||
|
$page = $this->objFromFixture('Page', 'page1');
|
||||||
|
$controller = new CMSMain();
|
||||||
|
$form = $controller->getEditForm($page->ID);
|
||||||
|
$this->assertInstanceOf("CMSForm", $form);
|
||||||
|
|
||||||
|
// Ensure that the form will not "validate" on delete or "unpublish" actions.
|
||||||
|
$exemptActions = $form->getValidationExemptActions();
|
||||||
|
$this->assertContains("delete", $exemptActions);
|
||||||
|
$this->assertContains("unpublish", $exemptActions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CMSMainTest_ClassA extends Page implements TestOnly {
|
class CMSMainTest_ClassA extends Page implements TestOnly {
|
||||||
|
Loading…
Reference in New Issue
Block a user