You are here

function ProfileModuleTestFreelist::testProfileSingle in SimpleTest 6

Same name and namespace in other branches
  1. 5 tests/profile_module.test \ProfileModuleTestFreelist::testProfileSingle()

File

tests/profile_module.test, line 276

Class

ProfileModuleTestFreelist

Code

function testProfileSingle() {
  $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
    ->drupalPost('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
    ->drupalPost("admin/user/profile/add/list", $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, '');

  // 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] = $this
    ->randomName(20);
  $this
    ->drupalPost("user/" . $user->uid . "/edit/{$my_category}", $edit, 'Save', 0);
  $this->_browser
    ->get(url("user/" . $user->uid));

  // checking profile page
  $this
    ->assertWantedText($edit[$form_name], "Checking " . $edit[$form_name]);
  $this
    ->assertWantedText($title, "Checking {$title}");

  // update field
  $new_title = $this
    ->randomName(20);
  $this
    ->drupalPost("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
    ->drupalPost("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);
}