function OgGroupAudienceField::testPropopulateViaUrl in Organic groups 7
Test prepopulating the audience field widget via URL.
File
- ./
og.test, line 1101
Class
- OgGroupAudienceField
- Test group audience field.
Code
function testPropopulateViaUrl() {
// Create users.
$admin_user = $this
->drupalCreateUser(array(
'access content',
'administer content types',
'create article content',
'edit any article content',
));
$this
->drupalLogin($admin_user);
// Add OG group field to the "article" bundle.
og_create_field(OG_GROUP_FIELD, 'node', 'article');
$groups = array();
// Create two node groups.
foreach (range(1, 3) as $id) {
$settings = array();
$settings['type'] = 'article';
$settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
$node = $this
->drupalCreateNode($settings);
$group = og_get_group('node', $node->nid);
$groups[$id] = $group;
}
// Create two entity_test group.
foreach (range(4, 6) as $id) {
$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[$id] = $group;
}
$id = 'edit-group-audience-und';
// Assert all 6 groups are unselected in the audience field.
$this
->drupalGet('node/add/article');
foreach ($groups as $group) {
$this
->assertNoOptionSelected($id, $group->gid);
}
// Assert all entity types passed in the URL as selected.
$options = array(
'query' => array(
'gids_node[]' => implode(',', array(
$groups[1]->etid,
$groups[2]->etid,
)),
'gids_entity_test[]' => implode(',', array(
$groups[4]->etid,
$groups[5]->etid,
)),
),
);
$this
->drupalGet('node/add/article', $options);
foreach ($groups as $group) {
$op = !in_array($group->gid, array(
3,
6,
)) ? 'assertOptionSelected' : 'assertNoOptionSelected';
$this
->{$op}($id, $group->gid);
}
// Assert all groups passed in the URL are selected.
$group = $groups[1];
$options = array(
'query' => array(
'gids_group[]' => $group->gid,
),
);
$this
->drupalGet('node/add/article', $options);
foreach ($groups as $group) {
$op = $group->gid == 1 ? 'assertOptionSelected' : 'assertNoOptionSelected';
$this
->{$op}($id, $group->gid);
}
// Pass invalid entity types, check nothing is selected.
$options = array(
'query' => array(
'gids_invalid_entity[]' => $group->gid,
),
);
$this
->drupalGet('node/add/article', $options);
foreach ($groups as $group) {
$this
->assertNoOptionSelected($id, $group->gid);
}
// Pass invalid group IDs, check nothing is selected.
$options = array(
'query' => array(
'gids_node[]' => 200,
),
);
$this
->drupalGet('node/add/article', $options);
foreach ($groups as $group) {
$this
->assertNoOptionSelected($id, $group->gid);
}
}