class ProfileModuleTest2 in SimpleTest 5
Same name and namespace in other branches
- 6 tests/profile_module.test \ProfileModuleTest2
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ProfileModuleTest2
Expanded class hierarchy of ProfileModuleTest2
File
- tests/
profile_module.test, line 850
View source
class ProfileModuleTest2 extends DrupalTestCase {
function get_info() {
return array(
'name' => 'Test other fields',
'desc' => "Testing weight, title page, required",
'group' => 'Profile Module',
);
}
function _rolesApi($op, $edit) {
if ($op == 'delete') {
$id = $edit['rid'];
db_query('DELETE FROM {role} WHERE rid = %d', $id);
db_query('DELETE FROM {permission} WHERE rid = %d', $id);
// Update the users who have this role set:
$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);
$uid = array();
while ($u = db_fetch_object($result)) {
$uid[] = $u->uid;
}
if ($uid) {
db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
}
// Users with only the deleted role are put back in the authenticated users pool.
db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
}
else {
if ($op == 'add') {
if (isset($edit['name'])) {
db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
$result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
$rid = db_result($result);
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
return $rid;
}
else {
return 0;
}
}
}
}
function testProfileOtherFields() {
$this
->drupalModuleEnable('profile');
// create test user
$edit['name'] = 'Profile ' . $this
->randomName(5);
$edit['perm'] = 'access content, administer users, access user profiles, administer site configuration, access administration pages, access configuration pages, access user profiles';
$rid = $this
->_rolesApi('add', $edit);
$name = $this
->randomName();
$pass = $this
->randomName();
$mail = "{$name}@example.com";
unset($edit);
$edit['roles'] = array(
$rid => $rid,
);
$user = user_save('', array(
'name' => $name,
'pass' => $pass,
'init' => $mail,
'mail' => $mail,
'roles' => $edit['roles'],
'status' => 1,
));
//log in
$edit = array(
'name' => $name,
'pass' => $pass,
);
$this
->drupalPostRequest('user', $edit, 'Log in', 0);
//wartosci
$my_category = $this
->randomName(10);
//single line textfield
$title = "first_" . $this
->randomName(10);
$form_name = 'profile_' . $title;
// weight
$weight = 3;
$edit = array(
'category' => $my_category,
'title' => $title,
'name' => $form_name,
'weight' => $weight,
'required' => 1,
);
$this
->drupalPostRequest("admin/user/profile/add/textfield", $edit, 'Save field', 0);
$fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
$sfield1 = array(
'fid' => $fid,
'title' => $title,
);
//second one line textfield
$title = "second_" . $this
->randomName(10);
$form_name = 'profile_' . $title;
// weight
$weight = -2;
$edit = array(
'category' => $my_category,
'title' => $title,
'name' => $form_name,
'weight' => $weight,
'register' => 1,
'required' => 1,
);
$this
->drupalPostRequest("admin/user/profile/add/textfield", $edit, 'Save field', 0);
$fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
$sfield2 = array(
'fid' => $fid,
'title' => $title,
);
// checking
$this->_browser
->get(url("user/" . $user->uid . "/edit/{$my_category}"));
$content = $this->_browser
->getContent();
$pos1 = strpos($content, $sfield1['title']);
$pos2 = strpos($content, $sfield2['title']);
$this
->assertTrue($pos2 < $pos1, 'Checking weight field');
$delete_fields = array();
$delete_fields[] = $sfield1['fid'];
$delete_fields[] = $sfield2['fid'];
// check if this field is visible in registration form
// logout
$this->_browser
->get(url("logout"));
$this->_browser
->get(url("user/register"));
$this
->assertNoUnwantedText($sfield1['title'], 'Field is not visible in registration form');
$this
->assertWantedText($sfield2['title'], 'Field is visible in registration form');
// try to register
$fname = $this
->randomName(5, 'simpletest_');
$fmail = "{$fname}@drupaltest.example.com";
$edit = array(
'name' => $fname,
'mail' => $fmail,
);
$this
->drupalPostRequest('user/register', $edit, 'Create new account', 0);
//$key = t('The field %field is required.', array('%field' => $title));
//$this->assertWantedText($key, 'Checking error message');
//log in
$edit = array(
'name' => $name,
'pass' => $pass,
);
$this
->drupalPostRequest('user', $edit, 'Log in', 0);
// TITLE
//selection
$title = $this
->randomName(10);
$form_name = 'profile_' . $title;
$page_title = $this
->randomName(5) . " %value";
$options = "";
for ($i = 0; $i < 3; $i++) {
$options .= $this
->randomName(8) . "\n";
}
$edit = array(
'category' => $my_category,
'title' => $title,
'name' => $form_name,
'page' => $page_title,
'options' => $options,
);
$this
->drupalPostRequest("admin/user/profile/add/selection", $edit, 'Save field', 0);
$fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
$element = rand(0, 2);
$op_tab = explode("\n", $options, 3);
$choice = rtrim($op_tab[$element]);
// checking
$this->_browser
->get(url("profile/" . $form_name . "/{$choice}"));
$title = str_replace("%value", $choice, $page_title);
$this
->assertTitle($title . ' | ' . variable_get('site_name', 'Drupal'), "Checking title {$title}");
$this
->assertWantedText($title, "Checking {$title} in content");
$delete_fields[] = $fid;
foreach ($delete_fields as $delfid) {
$this
->drupalPostRequest("admin/user/profile/delete/" . $delfid, array(), 'Delete', 0);
}
// delete test user and roles
if ($user->uid > 0) {
db_query('DELETE FROM {users} WHERE uid =' . ' %d', $user->uid);
db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
module_invoke_all('user', 'delete', '', $user);
}
//delete roles
$edit['rid'] = $rid;
$this
->_rolesApi('delete', $edit);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
DrupalTestCase:: |
function | tearDown implementation, setting back switched modules etc | 1 | |
ProfileModuleTest2:: |
function | |||
ProfileModuleTest2:: |
function | |||
ProfileModuleTest2:: |
function |