You are here

function ProfileModuleTestCheckbox::testProfileCheckbox in SimpleTest 5

Same name and namespace in other branches
  1. 6 tests/profile_module.test \ProfileModuleTestCheckbox::testProfileCheckbox()

File

tests/profile_module.test, line 401

Class

ProfileModuleTestCheckbox

Code

function testProfileCheckbox() {
  $this
    ->drupalModuleEnable('profile');

  // create test user
  $edit['name'] = 'Profile ' . $this
    ->randomName(5);
  $edit['perm'] = 'access content, administer users, 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 = 'Simpletest';

  //single line textfield
  $title = "single_" . $this
    ->randomName(10);
  $form_name = 'profile_' . $title;
  $explanation = $this
    ->randomName(50);
  $edit = array(
    'category' => $my_category,
    'title' => $title,
    'name' => $form_name,
    'explanation' => $explanation,
  );
  $this
    ->drupalPostRequest("admin/user/profile/add/checkbox", $edit, 'Save field', 0);
  $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
  $single_field = array(
    'title' => $title,
    'form_name' => $form_name,
    'explanation' => $explanation,
  );

  // checking simple fields
  $this->_browser
    ->get(url("user/" . $user->uid . "/edit/{$my_category}"));

  // checking field
  $this
    ->assertField($form_name, false);

  // checking name
  $this
    ->assertWantedText($title, "Checking title for " . $title);

  // checking explanation
  $this
    ->assertWantedText($explanation, "Checking explanation for " . $title);

  // ok, now let put some data
  unset($edit);
  $edit = array();
  $checking = array();
  $edit[$form_name] = 1;
  $this
    ->drupalPostRequest("user/" . $user->uid . "/edit/{$my_category}", $edit, 'Submit', 0);
  $this->_browser
    ->get(url("user/" . $user->uid));

  // checking profile page
  $this
    ->assertWantedText($title, "Checking checkbox");
  $this
    ->assertWantedText($title, "Checking {$title}");

  // update field
  $new_title = $this
    ->randomName(10);
  $this
    ->drupalPostRequest("admin/user/profile/edit/{$fid}", array(
    'title' => $new_title,
  ), 'Save field', 0);
  $this->_browser
    ->get(url("admin/user/profile"));
  $this
    ->assertWantedText($new_title, "Checking updated field");

  // deleting field
  $this
    ->drupalPostRequest("admin/user/profile/delete/{$fid}", array(), 'Delete', 0);
  $this->_browser
    ->get(url("admin/user/profile"));
  $this
    ->assertNoUnwantedText($new_title, "Checking deleted field {$title}");

  // 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);
}