2011-03-23 10:51:00 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class SecurityAdminTest extends FunctionalTest {
|
2011-03-29 06:54:08 +02:00
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
static $fixture_file = 'LeftAndMainTest.yml';
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2011-03-29 06:54:08 +02:00
|
|
|
protected $extraDataObjects = array('LeftAndMainTest_Object');
|
2012-03-06 01:23:02 +01:00
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
// TODO Fix export feature (moved from MemberTableField to GridFieldExportButton)
|
2012-03-06 01:23:02 +01:00
|
|
|
// function testGroupExport() {
|
|
|
|
// $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 01:23:02 +01:00
|
|
|
// /* First, open the applicable group */
|
|
|
|
// $response = $this->get('admin/security/show/' . $this->idFromFixture('Group','admin'));
|
|
|
|
// $inputs = $this->cssParser()->getBySelector('input#Form_EditForm_Title');
|
|
|
|
// $this->assertNotNull($inputs);
|
|
|
|
// $this->assertEquals('Administrators', (string)$inputs[0]['value']);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 01:23:02 +01:00
|
|
|
// /* Then load the export page */
|
|
|
|
// $this->get('admin/security/EditForm/field/Members/export');
|
|
|
|
// $lines = preg_split('/\n/', $this->content());
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 01:23:02 +01:00
|
|
|
// $this->assertEquals(count($lines), 3, "Export with members has one content row");
|
|
|
|
// $this->assertRegExp('/"","","admin@example.com"/', $lines[1], "Member values are correctly exported");
|
|
|
|
// }
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
// TODO Fix export feature (moved from MemberTableField to GridFieldExportButton)
|
2012-03-06 01:23:02 +01:00
|
|
|
// function testEmptyGroupExport() {
|
|
|
|
// $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 01:23:02 +01:00
|
|
|
// /* First, open the applicable group */
|
|
|
|
// $this->get('admin/security/show/' . $this->idFromFixture('Group','empty'));
|
|
|
|
// $inputs = $this->cssParser()->getBySelector('input#Form_EditForm_Title');
|
|
|
|
// $this->assertNotNull($inputs);
|
|
|
|
// $this->assertEquals('Empty Group', (string)$inputs[0]['value']);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 01:23:02 +01:00
|
|
|
// /* Then load the export page */
|
|
|
|
// $this->get('admin/security/EditForm/field/Members/export');
|
|
|
|
// $lines = preg_split('/\n/', $this->content());
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 01:23:02 +01:00
|
|
|
// $this->assertEquals(count($lines), 2, "Empty export only has header fields and an empty row");
|
|
|
|
// $this->assertEquals($lines[1], '', "Empty export only has no content row");
|
|
|
|
// }
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
function testAddHiddenPermission() {
|
|
|
|
SecurityAdmin::add_hidden_permission('CMS_ACCESS_ReportAdmin');
|
|
|
|
$this->assertContains('CMS_ACCESS_ReportAdmin', SecurityAdmin::get_hidden_permissions());
|
|
|
|
|
|
|
|
// reset to defaults
|
|
|
|
SecurityAdmin::clear_hidden_permissions();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveHiddenPermission() {
|
|
|
|
SecurityAdmin::add_hidden_permission('CMS_ACCESS_ReportAdmin');
|
|
|
|
$this->assertContains('CMS_ACCESS_ReportAdmin', SecurityAdmin::get_hidden_permissions());
|
|
|
|
SecurityAdmin::remove_hidden_permission('CMS_ACCESS_ReportAdmin');
|
|
|
|
$this->assertNotContains('CMS_ACCESS_ReportAdmin', SecurityAdmin::get_hidden_permissions());
|
|
|
|
|
|
|
|
// reset to defaults
|
|
|
|
SecurityAdmin::clear_hidden_permissions();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testClearHiddenPermission() {
|
|
|
|
SecurityAdmin::add_hidden_permission('CMS_ACCESS_ReportAdmin');
|
|
|
|
$this->assertContains('CMS_ACCESS_ReportAdmin', SecurityAdmin::get_hidden_permissions());
|
|
|
|
SecurityAdmin::clear_hidden_permissions('CMS_ACCESS_ReportAdmin');
|
|
|
|
$this->assertNotContains('CMS_ACCESS_ReportAdmin', SecurityAdmin::get_hidden_permissions());
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPermissionFieldRespectsHiddenPermissions() {
|
|
|
|
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
|
|
|
|
|
|
|
$group = $this->objFromFixture('Group', 'admin');
|
|
|
|
|
|
|
|
SecurityAdmin::add_hidden_permission('CMS_ACCESS_ReportAdmin');
|
2012-05-28 02:02:47 +02:00
|
|
|
$response = $this->get(sprintf('admin/security/EditForm/field/Groups/item/%d/edit', $group->ID));
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
$this->assertContains(
|
2011-03-29 06:54:08 +02:00
|
|
|
'CMS_ACCESS_SecurityAdmin',
|
2011-03-23 10:51:00 +01:00
|
|
|
$response->getBody()
|
|
|
|
);
|
|
|
|
$this->assertNotContains(
|
|
|
|
'CMS_ACCESS_ReportAdmin',
|
|
|
|
$response->getBody()
|
|
|
|
);
|
|
|
|
|
|
|
|
// reset to defaults
|
|
|
|
SecurityAdmin::clear_hidden_permissions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|