abstract class OpenAtriumAccessBaseTestCase in Open Atrium Core 7.2
Hierarchy
- class \OpenAtriumAccessBaseTestCase extends \SimpleTestCloneTestCase
Expanded class hierarchy of OpenAtriumAccessBaseTestCase
File
- modules/
oa_access/ tests/ oa_access.test, line 15 - Functional tests for the Open Atrium Access module.
View source
abstract class OpenAtriumAccessBaseTestCase extends SimpleTestCloneTestCase {
// The 'standard' profile defines an 'administrator' role which conflicts
// with panopoly_core's 'administrator' role.
// TODO: This is ignored by SimpleTestCloneTestCase...
protected $profile = 'testing';
public function setUp($modules = array()) {
// TODO: This is how it should look for DrupalWebTestCase!
//
//parent::setUp(array_merge(array(
// // Without oa_sections, we'll get a Table 'field_data_field_oa_user_ref'
// // doesn't exist error. Although, we don't actually use Sections here. :-)
// 'oa_sections',
// 'oa_teams',
// 'oa_access',
//), $modules));
// However, since we're using SimpleTestCloneTestCase, we need to use this
// instead.
parent::setUp();
module_enable($modules);
// Since we're not enabling oa_home, we need to make sure the front page
// exists, or $this->drupalLogin() will fail from the 404.
variable_set('site_frontpage', 'user');
// Flush all static caches.
drupal_static_reset();
}
/**
* Creates a node with an optional Space or Section.
*
* Replaces $this->drupalCreateNode() inside this test class.
*
* @param array $info
* An associative array with information about the node which will
* eventually get passed to node_save().
* @param object $space
* (Optional) A Drupal node object representing the Space this node should
* be created in.
* @param object $section
* (Optional) A Drupal node object representing the Section this node
* should be created in.
*
* @return object
* The Drupal node object that was created.
*
* @see DrupalWebTestCase::drupalCreateNode()
*/
protected function oaCreateNode($info, $space = NULL, $section = NULL) {
if ($space) {
$info['og_group_ref'][LANGUAGE_NONE][0]['target_id'] = $space->nid;
}
if ($section) {
$info['oa_section_ref'][LANGUAGE_NONE][0]['target_id'] = $section->nid;
}
return $this
->drupalCreateNode($info);
}
/**
* Create a user with an optional Space.
*
* Replaces $this->drupalCreateUser() inside this test class.
*
* @param array $permissions
* An array containing all the permissions this user should have.
* @param object $space
* (Optional) A Drupal node object representing the Space this user should
* be created in.
*
* @return object
* The Drupal user object that was created.
*
* @see DrupalWebTestCase::drupalCreateUser()
*/
protected function oaCreateUser($permissions, $space = NULL) {
$account = $this
->drupalCreateUser($permissions);
if ($space) {
og_group('node', $space->nid, array(
'entity type' => 'user',
'entity' => $account,
'membership type' => OG_MEMBERSHIP_TYPE_DEFAULT,
));
}
return $account;
}
/**
* Creates an Open Atrium Group with a new user in an optional Space.
*
* @param array $info
* An associative array with information about the node which
* will eventually get passed to node_save().
* @param array $permissions
* An array containing all the permissions this user should have.
* @param object $space
* (Optional) A Drupal node object representing the Space this user should
* be created in.
*
* @return array
* An associative array with two keys:
* - group: (object) A Drupal node object representing the new Group node.
* - user: (object) A Drupal user object representing the new user.
*/
protected function oaCreateGroupWithUser(array $info, array $permissions, $space = NULL) {
$info += array(
'type' => 'oa_group',
'title' => 'Group',
);
$group = $this
->oaCreateNode($info);
$account = $this
->oaCreateUser($permissions, $space);
// Add the user to the group.
og_group('node', $group->nid, array(
'entity type' => 'user',
'entity' => $account,
'membership type' => OG_MEMBERSHIP_TYPE_DEFAULT,
));
return array(
'group' => $group,
'user' => $account,
);
}
/**
* Creates an Open Atrium Team with a new user in a Space.
*
* @param array $info
* An associative array with information about the node which
* will eventually get passed to node_save().
* @param array $permissions
* An array containing all the permissions this user should have.
* @param object $space
* A Drupal node object representing the Space this Team and user should be
* created in.
*
* @return array
* An associative array with two keys:
* - group: (object) A Drupal node object representing the new Group node.
* - user: (object) A Drupal user object representing the new user.
*/
protected function oaCreateTeamWithUser(array $info, array $permissions, $space) {
$info += array(
'type' => 'oa_team',
'title' => 'Team',
);
$team = $this
->oaCreateNode($info, $space);
$account = $this
->oaCreateUser($permissions, $space);
// Add the user to the team.
oa_teams_add_member($team, $account->uid);
return array(
'team' => $team,
'user' => $account,
);
}
/**
* Post to a Group/Team permisisons page with a set of values.
*
* You're expected to use $this->drupalGet() to load the admin page before
* calling this function to submit.
*
* After posting to the admin form, it will verify that the permissions
* actually "stuck".
*
* @param array $values
* An associative array keyed by the module machine name which contains
* an associative array keyed by the permission machine name containing
* arrays of group or team nids.
*/
protected function oaPostPermissions($values) {
$edit = array();
foreach ($values as $module => $permissions) {
foreach ($permissions as $name => $groups) {
$edit["permissions[{$module}][{$name}][groups][]"] = $groups;
}
}
$this
->drupalPost(NULL, $edit, t('Save permissions'));
// Verify that the settinsg 'stuck'.
foreach ($values as $module => $permissions) {
foreach ($permissions as $name => $groups) {
$results = $this
->xpath('//select[@name=:name]//option', array(
':name' => "permissions[{$module}][{$name}][groups][]",
));
$found_groups = array();
foreach ($results as $option) {
if ($option['selected']) {
$found_groups[] = (string) $option['value'];
}
}
$this
->assertEqual($found_groups, $groups, t('Settings for %permission stuck', array(
'%permission' => $name,
)));
}
}
}
/**
* Check if a select has a certain option.
*
* @param string $name
* The name of the select.
* @param string $value
* The value of the option to check for.
*
* @return boolean
* TRUE if found; FALSE otherwise.
*/
function hasSelectOption($name, $value) {
$results = $this
->xpath('//select[@name=:name]//option[@value=:value]', array(
':name' => $name,
':value' => $value,
));
return count($results) > 0;
}
/**
* Get all permissions defined by implementing modules.
*
* Wraps oa_access_get_permissions(). Since we're using
* SimpleTestCloneTestCase, we can't guarantee that only our permissions are
* available, so we have to filter out all others.
*
* @param string $module
* The name of the module whose permissions we want included.
* @param boolean $reset
* (Optional) If set to TRUE, it will reset the static cache.
*
* @return array
* Associative array keyed with the permission name containing associative
* arrays with the following keys:
* - title: Human readable name of the permission.
* - description: Human readable description of the permission.
* - module: The machine name of the module which defines it.
* - type: Flags specifying if can be used for Groups or Teams or both.
*
* @see oa_access_get_permissions()
*/
protected function getPermissions($module, $reset = FALSE) {
$permissions = array();
foreach (oa_access_get_permissions($reset) as $name => $info) {
if ($info['module'] == $module) {
$permissions[$name] = $info;
}
}
return $permissions;
}
/**
* Gets all the permissions that a list of groups have.
*
* Wraps oa_access_get_group_permissions(). Since we're using
* SimpleTestCloneTestCase, we can't guarantee that only our permissions are
* available, so we have to filter out all others.
*
* @param string $module
* The name of the module whose permissions we want included.
* @param array $groups
* An array of nids of Groups or Teams.
*
* @return array
* An associative array keyed by group nid containing associative arrays
* keyed by the module and containing an array of permission names, for
* example:
* @code
* array('27' => array('mymodule' => array('a permission')))
* @endcode
* Which signifies that the group with nid 27 has 'a permission' from
* a module called 'mymodule'.
*
* @see oa_access_get_group_permissions().
*/
protected function getGroupPermissions($module, $groups) {
$permissions = array();
foreach (oa_access_get_group_permissions($groups) as $gid => $info) {
if (empty($permissions[$gid])) {
$permissions[$gid] = array();
}
if (isset($info[$module])) {
$permissions[$gid][$module] = $info[$module];
}
}
return $permissions;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OpenAtriumAccessBaseTestCase:: |
protected | property | ||
OpenAtriumAccessBaseTestCase:: |
protected | function | Gets all the permissions that a list of groups have. | |
OpenAtriumAccessBaseTestCase:: |
protected | function | Get all permissions defined by implementing modules. | |
OpenAtriumAccessBaseTestCase:: |
function | Check if a select has a certain option. | ||
OpenAtriumAccessBaseTestCase:: |
protected | function | Creates an Open Atrium Group with a new user in an optional Space. | |
OpenAtriumAccessBaseTestCase:: |
protected | function | Creates a node with an optional Space or Section. | |
OpenAtriumAccessBaseTestCase:: |
protected | function | Creates an Open Atrium Team with a new user in a Space. | |
OpenAtriumAccessBaseTestCase:: |
protected | function | Create a user with an optional Space. | |
OpenAtriumAccessBaseTestCase:: |
protected | function | Post to a Group/Team permisisons page with a set of values. | |
OpenAtriumAccessBaseTestCase:: |
public | function | 1 |