ProfileTestCase::setProfileField

7 profile.test ProfileTestCase::setProfileField($field, $value = NULL)

Set the profile field to a random value

Parameters

$field: The field that should be set.

$value: The value for the field, defaults to a random string.

Return value

The value that has been assigned to

File

modules/profile/profile.test, line 131
Tests for profile.module.

Code

function setProfileField($field, $value = NULL) {

  if (!isset($value)) {
    $value = $this->randomName();
  }

  $edit = array(
    $field['form_name'] => $value,
  );
  $this->drupalPost('user/' . $this->normal_user->uid . '/edit/' . $field['category'], $edit, t('Save'));

  // Check profile page.
  $content = $this->drupalGet('user/' . $this->normal_user->uid);
  $this->assertText($field['title'], t('Found profile field with title %title', array('%title' => $field['title'])));

  if ($field['type'] != 'checkbox') {
    // $value must be cast to a string in order to be found by assertText.
    $this->assertText("$value", t('Found profile field with value %value', array('%value' => $value)));
  }

  return $value;
}
Login or register to post comments