function DrupalTestCase::drupalCreateRolePerm in SimpleTest 5
Same name and namespace in other branches
- 6 drupal_test_case.php \DrupalTestCase::drupalCreateRolePerm()
Create a role / perm combination specified by permissions
Parameters
array $permissions Array of the permission strings:
Return value
integer role-id
1 call to DrupalTestCase::drupalCreateRolePerm()
- DrupalTestCase::drupalCreateUserRolePerm in ./
drupal_test_case.php - Creates a user / role / permissions combination specified by permissions
File
- ./
drupal_test_case.php, line 252
Class
- DrupalTestCase
- Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.
Code
function drupalCreateRolePerm($permissions = NULL) {
if ($permissions === NULL) {
$permstring = 'access comments, access content, post comments, post comments without approval';
}
else {
$permstring = implode(', ', $permissions);
}
/* Create role */
$role_name = $this
->randomName();
db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name);
$role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = '%s'", $role_name));
$this
->assertTrue($role, " [role] created name: {$role_name}, id: " . (isset($role->rid) ? $role->rid : '-n/a-'));
if ($role && !empty($role->rid)) {
/* Create permissions */
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, $permstring);
$this
->assertTrue(db_affected_rows(), ' [role] created permissions: ' . $permstring);
$this->_cleanupRoles[] = $role->rid;
return $role->rid;
}
else {
return false;
}
}