function OgGroupApi::testGetEntityGroups in Organic groups 7
Test the og_get_entity_groups() API function.
File
- ./
og.test, line 373
Class
- OgGroupApi
- Test the Organic groups API and CRUD handling.
Code
function testGetEntityGroups() {
// Add OG group field to the entity_test's "main" bundle.
og_create_field(OG_GROUP_FIELD, 'entity_test', 'main');
// Add OG audience field to the node's "article" bundle.
og_create_field(OG_AUDIENCE_FIELD, 'node', 'article');
// Create users.
$admin_user = $this
->drupalCreateUser(array(
'access content',
'administer content types',
'create article content',
'edit any article content',
));
$this
->drupalLogin($admin_user);
$settings = array();
$settings['type'] = 'article';
$node = $this
->drupalCreateNode($settings);
$groups = array();
// Create group enteties.
foreach (og_group_content_states() as $state => $value) {
$entity = entity_create('entity_test', array(
'name' => 'main',
'uid' => $admin_user->uid,
));
$entity->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
$entity
->save();
$group = og_get_group('entity_test', $entity->pid);
$groups[$state] = $group->gid;
// Assign article to the group.
$values = array(
'entity type' => 'node',
'entity' => $node,
'state' => $state,
);
og_group($group->gid, $values);
}
$node = node_load($node->nid);
foreach ($groups as $state => $gid) {
$this
->assertEqual(og_get_entity_groups('node', $node, array(
$state,
)), drupal_map_assoc(array(
$gid,
)), t('Group content is assigned to group @id with correct state', array(
'@id' => $gid,
)));
}
}