1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test the UUID User Services integration.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test the UUID User Services integration.
|
10
|
*/
|
11
|
class UuidUserServicesTest extends ServicesWebTestCase {
|
12
|
|
13
|
/**
|
14
|
* The endpoint configuration.
|
15
|
*
|
16
|
* @var object
|
17
|
*/
|
18
|
protected $endpoint = NULL;
|
19
|
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
public static function getInfo() {
|
24
|
return array(
|
25
|
'name' => 'UUID User Services tests',
|
26
|
'description' => 'Test the user services resource UUID methods and actions.',
|
27
|
'group' => 'UUID',
|
28
|
);
|
29
|
}
|
30
|
|
31
|
/**
|
32
|
* {@inheritdoc}
|
33
|
*/
|
34
|
public function setUp() {
|
35
|
parent::setUp(
|
36
|
'ctools',
|
37
|
'services',
|
38
|
'rest_server',
|
39
|
'uuid_services'
|
40
|
);
|
41
|
$this->endpoint = $this->saveNewEndpoint();
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* {@inheritdoc}
|
46
|
*/
|
47
|
public function saveNewEndpoint() {
|
48
|
$edit = $this->populateEndpointFAPI();
|
49
|
$endpoint = new stdClass();
|
50
|
$endpoint->disabled = FALSE;
|
51
|
$endpoint->api_version = 3;
|
52
|
$endpoint->name = $edit['name'];
|
53
|
$endpoint->server = $edit['server'];
|
54
|
$endpoint->path = $edit['path'];
|
55
|
$endpoint->authentication = array(
|
56
|
'services' => 'services',
|
57
|
);
|
58
|
$endpoint->server_settings = array(
|
59
|
'formatters' => array(
|
60
|
'json' => TRUE,
|
61
|
'bencode' => TRUE,
|
62
|
'rss' => TRUE,
|
63
|
'plist' => TRUE,
|
64
|
'xmlplist' => TRUE,
|
65
|
'php' => TRUE,
|
66
|
'yaml' => TRUE,
|
67
|
'jsonp' => FALSE,
|
68
|
'xml' => FALSE,
|
69
|
),
|
70
|
'parsers' => array(
|
71
|
'application/x-yaml' => TRUE,
|
72
|
'application/json' => TRUE,
|
73
|
'application/vnd.php.serialized' => TRUE,
|
74
|
'application/plist' => TRUE,
|
75
|
'application/plist+xml' => TRUE,
|
76
|
'application/x-www-form-urlencoded' => TRUE,
|
77
|
'multipart/form-data' => TRUE,
|
78
|
),
|
79
|
);
|
80
|
$endpoint->resources = array(
|
81
|
'user' => array(
|
82
|
'operations' => array(
|
83
|
'create' => array(
|
84
|
'enabled' => 1,
|
85
|
),
|
86
|
'retrieve' => array(
|
87
|
'enabled' => 1,
|
88
|
),
|
89
|
'update' => array(
|
90
|
'enabled' => 1,
|
91
|
),
|
92
|
'delete' => array(
|
93
|
'enabled' => 1,
|
94
|
),
|
95
|
'index' => array(
|
96
|
'enabled' => 1,
|
97
|
),
|
98
|
),
|
99
|
),
|
100
|
);
|
101
|
$endpoint->debug = 1;
|
102
|
$endpoint->export_type = FALSE;
|
103
|
services_endpoint_save($endpoint);
|
104
|
$endpoint = services_endpoint_load($endpoint->name);
|
105
|
$this->assertTrue($endpoint->name == $edit['name'], 'Endpoint successfully created');
|
106
|
return $endpoint;
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Tests user Retrieve.
|
111
|
*/
|
112
|
public function testUserRetrieve() {
|
113
|
$admin_user = $this->drupalCreateUser(array(
|
114
|
'administer services',
|
115
|
'administer users',
|
116
|
));
|
117
|
$this->drupalLogin($admin_user);
|
118
|
$other_user = $this->drupalCreateUser();
|
119
|
|
120
|
// Verify user is found.
|
121
|
$response = $this->servicesGet($this->endpoint->path . '/user/' . $other_user->uuid);
|
122
|
$this->assertTrue($other_user->uuid == $response['body']->uuid,
|
123
|
'Successfully received User info');
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Tests user Update his own account.
|
128
|
*/
|
129
|
public function testUserUpdate() {
|
130
|
$admin_user = $this->drupalCreateUser(array(
|
131
|
'administer services',
|
132
|
'administer users',
|
133
|
'administer permissions',
|
134
|
));
|
135
|
$this->drupalLogin($admin_user);
|
136
|
|
137
|
$other_user = $this->drupalCreateUser();
|
138
|
$update = array(
|
139
|
'uuid' => $other_user->uuid,
|
140
|
'roles' => array(
|
141
|
'2' => 'authenticated user',
|
142
|
'3' => 'administrator',
|
143
|
),
|
144
|
);
|
145
|
$this->servicesPut($this->endpoint->path . '/user/' . $other_user->uuid, $update);
|
146
|
$user_after_update = user_load($other_user->uid, TRUE);
|
147
|
$this->assertTrue(in_array('administrator', $user_after_update->roles), 'Administrator role successfully added');
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Tests user Update another account fail with no permissions.
|
152
|
*/
|
153
|
public function testUserUpdatePermFail() {
|
154
|
$user = $this->drupalCreateUser();
|
155
|
$this->drupalLogin($user);
|
156
|
|
157
|
$other_user = $this->drupalCreateUser();
|
158
|
|
159
|
$update = array(
|
160
|
'uuid' => $other_user->uuid,
|
161
|
'name' => 'test_edit',
|
162
|
'roles' => array(
|
163
|
'2' => 'authenticated user',
|
164
|
'3' => 'administrator',
|
165
|
),
|
166
|
);
|
167
|
$response = $this->servicesPut($this->endpoint->path . '/user/' . $other_user->uuid, $update);
|
168
|
$user_after_update = user_load($other_user->uid, TRUE);
|
169
|
$this->assertNotEqual($update['name'], $user_after_update->name, 'User name was not updated without the needed permissions');
|
170
|
$this->assertFalse(in_array('administrator', $user_after_update->roles), 'Administrator role was not added without the needed permissions');
|
171
|
$this->assertTrue($response['code'] == 403,
|
172
|
'Updating the user failed without the needed permissions');
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* Tests user Update his own account fail with no permissions.
|
177
|
*/
|
178
|
public function testUserOwnUpdatePermFail() {
|
179
|
$user = $this->drupalCreateUser([
|
180
|
'access user profiles',
|
181
|
]);
|
182
|
$this->drupalLogin($user);
|
183
|
$user = user_load($user->uid, TRUE);
|
184
|
|
185
|
$update = array(
|
186
|
'uuid' => $user->uuid,
|
187
|
'roles' => array(
|
188
|
'2' => 'authenticated user',
|
189
|
'3' => 'administrator',
|
190
|
),
|
191
|
);
|
192
|
$this->servicesPut($this->endpoint->path . '/user/' . $user->uuid, $update);
|
193
|
$user_after_update = user_load($user->uid, TRUE);
|
194
|
$this->assertFalse(in_array('administrator', $user_after_update->roles), 'Administrator role was not added without the needed permissions');
|
195
|
$this->assertEqual($user->roles, $user_after_update->roles, 'Existing roles persist after update.');
|
196
|
}
|
197
|
|
198
|
/**
|
199
|
* Tests user Delete.
|
200
|
*/
|
201
|
public function testUserDelete() {
|
202
|
$admin_user = $this->drupalCreateUser(array(
|
203
|
'administer services',
|
204
|
'administer users',
|
205
|
));
|
206
|
$this->drupalLogin($admin_user);
|
207
|
|
208
|
$other_user = $this->drupalCreateUser();
|
209
|
|
210
|
$this->servicesDelete($this->endpoint->path . '/user/' . $other_user->uuid);
|
211
|
$user_after_update = user_load($other_user->uid, TRUE);
|
212
|
$this->assertTrue(empty($user_after_update), 'User was deleted');
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* Tests user Delete fail with no permissions.
|
217
|
*/
|
218
|
public function testUserDeletePermFail() {
|
219
|
$user = $this->drupalCreateUser();
|
220
|
$this->drupalLogin($user);
|
221
|
|
222
|
$other_user = $this->drupalCreateUser();
|
223
|
|
224
|
$response = $this->servicesDelete($this->endpoint->path . '/user/' . $other_user->uuid);
|
225
|
$user_after_update = user_load($other_user->uid, TRUE);
|
226
|
$this->assertTrue(!empty($user_after_update), 'User was not deleted without the needed permissions');
|
227
|
$this->assertTrue($response['code'] == 403,
|
228
|
'Deleting the user failed without the needed permissions');
|
229
|
}
|
230
|
|
231
|
}
|