2009-12-16 06:43:59 +01:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Security\Tests;
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\Security\PermissionRole;
|
2016-06-23 01:37:22 +02:00
|
|
|
use SilverStripe\Security\PermissionRoleCode;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class PermissionRoleTest extends FunctionalTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'PermissionRoleTest.yml';
|
|
|
|
|
|
|
|
public function testDelete()
|
|
|
|
{
|
|
|
|
$role = $this->objFromFixture(PermissionRole::class, 'role');
|
|
|
|
|
|
|
|
$role->delete();
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
DataObject::get(PermissionRole::class, "\"ID\"={$role->ID}")->count(),
|
|
|
|
'Role is removed'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
DataObject::get(PermissionRoleCode::class, "\"RoleID\"={$role->ID}")->count(),
|
|
|
|
'Permissions removed along with the role'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidatesPrivilegedPermissions()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
$nonAdminCode = new PermissionRoleCode(['Code' => 'CMS_ACCESS_CMSMain']);
|
|
|
|
$adminCode = new PermissionRoleCode(['Code' => 'ADMIN']);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$this->logInWithPermission('APPLY_ROLES');
|
|
|
|
$result = $nonAdminCode->validate();
|
|
|
|
$this->assertTrue(
|
|
|
|
$result->isValid(),
|
|
|
|
'Members with only APPLY_ROLES can create non-privileged permission role codes'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->logInWithPermission('APPLY_ROLES');
|
|
|
|
$result = $adminCode->validate();
|
|
|
|
$this->assertFalse(
|
|
|
|
$result->isValid(),
|
|
|
|
'Members with only APPLY_ROLES can\'t create privileged permission role codes'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$result = $adminCode->validate();
|
|
|
|
$this->assertTrue(
|
|
|
|
$result->isValid(),
|
|
|
|
'Members with ADMIN can create privileged permission role codes'
|
|
|
|
);
|
|
|
|
}
|
2009-12-16 06:43:59 +01:00
|
|
|
}
|