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:
Damian Mooyman 2015-10-16 17:18:16 +13:00
commit bc669311dd
2 changed files with 143 additions and 124 deletions

View File

@ -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))) {

View File

@ -6,9 +6,9 @@
class CMSMainTest extends FunctionalTest { class CMSMainTest extends FunctionalTest {
protected static $fixture_file = 'CMSMainTest.yml'; protected static $fixture_file = 'CMSMainTest.yml';
static protected $orig = array(); static protected $orig = array();
function testSiteTreeHints() { function testSiteTreeHints() {
$cache = SS_Cache::factory('CMSMain_SiteTreeHints'); $cache = SS_Cache::factory('CMSMain_SiteTreeHints');
// Login as user with root creation privileges // Login as user with root creation privileges
@ -27,60 +27,60 @@ class CMSMainTest extends FunctionalTest {
$this->assertArrayHasKey('All', $hints); $this->assertArrayHasKey('All', $hints);
$this->assertArrayHasKey( $this->assertArrayHasKey(
'CMSMainTest_ClassA', 'CMSMainTest_ClassA',
$hints['All'], $hints['All'],
'Global list shows allowed classes' 'Global list shows allowed classes'
); );
$this->assertArrayNotHasKey( $this->assertArrayNotHasKey(
'CMSMainTest_HiddenClass', 'CMSMainTest_HiddenClass',
$hints['All'], $hints['All'],
'Global list does not list hidden classes' 'Global list does not list hidden classes'
); );
$this->assertNotContains( $this->assertNotContains(
'CMSMainTest_ClassA', 'CMSMainTest_ClassA',
$hints['Root']['disallowedChildren'], $hints['Root']['disallowedChildren'],
'Limits root classes' 'Limits root classes'
); );
$this->assertContains( $this->assertContains(
'CMSMainTest_NotRoot', 'CMSMainTest_NotRoot',
$hints['Root']['disallowedChildren'], $hints['Root']['disallowedChildren'],
'Limits root classes' 'Limits root classes'
); );
} }
public function testChildFilter() { public function testChildFilter() {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
// Check page A // Check page A
$pageA = new CMSMainTest_ClassA(); $pageA = new CMSMainTest_ClassA();
$pageA->write(); $pageA->write();
$pageB = new CMSMainTest_ClassB(); $pageB = new CMSMainTest_ClassB();
$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());
// Page A can't have unrelated children // Page A can't have unrelated children
$this->assertContains( $this->assertContains(
'Page', 'Page',
$children, $children,
'Limited parent lists disallowed classes' 'Limited parent lists disallowed classes'
); );
// But it can create a ClassB // But it can create a ClassB
$this->assertNotContains( $this->assertNotContains(
'CMSMainTest_ClassB', 'CMSMainTest_ClassB',
$children, $children,
'Limited parent omits explicitly allowed classes in disallowedChildren' 'Limited parent omits explicitly allowed classes in disallowedChildren'
); );
} }
/** /**
* @todo Test the results of a publication better * @todo Test the results of a publication better
*/ */
@ -88,18 +88,18 @@ class CMSMainTest extends FunctionalTest {
$page1 = $this->objFromFixture('Page', "page1"); $page1 = $this->objFromFixture('Page', "page1");
$page2 = $this->objFromFixture('Page', "page2"); $page2 = $this->objFromFixture('Page', "page2");
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin')); $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
$response = $this->get('admin/pages/publishall?confirm=1'); $response = $this->get('admin/pages/publishall?confirm=1');
$this->assertContains( $this->assertContains(
'Done: Published 30 pages', 'Done: Published 30 pages',
$response->getBody() $response->getBody()
); );
$actions = CMSBatchActionHandler::config()->batch_actions; $actions = CMSBatchActionHandler::config()->batch_actions;
// 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']);
@ -111,11 +111,11 @@ class CMSMainTest extends FunctionalTest {
$latestID = DB::prepared_query('select max("Version") from "RedirectorPage_versions" where "RecordID" = ?', array($pageID))->value(); $latestID = DB::prepared_query('select max("Version") from "RedirectorPage_versions" where "RecordID" = ?', array($pageID))->value();
$dsCount = DB::prepared_query('select count("Version") from "RedirectorPage_versions" where "RecordID" = ? and "Version"= ?', array($pageID, $latestID))->value(); $dsCount = DB::prepared_query('select count("Version") from "RedirectorPage_versions" where "RecordID" = ? and "Version"= ?', array($pageID, $latestID))->value();
$this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID); $this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID);
$this->session()->clear('loggedInAs'); $this->session()->clear('loggedInAs');
//$this->assertRegexp('/Done: Published 4 pages/', $response->getBody()) //$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
/* /*
$response = Director::test("admin/pages/publishitems", array( $response = Director::test("admin/pages/publishitems", array(
'ID' => '' 'ID' => ''
@ -125,7 +125,7 @@ class CMSMainTest extends FunctionalTest {
$this->assertRegexp('/Done: Published 4 pages/', $response->getBody()) $this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
*/ */
} }
/** /**
* Test publication of one of every page type * Test publication of one of every page type
*/ */
@ -134,24 +134,24 @@ 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($class instanceof TestOnly) continue; // if($class instanceof TestOnly) continue;
// $page->Title = "Test $class page"; // $page->Title = "Test $class page";
// $page->write(); // $page->write();
// $this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value()); // $this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
// $page->doPublish(); // $page->doPublish();
// $this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value()); // $this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
// // Check that you can visit the page // // Check that you can visit the page
// $this->get($page->URLSegment); // $this->get($page->URLSegment);
// } // }
} }
/** /**
* Test that getCMSFields works on each page type. * Test that getCMSFields works on each page type.
* Mostly, this is just checking that the method doesn't return an error * Mostly, this is just checking that the method doesn't return an error
@ -159,99 +159,99 @@ class CMSMainTest extends FunctionalTest {
public function testThatGetCMSFieldsWorksOnEveryPageType() { public function testThatGetCMSFieldsWorksOnEveryPageType() {
$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();
$page->flushCache(); $page->flushCache();
$page = DataObject::get_by_id("SiteTree", $page->ID); $page = DataObject::get_by_id("SiteTree", $page->ID);
$this->assertTrue($page->getCMSFields() instanceof FieldList); $this->assertTrue($page->getCMSFields() instanceof FieldList);
} }
} }
public function testCanPublishPageWithUnpublishedParentWithStrictHierarchyOff() { public function testCanPublishPageWithUnpublishedParentWithStrictHierarchyOff() {
$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();
$actions = $childPage->getCMSActions()->dataFields(); $actions = $childPage->getCMSActions()->dataFields();
$this->assertArrayHasKey( $this->assertArrayHasKey(
'action_publish', 'action_publish',
$actions, $actions,
'Can publish a page with an unpublished parent with strict hierarchy off' 'Can publish a page with an unpublished parent with strict hierarchy off'
); );
Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false);
} }
/** /**
* Test that a draft-deleted page can still be opened in the CMS * Test that a draft-deleted page can still be opened in the CMS
*/ */
public function testDraftDeletedPageCanBeOpenedInCMS() { public function testDraftDeletedPageCanBeOpenedInCMS() {
$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();
$response = $this->get('admin/pages/edit/show/' . $pageID); $response = $this->get('admin/pages/edit/show/' . $pageID);
$livePage = Versioned::get_one_by_stage("SiteTree", "Live", array( $livePage = Versioned::get_one_by_stage("SiteTree", "Live", array(
'"SiteTree"."ID"' => $pageID '"SiteTree"."ID"' => $pageID
)); ));
$this->assertInstanceOf('SiteTree', $livePage); $this->assertInstanceOf('SiteTree', $livePage);
$this->assertTrue($livePage->canDelete()); $this->assertTrue($livePage->canDelete());
// Check that the 'restore' button exists as a simple way of checking that the correct page is returned. // Check that the 'restore' button exists as a simple way of checking that the correct page is returned.
$this->assertRegExp('/<button[^>]+name="action_(restore|revert)"/i', $response->getBody()); $this->assertRegExp('/<button[^>]+name="action_(restore|revert)"/i', $response->getBody());
} }
/** /**
* Test CMSMain::getRecord() * Test CMSMain::getRecord()
*/ */
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();
$cmsMain = new CMSMain(); $cmsMain = new CMSMain();
// Bad calls // Bad calls
$this->assertNull($cmsMain->getRecord('0')); $this->assertNull($cmsMain->getRecord('0'));
$this->assertNull($cmsMain->getRecord('asdf')); $this->assertNull($cmsMain->getRecord('asdf'));
// 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');
$this->assertInstanceOf('Page', $newPage); $this->assertInstanceOf('Page', $newPage);
$this->assertEquals('5', $newPage->ParentID); $this->assertEquals('5', $newPage->ParentID);
} }
public function testDeletedPagesSiteTreeFilter() { public function testDeletedPagesSiteTreeFilter() {
$id = $this->idFromFixture('Page', 'page3'); $id = $this->idFromFixture('Page', 'page3');
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$result = $this->get('admin/pages/getsubtree?filter=CMSSiteTreeFilter_DeletedPages&ajax=1&ID=' . $id); $result = $this->get('admin/pages/getsubtree?filter=CMSSiteTreeFilter_DeletedPages&ajax=1&ID=' . $id);
$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;
@ -262,16 +262,16 @@ class CMSMainTest extends FunctionalTest {
$cmsUser->logIn(); $cmsUser->logIn();
$this->get('admin/pages/add'); $this->get('admin/pages/add');
$response = $this->post( $response = $this->post(
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
array( array(
'ParentID' => '0', 'ParentID' => '0',
'PageType' => 'Page', 'PageType' => 'Page',
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1, 'ajax' => 1,
), array( ), array(
'X-Pjax' => 'CurrentForm,Breadcrumbs', 'X-Pjax' => 'CurrentForm,Breadcrumbs',
) )
); );
// should redirect, which is a permission error // should redirect, which is a permission error
$this->assertEquals(403, $response->getStatusCode(), 'Add TopLevel page must fail for normal user'); $this->assertEquals(403, $response->getStatusCode(), 'Add TopLevel page must fail for normal user');
@ -281,28 +281,28 @@ class CMSMainTest extends FunctionalTest {
$response = $this->get('admin/pages/add'); $response = $this->get('admin/pages/add');
$response = $this->post( $response = $this->post(
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
array( array(
'ParentID' => '0', 'ParentID' => '0',
'PageType' => 'Page', 'PageType' => 'Page',
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1, 'ajax' => 1,
), array( ), array(
'X-Pjax' => 'CurrentForm,Breadcrumbs', 'X-Pjax' => 'CurrentForm,Breadcrumbs',
) )
); );
$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;
@ -312,8 +312,8 @@ class CMSMainTest extends FunctionalTest {
// Create toplevel page // Create toplevel page
$this->get('admin/pages/add'); $this->get('admin/pages/add');
$response = $this->post( $response = $this->post(
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
array('ParentID' => '0', 'PageType' => 'CMSMainTest_ClassA', 'Locale' => 'en_US', 'action_doAdd' => 1) array('ParentID' => '0', 'PageType' => 'CMSMainTest_ClassA', 'Locale' => 'en_US', 'action_doAdd' => 1)
); );
$this->assertFalse($response->isError()); $this->assertFalse($response->isError());
preg_match('/edit\/show\/(\d*)/', $response->getHeader('Location'), $matches); preg_match('/edit\/show\/(\d*)/', $response->getHeader('Location'), $matches);
@ -322,8 +322,8 @@ class CMSMainTest extends FunctionalTest {
// Create allowed child // Create allowed child
$this->get('admin/pages/add'); $this->get('admin/pages/add');
$response = $this->post( $response = $this->post(
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
array('ParentID' => $newPageId, 'PageType' => 'CMSMainTest_ClassB', 'Locale' => 'en_US', 'action_doAdd' => 1) array('ParentID' => $newPageId, 'PageType' => 'CMSMainTest_ClassB', 'Locale' => 'en_US', 'action_doAdd' => 1)
); );
$this->assertFalse($response->isError()); $this->assertFalse($response->isError());
$this->assertNull($response->getBody()); $this->assertNull($response->getBody());
@ -331,8 +331,8 @@ class CMSMainTest extends FunctionalTest {
// Create disallowed child // Create disallowed child
$this->get('admin/pages/add'); $this->get('admin/pages/add');
$response = $this->post( $response = $this->post(
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
array('ParentID' => $newPageId, 'PageType' => 'Page', 'Locale' => 'en_US', 'action_doAdd' => 1) array('ParentID' => $newPageId, 'PageType' => 'Page', 'Locale' => 'en_US', 'action_doAdd' => 1)
); );
$this->assertEquals(403, $response->getStatusCode(), 'Add disallowed child should fail'); $this->assertEquals(403, $response->getStatusCode(), 'Add disallowed child should fail');
@ -342,8 +342,8 @@ class CMSMainTest extends FunctionalTest {
} }
public function testBreadcrumbs() { public function testBreadcrumbs() {
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture('Page', 'page3');
$page31 = $this->objFromFixture('Page', 'page31'); $page31 = $this->objFromFixture('Page', 'page31');
$adminuser = $this->objFromFixture('Member', 'admin'); $adminuser = $this->objFromFixture('Member', 'admin');
$this->session()->inst_set('loggedInAs', $adminuser->ID); $this->session()->inst_set('loggedInAs', $adminuser->ID);
@ -375,11 +375,11 @@ 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);
} }
} }
/** /**
* Tests filtering in {@see CMSMain::getList()} * Tests filtering in {@see CMSMain::getList()}
*/ */
@ -390,8 +390,8 @@ class CMSMainTest extends FunctionalTest {
$pages = $controller->getList()->sort('Title'); $pages = $controller->getList()->sort('Title');
$this->assertEquals(28, $pages->count()); $this->assertEquals(28, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Home', 'Page 1', 'Page 10', 'Page 11', 'Page 12'), array('Home', 'Page 1', 'Page 10', 'Page 11', 'Page 12'),
$pages->Limit(5)->column('Title') $pages->Limit(5)->column('Title')
); );
// Change state of tree // Change state of tree
@ -412,59 +412,78 @@ class CMSMainTest extends FunctionalTest {
$pages = $controller->getList()->sort('Title'); $pages = $controller->getList()->sort('Title');
$this->assertEquals(26, $pages->count()); $this->assertEquals(26, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Home', 'Page 10', 'Page 11', 'Page 13', 'Page 14'), array('Home', 'Page 10', 'Page 11', 'Page 13', 'Page 14'),
$pages->Limit(5)->column('Title') $pages->Limit(5)->column('Title')
); );
// Test deleted page filter // Test deleted page filter
$params = array( $params = array(
'FilterClass' => 'CMSSiteTreeFilter_StatusDeletedPages' 'FilterClass' => 'CMSSiteTreeFilter_StatusDeletedPages'
); );
$pages = $controller->getList($params); $pages = $controller->getList($params);
$this->assertEquals(1, $pages->count()); $this->assertEquals(1, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Page 1'), array('Page 1'),
$pages->column('Title') $pages->column('Title')
); );
// Test live, but not on draft filter // Test live, but not on draft filter
$params = array( $params = array(
'FilterClass' => 'CMSSiteTreeFilter_StatusRemovedFromDraftPages' 'FilterClass' => 'CMSSiteTreeFilter_StatusRemovedFromDraftPages'
); );
$pages = $controller->getList($params); $pages = $controller->getList($params);
$this->assertEquals(1, $pages->count()); $this->assertEquals(1, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Page 12'), array('Page 12'),
$pages->column('Title') $pages->column('Title')
); );
// Test live pages filter // Test live pages filter
$params = array( $params = array(
'FilterClass' => 'CMSSIteTreeFilter_PublishedPages' 'FilterClass' => 'CMSSIteTreeFilter_PublishedPages'
); );
$pages = $controller->getList($params); $pages = $controller->getList($params);
$this->assertEquals(2, $pages->count()); $this->assertEquals(2, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Page 11', 'Page 12'), array('Page 11', 'Page 12'),
$pages->column('Title') $pages->column('Title')
); );
// Test that parentID is ignored when filtering // Test that parentID is ignored when filtering
$pages = $controller->getList($params, $page3->ID); $pages = $controller->getList($params, $page3->ID);
$this->assertEquals(2, $pages->count()); $this->assertEquals(2, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Page 11', 'Page 12'), array('Page 11', 'Page 12'),
$pages->column('Title') $pages->column('Title')
); );
// Test that parentID is respected when not filtering // Test that parentID is respected when not filtering
$pages = $controller->getList(array(), $page3->ID); $pages = $controller->getList(array(), $page3->ID);
$this->assertEquals(2, $pages->count()); $this->assertEquals(2, $pages->count());
$this->assertEquals( $this->assertEquals(
array('Page 3.1', 'Page 3.2'), array('Page 3.1', 'Page 3.2'),
$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 {