You are here

function ProfileModuleTestDate::testProfileSingle in SimpleTest 6

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

File

tests/profile_module.test, line 743

Class

ProfileModuleTestDate

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

  /*   $options = "";
      for($i = 0; $i < 3; $i++)
        $options .= $this->randomName(8) . "\n";*/
  $edit = array(
    'category' => $my_category,
    'title' => $title,
    'name' => $form_name,
    'explanation' => $explanation,
  );
  $this
    ->drupalPost("admin/user/profile/add/date", $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 name
  $this
    ->assertWantedText($title, "Checking title for " . $title);

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

  // checking days/month/years
  foreach (array(
    'year',
    'month',
    'day',
  ) as $field) {
    $this
      ->assertFalse($this
      ->setField('edit[' . $form_name . '][' . $field . ']', $this
      ->randomName(4)), 'Checking data field [' . $field . ']');
  }

  // ok, now let put some data
  // date 9-01-1983
  unset($edit);
  foreach (array(
    'year' => 1983,
    'month' => 'Jan',
    'day' => 9,
  ) as $field => $v) {
    $key = $form_name . '[' . $field . ']';
    $edit[$key] = $v;
  }
  list($format) = explode(' - ', variable_get('date_format_short', 'm/d/Y'), 2);
  $replace = array(
    'd' => sprintf('%02d', 9),
    'j' => 9,
    'm' => sprintf('%02d', '1'),
    'M' => map_month(1),
    'Y' => 1983,
  );
  $data = strtr($format, $replace);
  $this
    ->drupalPost("user/" . $user->uid . "/edit/{$my_category}", $edit, 'Save', 0);
  $this->_browser
    ->get(url("user/" . $user->uid));

  // checking profile page
  $this
    ->assertWantedText($data, "Checking date {$data}");
  $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);
}