1
|
<?php
|
2
|
// $Id:
|
3
|
|
4
|
class AclWebTestCase extends DrupalWebTestCase {
|
5
|
|
6
|
public static function getInfo() {
|
7
|
return array(
|
8
|
'name' => 'ACL access permissions',
|
9
|
'description' => 'Test ACL permissions for reading a node.',
|
10
|
'group' => 'ACL',
|
11
|
);
|
12
|
}
|
13
|
|
14
|
/**
|
15
|
* Implementation setUp().
|
16
|
*/
|
17
|
function setUp() {
|
18
|
parent::setUp('acl', 'acl_node_test');
|
19
|
$web_user = $this->drupalCreateUser(array('create page content'));
|
20
|
$this->drupalLogin($web_user);
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* Includes acl_create_acl, acl_delete_acl, acl_get_id_by_name
|
25
|
*/
|
26
|
function testNodeAclCreateDelete() {
|
27
|
// Add a node.
|
28
|
$node1 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
|
29
|
$this->assertTrue(node_load($node1->nid), t('Page node created.'));
|
30
|
|
31
|
acl_create_acl('test1', $node1->title);
|
32
|
$acl_id = acl_get_id_by_name('test1', $node1->title);
|
33
|
$this->assertNotNull($acl_id, t('ACL ID was succesfully found.'), $group = 'ACL');
|
34
|
$records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id))->fetchAll();
|
35
|
$this->assertEqual(count($records), 1, t('ACL was succesfully created.'), $group = 'ACL');
|
36
|
acl_delete_acl($records[0]->acl_id);
|
37
|
|
38
|
$records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(':acl_id' => $records[0]->acl_id))->fetchAll();
|
39
|
$this->pass(var_export($records, TRUE));
|
40
|
$this->assertEqual(count($records), 0, t('ACL was succesfully removed.'), $group = 'ACL');
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Includes acl_add_user, acl_remove_user, acl_has_users,
|
45
|
* acl_get_id_by_name, acl_has_user, acl_get_uids
|
46
|
*/
|
47
|
function testNodeAclSingleUserAddRemove() {
|
48
|
// Add a node.
|
49
|
$node1 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
|
50
|
$this->assertTrue(node_load($node1->nid), t('Page node created.'));
|
51
|
|
52
|
acl_create_acl('test2', $node1->title);
|
53
|
// Check to see if grants added by node_test_node_access_records()
|
54
|
// made it in.
|
55
|
$acl_id = acl_get_id_by_name('test2', $node1->title);
|
56
|
$this->assertNotNull($acl_id, t('ACL ID was succesfully found.'), $group = 'ACL');
|
57
|
$records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id))->fetchAll();
|
58
|
$this->assertEqual(count($records), 1, t('ACL was succesfully created.'), $group = 'ACL');
|
59
|
|
60
|
// Add user (can't we use the user created in setup?).
|
61
|
$web_user_1 = $this->drupalCreateUser();
|
62
|
//$this->drupalLogin($web_user);
|
63
|
acl_add_user($acl_id, $web_user_1->uid);
|
64
|
$records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(':uid' => $web_user_1->uid))->fetchAll();
|
65
|
// Verify user is added.
|
66
|
$this->assertEqual(count($records), 1, t('User was succesfully added.'), $group = 'ACL');
|
67
|
|
68
|
// Remove user.
|
69
|
acl_remove_user($acl_id, $web_user_1->uid);
|
70
|
$records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(':uid' => $web_user_1->uid))->fetchAll();
|
71
|
// Verify user is removed.
|
72
|
$this->assertEqual(count($records), 0, t('User was succesfully removed.'), $group = 'ACL');
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Includes acl_node_add_acl, acl_node_remove_acl, acl_node_clear_acls
|
77
|
*/
|
78
|
function testNodeAclAddRemoveFromNode() {
|
79
|
// Add nodes.
|
80
|
$node1 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
|
81
|
$this->assertTrue(node_load($node1->nid), t('Page node created.'));
|
82
|
$node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
|
83
|
$this->assertTrue(node_load($node2->nid), t('Page node created.'));
|
84
|
$node3 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
|
85
|
$this->assertTrue(node_load($node3->nid), t('Page node created.'));
|
86
|
|
87
|
// Create an ACL and add nodes.
|
88
|
$acl_id1 = acl_create_acl('test3', 'test', 1);
|
89
|
$this->assertNotNull($acl_id1, t('ACL ID was created.'), $group = 'ACL');
|
90
|
// Add two nodes.
|
91
|
$query = db_select('node', 'n')
|
92
|
->fields('n', array('nid'))
|
93
|
->condition('nid', array($node1->nid, $node2->nid), 'IN');
|
94
|
acl_add_nodes($query, $acl_id1, 1, 1, 1);
|
95
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id1))->fetchField();
|
96
|
$this->assertEqual($count, 2, t("2 nodes under control ($count)."), $group = 'ACL');
|
97
|
// Add a third node.
|
98
|
acl_node_add_acl($node3->nid, $acl_id1, 1, 1, 1);
|
99
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id1))->fetchField();
|
100
|
$this->assertEqual($count, 3, t('3 nodes under control.'), $group = 'ACL');
|
101
|
// Add the second node again.
|
102
|
acl_node_add_acl($node2->nid, $acl_id1, 1, 1, 1);
|
103
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id1))->fetchField();
|
104
|
$this->assertEqual($count, 3, t('Still only 3 nodes under control.'), $group = 'ACL');
|
105
|
|
106
|
// Remove the second node again.
|
107
|
acl_node_remove_acl($node2->nid, $acl_id1);
|
108
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id1))->fetchField();
|
109
|
$this->assertEqual($count, 2, t('2 nodes left under control.'), $group = 'ACL');
|
110
|
// Remove the second node again.
|
111
|
acl_node_remove_acl($node2->nid, $acl_id1);
|
112
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id1))->fetchField();
|
113
|
$this->assertEqual($count, 2, t('Still 2 nodes left under control.'), $group = 'ACL');
|
114
|
|
115
|
// Create another ACL and add nodes.
|
116
|
$acl_id2 = acl_create_acl('test3', 'test', 2);
|
117
|
$this->assertNotNull($acl_id2, t('ACL ID was created.'), $group = 'ACL');
|
118
|
acl_node_add_acl($node1->nid, $acl_id2, 1, 1, 1);
|
119
|
acl_node_add_acl($node2->nid, $acl_id2, 1, 1, 1);
|
120
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id2))->fetchField();
|
121
|
$this->assertEqual($count, 2, t('2 nodes under control.'), $group = 'ACL');
|
122
|
// Remove a node (which has two ACLs).
|
123
|
acl_node_clear_acls($node1->nid, 'test3');
|
124
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id1))->fetchField();
|
125
|
$this->assertEqual($count, 1, t('1 node left under control.'), $group = 'ACL');
|
126
|
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(':acl_id' => $acl_id2))->fetchField();
|
127
|
$this->assertEqual($count, 1, t('1 node left under control.'), $group = 'ACL');
|
128
|
}
|
129
|
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* Included acl_node_delete
|
134
|
*/
|
135
|
function testNodeAclAddAndRemoveNode() {
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Included acl_user_cancel
|
140
|
*/
|
141
|
function testNodeAclAddAndRemoveUser() {
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Includes independ check of the permissions by checking the grants
|
146
|
* table AND by trying to view the node as a unauthorised user and an
|
147
|
* authorized user for each of the 3 use cases (view, edit, delete)
|
148
|
*/
|
149
|
function testNodeAclPermissionCheck() {
|
150
|
}
|