2
// $Id: og.subscribe.test,v 1.21 2008/11/03 00:26:48 weitzman Exp $
6
* Tests for membership related operations in the organic groups module.
9
require_once drupal_get_path('module', 'og') . '/tests/og_testcase.php';
11
class OgSubscribe extends OgTestCase {
14
'name' => t('Organic groups membership tests'),
15
'description' => t("Tests membership functionality and asserts correct behavior with all the different selective settings (e.g. open, moderated, etc'). Note: requires Views"),
16
'group' => t('Organic groups'),
21
* Implementation of setUp().
24
parent::setUp('og', 'og_access');
25
// Create a user with admin permissions.
26
$this->web_admin = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'access administration pages', 'administer site configuration', 'administer organic groups'));
27
$this->drupalLogin($this->web_admin);
29
// Create a group node content type.
30
$og_group_type = $this->drupalCreateContentType();
31
variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
33
// Rebuild the menu so the new content types will appear in the menu.
36
// Create groups with different visibility (open, moderated, etc').
37
$this->selective = array('open' => OG_OPEN, 'moderated' => OG_MODERATED, 'invite' => OG_INVITE_ONLY, 'closed' => OG_CLOSED);
38
$this->nodes = array();
39
foreach ($this->selective as $key => $selective) {
40
// Create a group node and save the node in $this.
41
$this->nodes[$key] = node_load($this->addOgGroup($og_group_type->name, $selective));
44
// Create web user that will join the groups.
45
$this->web_user = $this->drupalCreateUser(array('access content'));
49
* Test a web user subscribing and unsubscribing a group.
51
function testWebUserSubscribeOg() {
52
$this->drupalLogin($this->web_user);
53
foreach ($this->selective as $key => $selective) {
55
$this->drupalGet('og/subscribe/'. $this->nodes[$key]->nid);
56
if ($key == 'open' || $key == 'moderated') {
57
$this->assertRaw(t('Are you sure you want to join the group %title?', array('%title' => $this->nodes[$key]->title)), t('Subscribe to @selective group text found.', array('@selective' => $key)));
58
// Click the join button.
59
$this->drupalPost(NULL, array(), t('Join'));
60
// Assert membership approval, waiting for approval text.
61
$this->assertRaw(t($key == 'open' ? 'You are now a member of the %title.' : 'Membership request to the %title group awaits approval by an administrator.', array('%title' => $this->nodes[$key]->title)), t('Subscribed @selective group text found.', array('@selective' => $key)));
62
// Assert user is properly subscribed to open group.
64
// Only in the 'open' group the web user is considered subscribed.
65
$this->assertTrue(array_key_exists($this->nodes[$key]->nid, og_get_subscriptions($this->web_user->uid, 1, TRUE)), t('Subscribed open group is loaded into user object.'));
68
// Unsubscribe a group.
69
$this->drupalGet('og/unsubscribe/'. $this->nodes[$key]->nid .'/'. $this->web_user->uid);
70
$this->assertRaw(t('Are you sure you want to remove @user from the group %title?', array('@user' => $this->web_user->name, '%title' => $this->nodes[$key]->title)), t('Unsubscribe @selective group text found.', array('@selective' => $key)));
71
// Click the join button.
72
$this->drupalPost(NULL, array(), t('Remove'));
73
// Assert membership removal.
74
$this->assertRaw(t('%user removed from %group.', array('%user' => $this->web_user->name, '%group' => $this->nodes[$key]->title)), t('Confirmation of unsubscribing @selective group text found.', array('@selective' => $key)));
75
// Assert user is properly removed to group.
77
// Assert the group was removed from web user.
78
$this->assertFalse(array_key_exists($this->nodes[$key]->nid, og_get_subscriptions($this->web_user->uid, 1, TRUE)), t('Open group was removed from the og_uid table.'));
82
// Assert a 403 page is given.
83
$this->assertResponse(403, t('User got a 403 page while trying to access @selective group subscription.', array('@selective' => $key)));