-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathog.test
More file actions
123 lines (96 loc) · 4.68 KB
/
Copy pathog.test
File metadata and controls
123 lines (96 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
// $Id$
/**
* Test the organic groups content handeling.
*/
class OgTypeTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Organic groups content types',
'description' => 'Test the organic groups group node and group post creation.',
'group' => 'Organic groups',
);
}
function setUp() {
parent::setUp('og');
}
function testOgType() {
$admin_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
$this->drupalLogin($admin_user);
$this->drupalGet('admin/structure/types/add');
// Assert OG default types exist.
$this->assertText(t('Group node'), t('Group node option was found.'));
$this->assertText(t('group post'), t('Group post option was found.'));
// Create group content type.
$group = $this->drupalCreateContentType(array(), array('og_group_type' => 'group'));
// Create post content type.
$group_post = $this->drupalCreateContentType(array(), array('og_group_post_type' => 'group post'));
$this->assertTrue(og_is_group_post_type($group_post->type), t('Content type is group post.'));
// Assert group post fields were added to the content type.
$this->drupalGet('node/add/' . $group_post->type);
$this->assertText(t('Groups audience'), t('Groups audience field was found.'));
}
}
class OgUserPermissionsTestCase extends DrupalWebTestCase {
protected $admin_user;
protected $rid;
public static function getInfo() {
return array(
'name' => 'Organic groups role permissions',
'description' => 'Verify that role permissions can be added and removed via the permissions page of the group.',
'group' => 'Organic groups'
);
}
function setUp() {
parent::setUp('og');
$this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
$this->drupalLogin($this->admin_user);
// Create group content type.
$group_type = $this->drupalCreateContentType(array('og_content_type_usage' => 'group'));
$this->group_type= $group_type->type;
$group = $this->drupalCreateNode(array('type' => $group_type->type));
$this->group_nid = $group->nid;
}
/**
* Change user permissions and check og_user_access().
*/
function testOgUserPermissionChanges() {
$account = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
$this->drupalLogin($account);
// Get the role ID of the anonymous user.
$roles = og_get_group_default_roles($this->group_nid);
// Add a permission.
$this->assertFalse(og_user_access($this->group_nid, 'unsubscribe', $account), t('User does not have "Unsubscribe user from group" permission.'));
$edit = array();
$edit[$roles[OG_ANONYMOUS_ROLE] . '[unsubscribe]'] = TRUE;
$this->drupalPost('og/' . $this->group_nid . '/admin/people/permissions', $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), t('Successful save message displayed.'));
$this->assertTrue(og_user_access($this->group_nid, 'unsubscribe', $account), t('User now has "Unsubscribe user from group" permission.'));
// Remove a permission.
$edit = array();
$edit[$rid . '[unsubscribe]'] = FALSE;
$this->drupalPost('og/' . $this->group_nid . '/admin/people/permissions', $edit, t('Save permissions'));
$this->assertFalse(og_user_access($this->group_nid, 'unsubscribe', $account), t('User no longer has "Unsubscribe user from group" permission.'));
}
/**
* Verify proper permission changes by og_user_role_change_permissions().
*/
function __testOgUserRoleChangePermissions() {
$rid = $this->rid;
$account = $this->admin_user;
// Verify current permissions.
$this->assertFalse(user_access('administer nodes', $account), t('User does not have "administer nodes" permission.'));
$this->assertTrue(user_access('access user profiles', $account), t('User has "access user profiles" permission.'));
$this->assertTrue(user_access('administer site configuration', $account), t('User has "administer site configuration" permission.'));
// Change permissions.
$permissions = array(
'administer nodes' => 1,
'access user profiles' => 0,
);
og_user_role_change_permissions($rid, $permissions);
// Verify proper permission changes.
$this->assertTrue(user_access('administer nodes', $account), t('User now has "administer nodes" permission.'));
$this->assertFalse(user_access('access user profiles', $account), t('User no longer has "access user profiles" permission.'));
$this->assertTrue(user_access('administer site configuration', $account), t('User still has "administer site configuration" permission.'));
}
}