mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
f0dfab1308
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98084 467b73ca-7a2a-4603-9d3b-597d59a354a9
63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
|
|
|
class PermissionTest extends SapphireTest {
|
|
static $fixture_file = 'sapphire/tests/security/PermissionTest.yml';
|
|
|
|
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);
|
|
}
|
|
|
|
function testDirectlyAppliedPermissions() {
|
|
$member = $this->objFromFixture('Member', 'author');
|
|
$this->assertTrue(Permission::checkMember($member, "SITETREE_VIEW_ALL"));
|
|
}
|
|
|
|
function testPermissionAreInheritedFromOneRole() {
|
|
$member = $this->objFromFixture('Member', 'author');
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_CMSMain"));
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
|
$this->assertFalse(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
|
}
|
|
|
|
function testPermissionAreInheritedFromMultipleRoles() {
|
|
$member = $this->objFromFixture('Member', 'access');
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_CMSMain"));
|
|
$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
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_CMSMain"));
|
|
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
|
|
|
// 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"));
|
|
}
|
|
/**
|
|
* Ensure the the get_*_by_permission functions are permission role aware
|
|
*/
|
|
function testGettingMembersByPermission() {
|
|
$accessMember = $this->objFromFixture('Member', 'access');
|
|
|
|
$result = Permission::get_members_by_permission(array('CMS_ACCESS_SecurityAdmin'));
|
|
|
|
$this->assertContains($result, $accessMember, 'Member is found via a permission attached to a role');
|
|
}
|
|
} |