mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
BUG Ensure CMSMainTest uses correct siteconfig
BUG Prevent CMSAddPageController invoking Security::LoginForm code during error handling
This commit is contained in:
parent
54b8389b8a
commit
c6c650f136
@ -9,6 +9,18 @@ class CMSMainTest extends FunctionalTest {
|
||||
|
||||
static protected $orig = array();
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Clear automatically created siteconfigs (in case one was created outside of the specified fixtures).
|
||||
$ids = $this->allFixtureIDs('SiteConfig');
|
||||
if($ids) {
|
||||
foreach(SiteConfig::get()->exclude('ID', $ids) as $config) {
|
||||
$config->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testSiteTreeHints() {
|
||||
$cache = SS_Cache::factory('CMSMain_SiteTreeHints');
|
||||
// Login as user with root creation privileges
|
||||
@ -313,26 +325,59 @@ class CMSMainTest extends FunctionalTest {
|
||||
$this->get('admin/pages/add');
|
||||
$response = $this->post(
|
||||
'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,
|
||||
'ajax' => 1
|
||||
), array(
|
||||
'X-Pjax' => 'CurrentForm,Breadcrumbs',
|
||||
)
|
||||
);
|
||||
$this->assertFalse($response->isError());
|
||||
preg_match('/edit\/show\/(\d*)/', $response->getHeader('Location'), $matches);
|
||||
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL'), $matches);
|
||||
$this->assertNotEmpty($ok);
|
||||
$newPageId = $matches[1];
|
||||
|
||||
// Create allowed child
|
||||
$this->get('admin/pages/add');
|
||||
$response = $this->post(
|
||||
'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,
|
||||
'ajax' => 1
|
||||
), array(
|
||||
'X-Pjax' => 'CurrentForm,Breadcrumbs',
|
||||
)
|
||||
);
|
||||
$this->assertFalse($response->isError());
|
||||
$this->assertNull($response->getBody());
|
||||
$this->assertEmpty($response->getBody());
|
||||
|
||||
// Verify that the page was created and redirected to accurately
|
||||
$newerPage = SiteTree::get()->byID($newPageId)->AllChildren()->first();
|
||||
$this->assertNotEmpty($newerPage);
|
||||
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL'), $matches);
|
||||
$this->assertNotEmpty($ok);
|
||||
$newerPageID = $matches[1];
|
||||
$this->assertEquals($newerPage->ID, $newerPageID);
|
||||
|
||||
// Create disallowed child
|
||||
$this->get('admin/pages/add');
|
||||
$response = $this->post(
|
||||
'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,
|
||||
'ajax' => 1
|
||||
), array(
|
||||
'X-Pjax' => 'CurrentForm,Breadcrumbs',
|
||||
)
|
||||
);
|
||||
$this->assertEquals(403, $response->getStatusCode(), 'Add disallowed child should fail');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user