View source
<?php
class OgUiUserPermissionsTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Organic groups UI role permissions',
'description' => 'Verify that role permissions can be added and removed via the permissions page of the group.',
'group' => 'Organic groups UI',
);
}
function setUp() {
parent::setUp('og_ui');
$this->admin_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer content types',
'administer group',
));
$this
->drupalLogin($this->admin_user);
$group_type = $this
->drupalCreateContentType();
$this->group_type = $group_type->type;
og_create_field(OG_GROUP_FIELD, 'node', $this->group_type);
$node = $this
->drupalCreateNode(array(
'type' => $group_type->type,
'og_group' => array(
LANGUAGE_NONE => array(
0 => array(
'value' => TRUE,
),
),
),
));
$this->group = og_get_group('node', $node->nid);
}
function testOgUiUserPermissionChanges() {
$web_user = $this
->drupalCreateUser();
$gid = $this->group->gid;
$this
->assertTrue(og_user_access($gid, 'subscribe', $web_user), t('User has "subscribe" permission.'));
$roles = og_get_default_roles();
$roles = array_flip(array_keys($roles['og']));
$edit = array();
$edit['1[subscribe]'] = FALSE;
$this
->drupalPost('admin/config/group/permissions', $edit, t('Save global permissions'));
$this
->assertText(t('The changes have been saved.'), t('Successful save message displayed.'));
$this
->resetAll();
$this
->assertFalse(og_user_access($gid, 'subscribe', $web_user), t('User now does not have "subscribe" permission.'));
$edit = array();
$edit['1[subscribe]'] = TRUE;
$this
->drupalPost('admin/config/group/permissions', $edit, t('Save global permissions'));
$this
->resetAll();
$this
->assertTrue(og_user_access($gid, 'subscribe', $web_user), t('User has "subscribe" permission again.'));
}
}
class OgUiSubscribeTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Organic groups UI subscribe',
'description' => 'Verify the subscribe and unsubsribe functionality.',
'group' => 'Organic groups UI',
);
}
function setUp() {
parent::setUp('og_ui', 'entity_test');
module_enable(array(
'entity_feature',
));
og_create_field(OG_GROUP_FIELD, 'node', 'article');
}
function testOgUiAddPeople() {
$admin_user = $this
->drupalCreateUser();
$this
->drupalLogin($admin_user);
$node = entity_create('node', array(
'type' => 'article',
'uid' => $admin_user->uid,
));
$node->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
entity_save('node', $node);
$group = og_get_group('node', $node->nid);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText(t('You are the group manager'), t('Group manager gets correct text.'));
$web_user = $this
->drupalCreateUser();
$this
->drupalLogin($web_user);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText(t('Request group membership'), t('Non-member without "subscribe without approval" gets correct text.'));
$this
->clickLink(t('Request group membership'));
$this
->assertText('Request message', t('Request message does not appear.'));
$request = $this
->randomString();
$edit = array();
$edit['membership_fields[og_membership_request][und][0][value]'] = $request;
$this
->drupalPost(NULL, $edit, t('Join'));
$og_membership = og_get_group_membership($group->gid, 'user', $web_user->uid);
$this
->assertEqual($request, $og_membership->og_membership_request[LANGUAGE_NONE][0]['value'], t('User request was saved in group membership.'));
$this
->drupalGet('node/' . $node->nid);
$this
->assertText(t('Unsubscribe from group'), t('Member gets correct unsubscribe text.'));
$this
->clickLink(t('Unsubscribe from group'));
$this
->drupalPost(NULL, array(), t('Remove'));
$this
->assertFalse(og_is_member($group->gid, 'user', $web_user, array(
OG_STATE_ACTIVE,
OG_STATE_PENDING,
)), t('User unsubscribed from group.'));
$roles = array_flip(og_get_global_roles());
$rid = $roles[OG_ANONYMOUS_ROLE];
$permissions = array(
'subscribe without approval' => 1,
);
og_role_change_permissions($rid, $permissions);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText(t('Subscribe to group'), t('Non-member with "subscribe without approval" gets correct text.'));
$this
->clickLink(t('Subscribe to group'));
$this
->assertNoText('Request message', t('Request message does not appear.'));
$this
->drupalPost(NULL, array(), t('Join'));
$this
->assertTrue(og_is_member($group->gid, 'user', $web_user), t('User subscribed to group'));
}
}
class OgUiManagePeopleTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Organic groups UI manage people',
'description' => 'Verify the people management functionality.',
'group' => 'Organic groups UI',
);
}
function setUp() {
parent::setUp('og_ui', 'entity_test');
module_enable(array(
'entity_feature',
));
og_create_field(OG_GROUP_FIELD, 'entity_test', 'main');
}
function testOgUiAddPeople() {
$admin_user = $this
->drupalCreateUser();
$this
->drupalLogin($admin_user);
$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);
foreach (og_group_content_states() as $state => $name) {
$web_user = $this
->drupalCreateUser();
$edit = array();
$edit['og_add_user'] = $web_user->name;
$edit['og_add_user_state'] = $state;
$this
->drupalPost('group/entity_test/' . $entity->pid . '/admin/people/add-user', $edit, t('Add users'));
$web_user = user_load($web_user->uid, TRUE);
$this
->assertTrue(og_is_member($group->gid, 'user', $web_user, array(
$state,
)), t('User was added to the group with @name state.', array(
'@name' => $name,
)));
}
$edit = array();
$edit['og_add_user'] = $this
->randomName();
$this
->drupalPost('group/entity_test/' . $entity->pid . '/admin/people/add-user', $edit, t('Add users'));
$this
->assertText(t('You have entered an invalid user name.'), t('Invalid user name not added to group.'));
}
}
class OgUiUpgradePathTestCase extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Organic groups UI upgrade path',
'description' => 'Tests the upgrade path of Organic groups UI.',
'group' => 'Organic groups UI',
);
}
public function setUp() {
$this->databaseDumpFiles = array(
drupal_get_path('module', 'og_ui') . '/tests/drupal-6.og-ui.database.php',
);
parent::setUp();
$this
->performUpgrade();
module_enable(array(
'entity',
));
module_load_include('inc', 'entity', 'includes/entity');
module_load_include('inc', 'entity', 'includes/entity.controller');
module_enable(array(
'og_migrate',
'og_ui',
));
menu_rebuild();
variable_set('og_update_batch_size', 3);
$this
->drupalLogout();
$admin_user = $this
->drupalCreateUser(array(
'access administration pages',
));
$this
->drupalLogin($admin_user);
_field_info_collate_fields(TRUE);
_field_info_collate_types(TRUE);
}
public function testOgUiUpgrade() {
$edit = array(
'migrate[upgrade_group]' => TRUE,
'migrate[upgrade_group_visibility]' => TRUE,
);
$this
->drupalPost('admin/config/group/group-migrate', $edit, t('Migrate'));
$nodes_info = array(
1 => array(
'name' => t('open'),
'anon' => array(
'subscribe' => FALSE,
'subscribe without approval' => TRUE,
),
),
2 => array(
'name' => t('moderated'),
'anon' => array(
'subscribe' => TRUE,
'subscribe without approval' => FALSE,
),
),
3 => array(
'name' => t('invite only'),
'anon' => array(
'subscribe' => FALSE,
'subscribe without approval' => FALSE,
),
),
4 => array(
'name' => t('closed'),
'anon' => array(
'subscribe' => FALSE,
'subscribe without approval' => FALSE,
),
'auth' => array(
'unsubscribe' => FALSE,
),
),
);
foreach ($nodes_info as $nid => $node_info) {
$node_info += array(
'auth' => array(
'unsubscribe' => TRUE,
),
);
$node = node_load($nid);
$this
->assertEqual($node->{OG_DEFAULT_ACCESS_FIELD}[LANGUAGE_NONE][0]['value'], 1, t('Organic groups role and permissions field found and is enabled.'));
$group = og_get_group('node', $nid);
$this
->assertTrue($group, t('Node ID @nid is a group.', array(
'@nid' => $nid,
)));
$roles = og_roles($group->gid);
$permissions = og_role_permissions($roles);
$anon_rid = array_search(OG_ANONYMOUS_ROLE, $roles);
$auth_rid = array_search(OG_AUTHENTICATED_ROLE, $roles);
$this
->assertEqual($permissions[$anon_rid], array_filter($node_info['anon']), t('Correct permissions were set for non-member role in @type group.', array(
'@type' => $node_info['name'],
)));
$this
->assertEqual($permissions[$auth_rid], array_filter($node_info['auth']), t('Correct permissions were set for member role in @type group.', array(
'@type' => $node_info['name'],
)));
}
}
}