2009-10-16 00:27:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PermissionTest extends SapphireTest {
|
2011-03-30 08:49:11 +02:00
|
|
|
static $fixture_file = 'PermissionTest.yml';
|
2009-10-16 00:27:56 +02:00
|
|
|
|
2010-04-13 01:41:33 +02:00
|
|
|
function testGetCodesGrouped() {
|
|
|
|
$codes = Permission::get_codes();
|
|
|
|
$this->assertArrayNotHasKey('SITETREE_VIEW_ALL', $codes);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetCodesUngrouped() {
|
|
|
|
$codes = Permission::get_codes(null, false);
|
|
|
|
$this->assertArrayHasKey('SITETREE_VIEW_ALL', $codes);
|
|
|
|
}
|
|
|
|
|
2009-10-16 00:27:56 +02:00
|
|
|
function testDirectlyAppliedPermissions() {
|
|
|
|
$member = $this->objFromFixture('Member', 'author');
|
|
|
|
$this->assertTrue(Permission::checkMember($member, "SITETREE_VIEW_ALL"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPermissionAreInheritedFromOneRole() {
|
|
|
|
$member = $this->objFromFixture('Member', 'author');
|
2011-03-29 06:54:08 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_MyAdmin"));
|
2009-10-16 00:27:56 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
|
|
|
$this->assertFalse(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
|
|
|
}
|
2010-04-13 01:41:33 +02:00
|
|
|
|
2009-10-16 00:27:56 +02:00
|
|
|
function testPermissionAreInheritedFromMultipleRoles() {
|
|
|
|
$member = $this->objFromFixture('Member', 'access');
|
2011-03-29 06:54:08 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_MyAdmin"));
|
2009-10-16 00:27:56 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
|
|
|
$this->assertTrue(Permission::checkMember($member, "EDIT_PERMISSIONS"));
|
|
|
|
$this->assertFalse(Permission::checkMember($member, "SITETREE_VIEW_ALL"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRolesAndPermissionsFromParentGroupsAreInherited() {
|
|
|
|
$member = $this->objFromFixture('Member', 'globalauthor');
|
|
|
|
|
|
|
|
// Check that permissions applied to the group are there
|
|
|
|
$this->assertTrue(Permission::checkMember($member, "SITETREE_EDIT_ALL"));
|
|
|
|
|
|
|
|
// Check that roles from parent groups are there
|
2011-03-29 06:54:08 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_MyAdmin"));
|
2009-10-16 00:27:56 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
2010-04-13 01:41:33 +02:00
|
|
|
|
2009-10-16 00:27:56 +02:00
|
|
|
// Check that permissions from parent groups are there
|
|
|
|
$this->assertTrue(Permission::checkMember($member, "SITETREE_VIEW_ALL"));
|
|
|
|
|
|
|
|
// Check that a random permission that shouldn't be there isn't
|
|
|
|
$this->assertFalse(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
|
|
|
}
|
2010-04-13 04:00:15 +02:00
|
|
|
/**
|
|
|
|
* Ensure the the get_*_by_permission functions are permission role aware
|
|
|
|
*/
|
|
|
|
function testGettingMembersByPermission() {
|
|
|
|
$accessMember = $this->objFromFixture('Member', 'access');
|
2010-04-13 04:14:23 +02:00
|
|
|
$accessAuthor = $this->objFromFixture('Member', 'author');
|
|
|
|
|
2010-04-13 04:00:15 +02:00
|
|
|
$result = Permission::get_members_by_permission(array('CMS_ACCESS_SecurityAdmin'));
|
2010-04-13 04:18:14 +02:00
|
|
|
$resultIDs = $result ? $result->column() : array();
|
|
|
|
|
|
|
|
$this->assertContains($accessMember->ID, $resultIDs,
|
|
|
|
'Member is found via a permission attached to a role');
|
|
|
|
$this->assertNotContains($accessAuthor->ID, $resultIDs);
|
2010-04-13 04:00:15 +02:00
|
|
|
}
|
2009-11-22 06:16:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
function testHiddenPermissions(){
|
|
|
|
$permissionCheckboxSet = new PermissionCheckboxSetField('Permissions','Permissions','Permission','GroupID');
|
|
|
|
$this->assertContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field());
|
|
|
|
$this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
|
|
|
|
|
|
|
Permission::add_to_hidden_permissions('CMS_ACCESS_CMSMain');
|
|
|
|
Permission::add_to_hidden_permissions('CMS_ACCESS_AssetAdmin');
|
|
|
|
$this->assertNotContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field());
|
|
|
|
$this->assertNotContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
|
|
|
|
|
|
|
Permission::remove_from_hidden_permissions('CMS_ACCESS_AssetAdmin');
|
|
|
|
$this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
2011-03-30 06:31:24 +02:00
|
|
|
Permission::remove_from_hidden_permissions('CMS_ACCESS_CMSMain');
|
2009-11-22 06:16:38 +01:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|