Commit 028920c1 authored by catch's avatar catch

Issue #2030655 by justafish, Alumei, daffie, alexpott, wwhurley, jamesquinton,...

Issue #2030655 by justafish, Alumei, daffie, alexpott, wwhurley, jamesquinton, pcambra, InternetDevels, rdatar, james_kerrigan: Expand Role with methods.
parent 837d726f
......@@ -621,7 +621,7 @@ protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NUL
// Grant the specified permissions to the role, if any.
if (!empty($permissions)) {
user_role_grant_permissions($role->id(), $permissions);
$assigned_permissions = entity_load('user_role', $role->id())->permissions;
$assigned_permissions = entity_load('user_role', $role->id())->getPermissions();
$missing_permissions = array_diff($permissions, $assigned_permissions);
if (!$missing_permissions) {
$this->pass(String::format('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), 'Role');
......
......@@ -47,28 +47,28 @@ class Role extends ConfigEntityBase implements RoleInterface {
*
* @var string
*/
public $id;
protected $id;
/**
* The human-readable label of this role.
*
* @var string
*/
public $label;
protected $label;
/**
* The weight of this role in administrative listings.
*
* @var int
*/
public $weight;
protected $weight;
/**
* The permissions belonging to this role.
*
* @var array
*/
public $permissions = array();
protected $permissions = array();
/**
* {@inheritdoc}
......@@ -77,6 +77,21 @@ public function getPermissions() {
return $this->permissions;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->get('weight');
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->set('weight', $weight);
return $this;
}
/**
* {@inheritdoc}
*/
......
......@@ -42,7 +42,7 @@ public function form(array $form, array &$form_state) {
);
$form['weight'] = array(
'#type' => 'value',
'#value' => $entity->get('weight'),
'#value' => $entity->getWeight(),
);
return parent::form($form, $form_state, $entity);
......
......@@ -41,8 +41,7 @@ public function hasPermission($permission);
* @param string $permission
* The permission to grant.
*
* @return RoleInterface
* The called object for chaining.
* @return $this
*/
public function grantPermission($permission);
......@@ -52,9 +51,26 @@ public function grantPermission($permission);
* @param string $permission
* The permission to revoke.
*
* @return RoleInterface
* The called object for chaining.
* @return $this
*/
public function revokePermission($permission);
/**
* Returns the weight.
*
* @return int
* The weight of this role.
*/
public function getWeight();
/**
* Sets the weight to the given value.
*
* @param int $weight
* The desired weight.
*
* @return $this
*/
public function setWeight($weight);
}
......@@ -92,9 +92,9 @@ function testRoleWeightOrdering() {
// Change the role weights to make the roles in reverse order.
$edit = array();
foreach ($roles as $role) {
$edit['entities['. $role->id() .'][weight]'] = $weight;
$edit['entities[' . $role->id() . '][weight]'] = $weight;
$new_role_weights[$role->id()] = $weight;
$saved_rids[] = $role->id;
$saved_rids[] = $role->id();
$weight--;
}
$this->drupalPostForm('admin/people/roles', $edit, t('Save order'));
......@@ -106,8 +106,8 @@ function testRoleWeightOrdering() {
$rids = array();
// Test that the role weights have been correctly saved.
foreach ($roles as $role) {
$this->assertEqual($role->weight, $new_role_weights[$role->id()]);
$rids[] = $role->id;
$this->assertEqual($role->getWeight(), $new_role_weights[$role->id()]);
$rids[] = $role->id();
}
// The order of the roles should be reversed.
$this->assertIdentical($rids, array_reverse($saved_rids));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment