~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/og/tests/og.subscribe.test

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: og.subscribe.test,v 1.21 2008/11/03 00:26:48 weitzman Exp $
 
3
 
 
4
/**
 
5
 * @file
 
6
 * Tests for membership related operations in the organic groups module.
 
7
 */
 
8
 
 
9
require_once drupal_get_path('module', 'og') . '/tests/og_testcase.php';
 
10
 
 
11
class OgSubscribe extends OgTestCase {
 
12
  function getInfo() {
 
13
    return array(
 
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'),
 
17
    );
 
18
  }
 
19
 
 
20
  /**
 
21
   * Implementation of setUp().
 
22
   */
 
23
  function 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);
 
28
 
 
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');
 
32
 
 
33
    // Rebuild the menu so the new content types will appear in the menu.
 
34
    menu_rebuild();
 
35
 
 
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));
 
42
    }
 
43
 
 
44
    // Create web user that will join the groups.
 
45
    $this->web_user = $this->drupalCreateUser(array('access content'));
 
46
  }
 
47
 
 
48
  /**
 
49
   * Test a web user subscribing and unsubscribing a group.
 
50
   */
 
51
  function testWebUserSubscribeOg() {
 
52
    $this->drupalLogin($this->web_user);
 
53
    foreach ($this->selective as $key => $selective) {
 
54
      // Get the join page.
 
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.
 
63
        if ($key == 'open') {
 
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.'));
 
66
        }
 
67
 
 
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.
 
76
        if ($key == 'open') {
 
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.'));
 
79
        }
 
80
      }
 
81
      else {
 
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)));
 
84
      }
 
85
    }
 
86
  }
 
87
 
 
88
}