Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: profile.test,v 1.8 2008/04/01 23:33:54 boombatower Exp $
|
3 | |
|
4 | | class ProfileTestSingleTestCase extends DrupalTestCase {
|
5 | | function getInfo() {
|
6 | 1 | $modules = (module_list());
|
7 | 1 | return array('name' => 'Test Single field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
8 | | }
|
9 | |
|
10 | | function _rolesApi($op, $edit) {
|
11 | | if ($op == 'delete') {
|
12 | | $id = $edit['rid'];
|
13 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
14 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
15 | |
|
16 | | // Update the users who have this role set:
|
17 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
18 | | $uid = array();
|
19 | |
|
20 | | while ($u = db_fetch_object($result)) {
|
21 | | $uid[] = $u->uid;
|
22 | | }
|
23 | |
|
24 | | if ($uid) {
|
25 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
26 | | }
|
27 | |
|
28 | | // Users with only the deleted role are put back in the authenticated users pool.
|
29 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
30 | |
|
31 | | }
|
32 | | else if ($op == 'add') {
|
33 | | if (isset($edit['name'])) {
|
34 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
35 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
36 | | $rid = db_result($result);
|
37 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
38 | | return $rid;
|
39 | | }
|
40 | | else {
|
41 | | return 0;
|
42 | | }
|
43 | | }
|
44 | | }
|
45 | |
|
46 | | function testProfileSingle() {
|
47 | | $this->drupalModuleEnable('profile');
|
48 | | // create test user
|
49 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
50 | | $edit['perm'] = 'access administration pages, administer site configuration, administer users';
|
51 | | $rid = $this->_rolesApi('add', $edit );
|
52 | | $name = $this->randomName();
|
53 | | $pass = $this->randomName();
|
54 | | $mail = "$name@example.com";
|
55 | | unset($edit);
|
56 | | $edit['roles'] = array($rid => $rid);
|
57 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
58 | | //log in
|
59 | | $edit = array('name' => $name, 'pass' => $pass);
|
60 | | $this->drupalPost('user', $edit, t('Log in'));
|
61 | |
|
62 | | //wartosci
|
63 | | $my_category = 'Simpletest';
|
64 | | //single line textfield
|
65 | | $title = "single_" . $this->randomName(10);
|
66 | | $form_name = 'profile_' . $title;
|
67 | | $explanation = $this->randomName(50);
|
68 | | $edit = array('category' => $my_category,
|
69 | | 'title' => $title,
|
70 | | 'name' => $form_name,
|
71 | | 'explanation' => $explanation,
|
72 | | );
|
73 | | $this->drupalPost('admin/user/profile/add/textfield', $edit, t('Save field'), 0);
|
74 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
75 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
76 | |
|
77 | | // checking simple fields
|
78 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
79 | |
|
80 | | // checking field
|
81 | | $this->assertField($form_name , t('Found form named @name', array('@name' => $form_name)));
|
82 | | // checking name
|
83 | | $this->assertText($title, "Checking title for ". $title);
|
84 | | // checking explanation
|
85 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
86 | |
|
87 | | // ok, now let put some data
|
88 | | unset($edit);
|
89 | | $edit = array();
|
90 | | $checking = array();
|
91 | | $edit[$form_name] = $this->randomName(20);
|
92 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save') , 0);
|
93 | | $this->drupalGet("user/". $user->uid);
|
94 | |
|
95 | | // checking profile page
|
96 | | $this->assertText($edit[$form_name], "Checking ". $edit[$form_name]);
|
97 | | $this->assertText($title, "Checking $title");
|
98 | | // update field
|
99 | | $new_title = $this->randomName(20);
|
100 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field') , 0);
|
101 | | $this->drupalGet("admin/user/profile");
|
102 | | $this->assertText($new_title, "Checking updated field");
|
103 | | // deleting field
|
104 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
105 | | $this->drupalGet("admin/user/profile");
|
106 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
107 | |
|
108 | | // delete test user and roles
|
109 | | if ($user->uid > 0) {
|
110 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
111 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
112 | | module_invoke_all('user', 'delete', '', $user);
|
113 | | }
|
114 | |
|
115 | | //delete roles
|
116 | | $edit['rid'] = $rid;
|
117 | | $this->_rolesApi('delete', $edit);
|
118 | | }
|
119 | |
|
120 | | }
|
121 | |
|
122 | | class ProfileTestTextareaTestCase extends DrupalTestCase {
|
123 | | function getInfo() {
|
124 | 1 | $modules = (module_list());
|
125 | 1 | return array('name' => 'Test Textarea field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
126 | | }
|
127 | |
|
128 | | function _rolesApi($op, $edit) {
|
129 | | if ($op == 'delete') {
|
130 | | $id = $edit['rid'];
|
131 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
132 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
133 | |
|
134 | | // Update the users who have this role set:
|
135 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
136 | | $uid = array();
|
137 | |
|
138 | | while ($u = db_fetch_object($result)) {
|
139 | | $uid[] = $u->uid;
|
140 | | }
|
141 | |
|
142 | | if ($uid) {
|
143 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
144 | | }
|
145 | |
|
146 | | // Users with only the deleted role are put back in the authenticated users pool.
|
147 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
148 | |
|
149 | | }
|
150 | | else if ($op == 'add') {
|
151 | | if (isset($edit['name'])) {
|
152 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
153 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
154 | | $rid = db_result($result);
|
155 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
156 | | return $rid;
|
157 | | }
|
158 | | else {
|
159 | | return 0;
|
160 | | }
|
161 | | }
|
162 | | }
|
163 | |
|
164 | | function testProfileSingle() {
|
165 | | $this->drupalModuleEnable('profile');
|
166 | | // create test user
|
167 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
168 | | $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
169 | | $rid = $this->_rolesApi('add', $edit );
|
170 | | $name = $this->randomName();
|
171 | | $pass = $this->randomName();
|
172 | | $mail = "$name@example.com";
|
173 | | unset($edit);
|
174 | | $edit['roles'] = array($rid => $rid);
|
175 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
176 | | //log in
|
177 | | $edit = array('name' => $name, 'pass' => $pass);
|
178 | | $this->drupalPost('user', $edit, t('Log in'), 0 );
|
179 | |
|
180 | | //wartosci
|
181 | | $my_category = 'Simpletest';
|
182 | | //single line textfield
|
183 | | $title = "single_" . $this->randomName(10);
|
184 | | $form_name = 'profile_' . $title;
|
185 | | $explanation = $this->randomName(50);
|
186 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
|
187 | | $this->drupalPost("admin/user/profile/add/textarea", $edit, t('Save field'), 0);
|
188 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
189 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
190 | |
|
191 | | // checking simple fields
|
192 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
193 | |
|
194 | | // checking field
|
195 | | $this->assertField($form_name, '');
|
196 | | // checking name
|
197 | | $this->assertText($title, "Checking title for ". $title);
|
198 | | // checking explanation
|
199 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
200 | |
|
201 | | // ok, now let put some data
|
202 | | unset($edit);
|
203 | | $edit = array();
|
204 | | $checking = array();
|
205 | | $edit[$form_name] = $this->randomName(20);
|
206 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save'), 0);
|
207 | | $this->drupalGet("user/". $user->uid);
|
208 | |
|
209 | | // checking profile page
|
210 | | $this->assertText($edit[$form_name], "Checking ". $edit[$form_name]);
|
211 | | $this->assertText($title, "Checking $title");
|
212 | | // update field
|
213 | | $new_title = $this->randomName(20);
|
214 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field'), 0);
|
215 | | $this->drupalGet("admin/user/profile");
|
216 | | $this->assertText($new_title, "Checking updated field");
|
217 | | // deleting field
|
218 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
219 | | $this->drupalGet("admin/user/profile");
|
220 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
221 | |
|
222 | | // delete test user and roles
|
223 | | if ($user->uid > 0) {
|
224 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
225 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
226 | | module_invoke_all('user', 'delete', '', $user);
|
227 | | }
|
228 | |
|
229 | | //delete roles
|
230 | | $edit['rid'] = $rid;
|
231 | | $this->_rolesApi('delete', $edit);
|
232 | | }
|
233 | | }
|
234 | |
|
235 | |
|
236 | | class ProfileTestFreelistTestCase extends DrupalTestCase {
|
237 | | function getInfo() {
|
238 | 1 | $modules = (module_list());
|
239 | 1 | return array('name' => 'Test Freelist field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
240 | | }
|
241 | |
|
242 | | function _rolesApi($op, $edit) {
|
243 | | if ($op == 'delete') {
|
244 | | $id = $edit['rid'];
|
245 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
246 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
247 | |
|
248 | | // Update the users who have this role set:
|
249 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
250 | | $uid = array();
|
251 | |
|
252 | | while ($u = db_fetch_object($result)) {
|
253 | | $uid[] = $u->uid;
|
254 | | }
|
255 | |
|
256 | | if ($uid) {
|
257 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
258 | | }
|
259 | |
|
260 | | // Users with only the deleted role are put back in the authenticated users pool.
|
261 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
262 | |
|
263 | | }
|
264 | | else if ($op == 'add') {
|
265 | | if (isset($edit['name'])) {
|
266 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
267 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
268 | | $rid = db_result($result);
|
269 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
270 | | return $rid;
|
271 | | }
|
272 | | else {
|
273 | | return 0;
|
274 | | }
|
275 | | }
|
276 | | }
|
277 | |
|
278 | | function testProfileSingle() {
|
279 | | $this->drupalModuleEnable('profile');
|
280 | | // create test user
|
281 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
282 | | $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
283 | | $rid = $this->_rolesApi('add', $edit );
|
284 | | $name = $this->randomName();
|
285 | | $pass = $this->randomName();
|
286 | | $mail = "$name@example.com";
|
287 | | unset($edit);
|
288 | | $edit['roles'] = array($rid => $rid);
|
289 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
290 | | //log in
|
291 | | $edit = array('name' => $name, 'pass' => $pass);
|
292 | | $this->drupalPost('user', $edit, t('Log in'), 0 );
|
293 | |
|
294 | | //wartosci
|
295 | | $my_category = 'Simpletest';
|
296 | | //single line textfield
|
297 | | $title = "single_" . $this->randomName(10);
|
298 | | $form_name = 'profile_' . $title;
|
299 | | $explanation = $this->randomName(50);
|
300 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
|
301 | | $this->drupalPost("admin/user/profile/add/list", $edit, t('Save field'), 0);
|
302 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
303 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
304 | |
|
305 | | // checking simple fields
|
306 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
307 | |
|
308 | | // checking field
|
309 | | $this->assertField($form_name, '');
|
310 | | // checking name
|
311 | | $this->assertText($title, "Checking title for ". $title);
|
312 | | // checking explanation
|
313 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
314 | |
|
315 | | // ok, now let put some data
|
316 | | unset($edit);
|
317 | | $edit = array();
|
318 | | $checking = array();
|
319 | | $edit[$form_name] = $this->randomName(20);
|
320 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save'), 0);
|
321 | | $this->drupalGet("user/". $user->uid);
|
322 | |
|
323 | | // checking profile page
|
324 | | $this->assertText($edit[$form_name], "Checking ". $edit[$form_name]);
|
325 | | $this->assertText($title, "Checking $title");
|
326 | | // update field
|
327 | | $new_title = $this->randomName(20);
|
328 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field'), 0);
|
329 | | $this->drupalGet("admin/user/profile");
|
330 | | $this->assertText($new_title, "Checking updated field");
|
331 | | // deleting field
|
332 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
333 | | $this->drupalGet("admin/user/profile");
|
334 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
335 | |
|
336 | | // delete test user and roles
|
337 | | if ($user->uid > 0) {
|
338 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
339 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
340 | | module_invoke_all('user', 'delete', '', $user);
|
341 | | }
|
342 | |
|
343 | | //delete roles
|
344 | | $edit['rid'] = $rid;
|
345 | | $this->_rolesApi('delete', $edit);
|
346 | | }
|
347 | |
|
348 | | }
|
349 | |
|
350 | |
|
351 | | class ProfileTestCheckboxTestCase extends DrupalTestCase {
|
352 | | function getInfo() {
|
353 | 1 | $modules = (module_list());
|
354 | 1 | return array('name' => 'Test Checkbox field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
355 | | }
|
356 | |
|
357 | | function _rolesApi($op, $edit) {
|
358 | | if ($op == 'delete') {
|
359 | | $id = $edit['rid'];
|
360 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
361 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
362 | |
|
363 | | // Update the users who have this role set:
|
364 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
365 | | $uid = array();
|
366 | |
|
367 | | while ($u = db_fetch_object($result)) {
|
368 | | $uid[] = $u->uid;
|
369 | | }
|
370 | |
|
371 | | if ($uid) {
|
372 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
373 | | }
|
374 | |
|
375 | | // Users with only the deleted role are put back in the authenticated users pool.
|
376 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
377 | |
|
378 | | }
|
379 | | else if ($op == 'add') {
|
380 | | if (isset($edit['name'])) {
|
381 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
382 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
383 | | $rid = db_result($result);
|
384 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
385 | | return $rid;
|
386 | | }
|
387 | | else {
|
388 | | return 0;
|
389 | | }
|
390 | | }
|
391 | | }
|
392 | |
|
393 | | function testProfileCheckbox() {
|
394 | | $this->drupalModuleEnable('profile');
|
395 | | // create test user
|
396 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
397 | | $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
398 | | $rid = $this->_rolesApi('add', $edit );
|
399 | | $name = $this->randomName();
|
400 | | $pass = $this->randomName();
|
401 | | $mail = "$name@example.com";
|
402 | | unset($edit);
|
403 | | $edit['roles'] = array($rid => $rid);
|
404 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
405 | | //log in
|
406 | | $edit = array('name' => $name, 'pass' => $pass);
|
407 | | $this->drupalPost('user', $edit, t('Log in'), 0);
|
408 | |
|
409 | | //wartosci
|
410 | | $my_category = 'Simpletest';
|
411 | | //single line textfield
|
412 | | $title = "single_" . $this->randomName(10);
|
413 | | $form_name = 'profile_' . $title;
|
414 | | $explanation = $this->randomName(50);
|
415 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
|
416 | | $this->drupalPost("admin/user/profile/add/checkbox", $edit, t('Save field'), 0);
|
417 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
418 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
419 | |
|
420 | | // checking simple fields
|
421 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
422 | |
|
423 | | // checking field
|
424 | | $this->assertField($form_name, false);
|
425 | | // checking name
|
426 | | $this->assertText($title, "Checking title for ". $title);
|
427 | | // checking explanation
|
428 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
429 | |
|
430 | | // ok, now let put some data
|
431 | | unset($edit);
|
432 | | $edit = array();
|
433 | | $checking = array();
|
434 | | $edit[$form_name] = 1;
|
435 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save'), 0);
|
436 | | $this->drupalGet("user/". $user->uid);
|
437 | | // checking profile page
|
438 | | $this->assertText($title, "Checking checkbox");
|
439 | | $this->assertText($title, "Checking $title");
|
440 | | // update field
|
441 | | $new_title = $this->randomName(10);
|
442 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field'), 0);
|
443 | | $this->drupalGet("admin/user/profile");
|
444 | | $this->assertText($new_title, "Checking updated field");
|
445 | | // deleting field
|
446 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
447 | | $this->drupalGet("admin/user/profile");
|
448 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
449 | |
|
450 | | // delete test user and roles
|
451 | | if ($user->uid > 0) {
|
452 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
453 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
454 | | module_invoke_all('user', 'delete', '', $user);
|
455 | | }
|
456 | |
|
457 | | //delete roles
|
458 | | $edit['rid'] = $rid;
|
459 | | $this->_rolesApi('delete', $edit);
|
460 | | }
|
461 | | }
|
462 | |
|
463 | | class ProfileTestUrlTestCase extends DrupalTestCase {
|
464 | | function getInfo() {
|
465 | 1 | $modules = (module_list());
|
466 | 1 | return array('name' => 'Test Url field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
467 | | }
|
468 | |
|
469 | | function _rolesApi($op, $edit) {
|
470 | | if ($op == 'delete') {
|
471 | | $id = $edit['rid'];
|
472 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
473 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
474 | |
|
475 | | // Update the users who have this role set:
|
476 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
477 | | $uid = array();
|
478 | |
|
479 | | while ($u = db_fetch_object($result)) {
|
480 | | $uid[] = $u->uid;
|
481 | | }
|
482 | |
|
483 | | if ($uid) {
|
484 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
485 | | }
|
486 | |
|
487 | | // Users with only the deleted role are put back in the authenticated users pool.
|
488 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
489 | |
|
490 | | }
|
491 | | else if ($op == 'add') {
|
492 | | if (isset($edit['name'])) {
|
493 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
494 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
495 | | $rid = db_result($result);
|
496 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
497 | | return $rid;
|
498 | | }
|
499 | | else {
|
500 | | return 0;
|
501 | | }
|
502 | | }
|
503 | | }
|
504 | |
|
505 | | function testProfileSingle() {
|
506 | | $this->drupalVariableSet('user_register',1);
|
507 | | $this->drupalModuleEnable('profile');
|
508 | | // create test user
|
509 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
510 | | $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
511 | | $rid = $this->_rolesApi('add', $edit );
|
512 | | $name = $this->randomName();
|
513 | | $pass = $this->randomName();
|
514 | | $mail = "$name@example.com";
|
515 | | unset($edit);
|
516 | | $edit['roles'] = array($rid => $rid);
|
517 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
518 | | //log in
|
519 | | $edit = array('name' => $name, 'pass' => $pass);
|
520 | | $this->drupalPost('user', $edit, t('Log in'), 0);
|
521 | |
|
522 | | //wartosci
|
523 | | $my_category = 'Simpletest';
|
524 | | //single line textfield
|
525 | | $title = "single_" . $this->randomName(10);
|
526 | | $form_name = 'profile_' . $title;
|
527 | | $explanation = $this->randomName(50);
|
528 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
|
529 | | $this->drupalPost("admin/user/profile/add/url", $edit, t('Save field'), 0);
|
530 | | $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s'", $title));
|
531 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
532 | |
|
533 | | // checking simple fields
|
534 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
535 | |
|
536 | | // checking field
|
537 | | $this->assertField($form_name, '');
|
538 | | // checking name
|
539 | | $this->assertText($title, "Checking title for ". $title);
|
540 | | // checking explanation
|
541 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
542 | |
|
543 | | // ok, now let put some data
|
544 | | unset($edit);
|
545 | | $edit = array();
|
546 | | $checking = array();
|
547 | | $edit[$form_name] = 'http://www.' . $this->randomName(10). '.org';
|
548 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save'), 0);
|
549 | | $this->drupalGet("user/". $user->uid);
|
550 | |
|
551 | | // checking profile page
|
552 | | $this->assertText($edit[$form_name], "Checking ". $edit[$form_name]);
|
553 | | $this->assertText($title, "Checking $title");
|
554 | | // update field
|
555 | | $new_title = $this->randomName(20);
|
556 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field'), 0);
|
557 | | $this->drupalGet("admin/user/profile");
|
558 | | $this->assertText($new_title, "Checking updated field");
|
559 | | // deleting field
|
560 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
561 | | $this->drupalGet("admin/user/profile");
|
562 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
563 | |
|
564 | | // delete test user and roles
|
565 | | if ($user->uid > 0) {
|
566 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
567 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
568 | | module_invoke_all('user', 'delete', '', $user);
|
569 | | }
|
570 | |
|
571 | | //delete roles
|
572 | | $edit['rid'] = $rid;
|
573 | | $this->_rolesApi('delete', $edit);
|
574 | |
|
575 | | }
|
576 | | }
|
577 | |
|
578 | | class ProfileTestSelectionTestCase extends DrupalTestCase {
|
579 | | function getInfo() {
|
580 | 1 | $modules = (module_list());
|
581 | 1 | return array('name' => 'Test Selection field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
582 | | }
|
583 | |
|
584 | | function _rolesApi($op, $edit) {
|
585 | | if ($op == 'delete') {
|
586 | | $id = $edit['rid'];
|
587 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
588 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
589 | |
|
590 | | // Update the users who have this role set:
|
591 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
592 | | $uid = array();
|
593 | |
|
594 | | while ($u = db_fetch_object($result)) {
|
595 | | $uid[] = $u->uid;
|
596 | | }
|
597 | |
|
598 | | if ($uid) {
|
599 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
600 | | }
|
601 | |
|
602 | | // Users with only the deleted role are put back in the authenticated users pool.
|
603 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
604 | |
|
605 | | }
|
606 | | else if ($op == 'add') {
|
607 | | if (isset($edit['name'])) {
|
608 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
609 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
610 | | $rid = db_result($result);
|
611 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
612 | | return $rid;
|
613 | | }
|
614 | | else {
|
615 | | return 0;
|
616 | | }
|
617 | | }
|
618 | | }
|
619 | |
|
620 | | function testProfileSingle() {
|
621 | | $this->drupalModuleEnable('profile');
|
622 | | // create test user
|
623 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
624 | | $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
625 | | $rid = $this->_rolesApi('add', $edit );
|
626 | | $name = $this->randomName();
|
627 | | $pass = $this->randomName();
|
628 | | $mail = "$name@example.com";
|
629 | | unset($edit);
|
630 | | $edit['roles'] = array($rid => $rid);
|
631 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
632 | | //log in
|
633 | | $edit = array('name' => $name, 'pass' => $pass);
|
634 | | $this->drupalPost('user', $edit, t('Log in'), 0);
|
635 | |
|
636 | | //wartosci
|
637 | | $my_category = 'Simpletest';
|
638 | | //single line textfield
|
639 | | $title = "single_" . $this->randomName(10);
|
640 | | $form_name = 'profile_' . $title;
|
641 | | $explanation = $this->randomName(50);
|
642 | | $options = "";
|
643 | | for($i = 0; $i < 3; $i++)
|
644 | | $options .= $this->randomName(8) . "\n";
|
645 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation, 'options' => $options);
|
646 | | $this->drupalPost("admin/user/profile/add/selection", $edit, t('Save field'), 0);
|
647 | | $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s'", $title));
|
648 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
649 | |
|
650 | | // checking simple fields
|
651 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
652 | | // checking name
|
653 | | $this->assertText($title, "Checking title for ". $title);
|
654 | | // checking explanation
|
655 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
656 | | // can we choose something which doesn't come from the list ?
|
657 | | //$this->assertFalse($this->setField('edit['.$form_name .']', $this->randomName(10)));
|
658 | | // or can we choose each of our options
|
659 | | $op_tab = explode("\n", $options,3);
|
660 | | //foreach($op_tab as $option)
|
661 | | //$this->assertTrue($this->setField($form_name, $option));
|
662 | |
|
663 | |
|
664 | | // ok, now let put some data
|
665 | | unset($edit);
|
666 | | $edit = array();
|
667 | | $checking = array();
|
668 | | $element = rand(0,2);
|
669 | | $key = $form_name;
|
670 | | $edit[$key] = rtrim($op_tab[$element]);
|
671 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save'), 0);
|
672 | | $this->drupalGet("user/". $user->uid);
|
673 | |
|
674 | | // checking profile page
|
675 | | $this->assertText($edit[$form_name], "Checking ". $edit[$form_name]);
|
676 | | $this->assertText($title, "Checking $title");
|
677 | | // update field
|
678 | | $new_title = $this->randomName(20);
|
679 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field'), 0);
|
680 | | $this->drupalGet("admin/user/profile");
|
681 | | $this->assertText($new_title, "Checking updated field");
|
682 | | // deleting field
|
683 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
684 | | $this->drupalGet("admin/user/profile");
|
685 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
686 | |
|
687 | | // delete test user and roles
|
688 | | if ($user->uid > 0) {
|
689 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
690 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
691 | | module_invoke_all('user', 'delete', '', $user);
|
692 | | }
|
693 | |
|
694 | | //delete roles
|
695 | | $edit['rid'] = $rid;
|
696 | | $this->_rolesApi('delete', $edit);
|
697 | |
|
698 | | }
|
699 | |
|
700 | | }
|
701 | |
|
702 | |
|
703 | | class ProfileTestDateTestCase extends DrupalTestCase {
|
704 | | function getInfo() {
|
705 | 1 | $modules = (module_list());
|
706 | 1 | return array('name' => 'Test Date field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
|
707 | | }
|
708 | |
|
709 | | function _rolesApi($op, $edit) {
|
710 | | if ($op == 'delete') {
|
711 | | $id = $edit['rid'];
|
712 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
713 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
714 | |
|
715 | | // Update the users who have this role set:
|
716 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
717 | | $uid = array();
|
718 | |
|
719 | | while ($u = db_fetch_object($result)) {
|
720 | | $uid[] = $u->uid;
|
721 | | }
|
722 | |
|
723 | | if ($uid) {
|
724 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
725 | | }
|
726 | |
|
727 | | // Users with only the deleted role are put back in the authenticated users pool.
|
728 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
729 | |
|
730 | | }
|
731 | | else if ($op == 'add') {
|
732 | | if (isset($edit['name'])) {
|
733 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
734 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
735 | | $rid = db_result($result);
|
736 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
737 | | return $rid;
|
738 | | }
|
739 | | else {
|
740 | | return 0;
|
741 | | }
|
742 | | }
|
743 | | }
|
744 | |
|
745 | | function testProfileSingle() {
|
746 | | $this->drupalModuleEnable('profile');
|
747 | | // create test user
|
748 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
749 | | $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
750 | | $rid = $this->_rolesApi('add', $edit );
|
751 | | $name = $this->randomName();
|
752 | | $pass = $this->randomName();
|
753 | | $mail = "$name@example.com";
|
754 | | unset($edit);
|
755 | | $edit['roles'] = array($rid => $rid);
|
756 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
757 | | //log in
|
758 | | $edit = array('name' => $name, 'pass' => $pass);
|
759 | | $this->drupalPost('user', $edit, t('Log in'), 0);
|
760 | |
|
761 | | //wartosci
|
762 | | $my_category = 'Simpletest';
|
763 | | //single line textfield
|
764 | | $title = "single_" . $this->randomName(10);
|
765 | | $form_name = 'profile_' . $title;
|
766 | | $explanation = $this->randomName(50);
|
767 | | /* $options = "";
|
768 | | for($i = 0; $i < 3; $i++)
|
769 | | $options .= $this->randomName(8) . "\n";*/
|
770 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
|
771 | | $this->drupalPost("admin/user/profile/add/date", $edit, t('Save field'), 0);
|
772 | | $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s'", $title));
|
773 | | $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
|
774 | |
|
775 | | // checking simple fields
|
776 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
777 | | // checking name
|
778 | | $this->assertText($title, "Checking title for ". $title);
|
779 | | // checking explanation
|
780 | | $this->assertText($explanation, "Checking explanation for ". $title);
|
781 | | // checking days/month/years
|
782 | | //foreach(array('year', 'month', 'day') as $field)
|
783 | | //$this->assertFalse($this->setField('edit['.$form_name .']['. $field .']', $this->randomName(4)), 'Checking data field ['.$field.']');
|
784 | | // ok, now let put some data
|
785 | | // date 9-01-1983
|
786 | | unset($edit);
|
787 | | foreach(array('year' => 1983, 'month' => 'Jan', 'day' => 9) as $field => $v) {
|
788 | | $key = $form_name . '[' . $field . ']';
|
789 | | $edit[$key] = $v;
|
790 | | }
|
791 | |
|
792 | | list($format) = explode(' - ', variable_get('date_format_short', 'm/d/Y'), 2);
|
793 | |
|
794 | | $replace = array('d' => sprintf('%02d', 9),
|
795 | | 'j' => 9,
|
796 | | 'm' => sprintf('%02d', '1'),
|
797 | | 'M' => map_month(1),
|
798 | | 'Y' => 1983);
|
799 | | $data = strtr($format, $replace);
|
800 | | $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, t('Save'), 0);
|
801 | | $this->drupalGet("user/". $user->uid);
|
802 | |
|
803 | | // checking profile page
|
804 | | $this->assertText($data, "Checking date $data");
|
805 | | $this->assertText($title, "Checking $title");
|
806 | | // update field
|
807 | | $new_title = $this->randomName(20);
|
808 | | $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field'), 0);
|
809 | | $this->drupalGet("admin/user/profile");
|
810 | | $this->assertText($new_title, "Checking updated field");
|
811 | | // deleting field
|
812 | | $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0);
|
813 | | $this->drupalGet("admin/user/profile");
|
814 | | $this->assertNoText($new_title, "Checking deleted field $title");
|
815 | |
|
816 | | // delete test user and roles
|
817 | | if ($user->uid > 0) {
|
818 | | db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
|
819 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
820 | | module_invoke_all('user', 'delete', '', $user);
|
821 | | }
|
822 | |
|
823 | | //delete roles
|
824 | | $edit['rid'] = $rid;
|
825 | | $this->_rolesApi('delete', $edit);
|
826 | |
|
827 | | }
|
828 | |
|
829 | | }
|
830 | |
|
831 | |
|
832 | | class ProfileTest2TestCase extends DrupalTestCase {
|
833 | | function getInfo() {
|
834 | 1 | $modules = (module_list());
|
835 | 1 | return array('name' => 'Test other fields', 'description' => "Testing weight, title page, required" , 'group' => 'Profile Module');
|
836 | | }
|
837 | |
|
838 | | function _rolesApi($op, $edit) {
|
839 | | if ($op == 'delete') {
|
840 | | $id = $edit['rid'];
|
841 | | db_query('DELETE FROM {role} WHERE rid = %d', $id);
|
842 | | db_query('DELETE FROM {permission} WHERE rid = %d', $id);
|
843 | |
|
844 | | // Update the users who have this role set:
|
845 | | $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
|
846 | | $uid = array();
|
847 | |
|
848 | | while ($u = db_fetch_object($result)) {
|
849 | | $uid[] = $u->uid;
|
850 | | }
|
851 | |
|
852 | | if ($uid) {
|
853 | | db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
|
854 | | }
|
855 | |
|
856 | | // Users with only the deleted role are put back in the authenticated users pool.
|
857 | | db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
|
858 | |
|
859 | | }
|
860 | | else if ($op == 'add') {
|
861 | | if (isset($edit['name'])) {
|
862 | | db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
|
863 | | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
|
864 | | $rid = db_result($result);
|
865 | | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
|
866 | | return $rid;
|
867 | | }
|
868 | | else {
|
869 | | return 0;
|
870 | | }
|
871 | | }
|
872 | |
|
873 | | }
|
874 | |
|
875 | | function testProfileOtherFields() {
|
876 | | $this->drupalModuleEnable('profile');
|
877 | | // create test user
|
878 | | $edit['name'] = 'Profile '. $this->randomName(5);
|
879 | | $edit['perm'] = 'access content, administer users, access user profiles, administer site configuration, access administration pages, access configuration pages, access user profiles';
|
880 | | $rid = $this->_rolesApi('add', $edit );
|
881 | | $name = $this->randomName();
|
882 | | $pass = $this->randomName();
|
883 | | $mail = "$name@example.com";
|
884 | | unset($edit);
|
885 | | $edit['roles'] = array($rid => $rid);
|
886 | | $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
|
887 | | //log in
|
888 | | $edit = array('name' => $name, 'pass' => $pass);
|
889 | | $this->drupalPost('user', $edit, t('Log in'), 0);
|
890 | | //wartosci
|
891 | | $my_category = $this->randomName(10);
|
892 | | //single line textfield
|
893 | | $title = "first_" . $this->randomName(10);
|
894 | | $form_name = 'profile_' . $title;
|
895 | | // weight
|
896 | | $weight = 3;
|
897 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'weight' => $weight, 'required' => 1);
|
898 | | $this->drupalPost("admin/user/profile/add/textfield", $edit, t('Save field'), 0);
|
899 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
900 | | $sfield1 = array('fid'=> $fid, 'title' => $title);
|
901 | | //second one line textfield
|
902 | | $title = "second_" . $this->randomName(10);
|
903 | | $form_name = 'profile_' . $title;
|
904 | | // weight
|
905 | | $weight = -2;
|
906 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'weight' => $weight, 'register' => 1, 'required' => 1);
|
907 | | $this->drupalPost("admin/user/profile/add/textfield", $edit, t('Save field'), 0);
|
908 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
909 | | $sfield2 = array('fid'=> $fid, 'title' => $title);
|
910 | | // checking
|
911 | | $this->drupalGet("user/". $user->uid. "/edit/$my_category");
|
912 | | $content = $this->drupalGetContent();
|
913 | | $pos1 = strpos($content, $sfield1['title']);
|
914 | | $pos2 = strpos($content, $sfield2['title']);
|
915 | | $this->assertTrue($pos2 < $pos1, 'Checking weight field');
|
916 | | $delete_fields = array();
|
917 | | $delete_fields[] = $sfield1['fid'];
|
918 | | $delete_fields[] = $sfield2['fid'];
|
919 | | // check if this field is visible in registration form
|
920 | | // logout
|
921 | | $this->drupalGet("logout");
|
922 | | $this->drupalGet("user/register");
|
923 | | $this->assertNoText($sfield1['title'], 'Field is not visible in registration form');
|
924 | | $this->assertText($sfield2['title'], 'Field is visible in registration form');
|
925 | | // try to register
|
926 | | $fname = $this->randomName(5, 'simpletest_');
|
927 | | $fmail = "$fname@drupaltest.example.com";
|
928 | | $edit = array('name' => $fname,
|
929 | | 'mail' => $fmail);
|
930 | | $this->drupalPost('user/register', $edit, t('Create new account'), 0);
|
931 | | //$key = t('The field %field is required.', array('%field' => $title));
|
932 | | //$this->assertText($key, 'Checking error message');
|
933 | | //log in
|
934 | | $edit = array('name' => $name, 'pass' => $pass);
|
935 | | $this->drupalPost('user', $edit, t('Log in'), 0);
|
936 | | // TITLE
|
937 | | //selection
|
938 | | $title = $this->randomName(10);
|
939 | | $form_name = 'profile_' . $title;
|
940 | | $page_title = $this->randomName(5) . " %value";
|
941 | | $options = "";
|
942 | | for($i = 0; $i < 3; $i++)
|
943 | | $options .= $this->randomName(8) . "\n";
|
944 | | $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'page' => $page_title, 'options' => $options);
|
945 | | $this->drupalPost("admin/user/profile/add/selection", $edit, t('Save field'), 0);
|
946 | | $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
|
947 | | $element = rand(0,2);
|
948 | | $op_tab = explode("\n", $options,3);
|
949 | | $choice = rtrim($op_tab[$element]);
|
950 | | // checking
|
951 | | $this->drupalGet("profile/". $form_name. "/$choice");
|
952 | | $title = str_replace("%value", $choice, $page_title);
|
953 | |
|
954 | | $this->assertTitle($title. ' | '. variable_get('site_name', 'Drupal'), "Checking title $title");
|
955 | | $this->assertText($title, "Checking $title in content");
|
956 | | $delete_fields[] = $fid;
|
957 | |
|
958 | | foreach($delete_fields as $delfid) {
|
959 | | $this->drupalPost("admin/user/profile/delete/".$delfid, array(), t('Delete'), 0 );
|
960 | | }
|
961 | | // delete test user and roles
|
962 | | if ($user->uid > 0) {
|
963 | | db_query('DELETE FROM {users} WHERE uid =' .
|
964 | | ' %d', $user->uid);
|
965 | | db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
|
966 | | module_invoke_all('user', 'delete', '', $user);
|
967 | | }
|
968 | | //delete roles
|
969 | | $edit['rid'] = $rid;
|
970 | | $this->_rolesApi('delete', $edit);
|
971 | |
|
972 | | }
|
973 | | }
|
974 | |
|
975 | | ?>
|