mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FEATURE: added several tests for PermissionCheckboxSetField, PermissionRole and Group (from r94887)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@95629 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
bb14045626
commit
c57ec36ea9
@ -77,6 +77,15 @@ class GroupTest extends FunctionalTest {
|
|||||||
// Test adding child group
|
// Test adding child group
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDelete() {
|
||||||
|
$adminGroup = $this->objFromFixture('Group', 'admingroup');
|
||||||
|
|
||||||
|
$adminGroup->delete();
|
||||||
|
|
||||||
|
$this->assertNull(DataObject::get('Group', "ID={$adminGroup->ID}"), 'Group is removed');
|
||||||
|
$this->assertNull(DataObject::get('Permission',"GroupID={$adminGroup->ID}"), 'Permissions removed along with the group');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GroupTest_Member extends Member implements TestOnly {
|
class GroupTest_Member extends Member implements TestOnly {
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
* @subpackage tests
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class PermissionCheckboxSetFieldTest extends SapphireTest {
|
class PermissionCheckboxSetFieldTest extends SapphireTest {
|
||||||
|
static $fixture_file = 'sapphire/tests/security/PermissionCheckboxSetFieldTest.yml';
|
||||||
|
|
||||||
function testHiddenPermissions() {
|
function testHiddenPermissions() {
|
||||||
$f = new PermissionCheckboxSetField(
|
$f = new PermissionCheckboxSetField(
|
||||||
'Permissions',
|
'Permissions',
|
||||||
@ -21,4 +23,65 @@ class PermissionCheckboxSetFieldTest extends SapphireTest {
|
|||||||
$this->assertContains('CMS_ACCESS_CMSMain', $f->Field());
|
$this->assertContains('CMS_ACCESS_CMSMain', $f->Field());
|
||||||
$this->assertNotContains('CMS_ACCESS_ReportAdmin', $f->Field());
|
$this->assertNotContains('CMS_ACCESS_ReportAdmin', $f->Field());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSaveInto() {
|
||||||
|
$group = $this->objFromFixture('Group', 'group'); // tested group
|
||||||
|
$untouchable = $this->objFromFixture('Group', 'untouchable'); // group that should not change
|
||||||
|
|
||||||
|
$field = new PermissionCheckboxSetField(
|
||||||
|
'Permissions',
|
||||||
|
'Permissions',
|
||||||
|
'Permission',
|
||||||
|
'GroupID',
|
||||||
|
$group
|
||||||
|
);
|
||||||
|
|
||||||
|
// get the number of permissions before we start
|
||||||
|
$baseCount = DataObject::get('Permission')->Count();
|
||||||
|
|
||||||
|
// there are currently no permissions, save empty checkbox
|
||||||
|
$field->saveInto($group);
|
||||||
|
$group->flushCache();
|
||||||
|
$untouchable->flushCache();
|
||||||
|
$this->assertEquals($group->Permissions()->Count(), 0, 'The tested group has no permissions');
|
||||||
|
|
||||||
|
$this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
|
||||||
|
$this->assertEquals($untouchable->Permissions("Code='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
|
||||||
|
|
||||||
|
$this->assertEquals(DataObject::get('Permission')->Count(), $baseCount, 'There are no orphaned permissions');
|
||||||
|
|
||||||
|
// add some permissions
|
||||||
|
$field->setValue(array(
|
||||||
|
'ADMIN'=>true,
|
||||||
|
'CMS_ACCESS_AssetAdmin'=>true
|
||||||
|
));
|
||||||
|
|
||||||
|
$field->saveInto($group);
|
||||||
|
$group->flushCache();
|
||||||
|
$untouchable->flushCache();
|
||||||
|
$this->assertEquals($group->Permissions()->Count(), 2, 'The tested group has two permissions permission');
|
||||||
|
$this->assertEquals($group->Permissions("Code='ADMIN'")->Count(), 1, 'The tested group has ADMIN permission');
|
||||||
|
$this->assertEquals($group->Permissions("Code='CMS_ACCESS_AssetAdmin'")->Count(), 1, 'The tested group has CMS_ACCESS_AssetAdmin permission');
|
||||||
|
|
||||||
|
$this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
|
||||||
|
$this->assertEquals($untouchable->Permissions("Code='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
|
||||||
|
|
||||||
|
$this->assertEquals(DataObject::get('Permission')->Count(), $baseCount+2, 'There are no orphaned permissions');
|
||||||
|
|
||||||
|
// remove permission
|
||||||
|
$field->setValue(array(
|
||||||
|
'ADMIN'=>true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$field->saveInto($group);
|
||||||
|
$group->flushCache();
|
||||||
|
$untouchable->flushCache();
|
||||||
|
$this->assertEquals($group->Permissions()->Count(), 1, 'The tested group has 1 permission');
|
||||||
|
$this->assertEquals($group->Permissions("Code='ADMIN'")->Count(), 1, 'The tested group has ADMIN permission');
|
||||||
|
|
||||||
|
$this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
|
||||||
|
$this->assertEquals($untouchable->Permissions("Code='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
|
||||||
|
|
||||||
|
$this->assertEquals(DataObject::get('Permission')->Count(), $baseCount+1, 'There are no orphaned permissions');
|
||||||
|
}
|
||||||
}
|
}
|
10
tests/security/PermissionCheckboxSetFieldTest.yml
Normal file
10
tests/security/PermissionCheckboxSetFieldTest.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Group:
|
||||||
|
group:
|
||||||
|
Code: group
|
||||||
|
untouchable:
|
||||||
|
Code: untouchable
|
||||||
|
|
||||||
|
Permission:
|
||||||
|
perm1:
|
||||||
|
Code: ADMIN
|
||||||
|
Group: =>Group.untouchable
|
17
tests/security/PermissionRoleTest.php
Normal file
17
tests/security/PermissionRoleTest.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package sapphire
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class PermissionRoleTest extends FunctionalTest {
|
||||||
|
static $fixture_file = 'sapphire/tests/security/PermissionRoleTest.yml';
|
||||||
|
|
||||||
|
function testDelete() {
|
||||||
|
$role = $this->objFromFixture('PermissionRole', 'role');
|
||||||
|
|
||||||
|
$role->delete();
|
||||||
|
|
||||||
|
$this->assertNull(DataObject::get('PermissionRole', "ID={$role->ID}"), 'Role is removed');
|
||||||
|
$this->assertNull(DataObject::get('PermissionRoleCode',"RoleID={$role->ID}"), 'Permissions removed along with the role');
|
||||||
|
}
|
||||||
|
}
|
7
tests/security/PermissionRoleTest.yml
Normal file
7
tests/security/PermissionRoleTest.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
PermissionRole:
|
||||||
|
role:
|
||||||
|
Title: role
|
||||||
|
PermissionRoleCode:
|
||||||
|
code:
|
||||||
|
Code: ADMIN
|
||||||
|
Role: =>PermissionRole.role
|
Loading…
Reference in New Issue
Block a user