Create a profile field.

Parameters

$type: The field type to be created.

$category: The category in which the field should be created.

$edit: Additional parameters to be submitted.

Return value

The fid of the field that was just created.

7 calls to ProfileTestCase::createProfileField()
ProfileBlockTestCase::setUp in modules/profile/profile.test
Sets up a Drupal site for running functional and integration tests.
ProfileTestAutocomplete::testAutocomplete in modules/profile/profile.test
Tests profile field autocompletion and access.
ProfileTestBrowsing::testProfileBrowsing in modules/profile/profile.test
Test profile browsing.
ProfileTestDate::testProfileDateField in modules/profile/profile.test
Create a date field, give it a value, update and delete the field.
ProfileTestFields::testProfileFields in modules/profile/profile.test
Test each of the field types. List selection and date fields are tested separately because they need some special handling.

... See full list

File

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

Class

ProfileTestCase
A class for common methods for testing profile fields.

Code

function createProfileField($type = 'textfield', $category = 'simpletest', $edit = array()) {
  $edit['title'] = $title = $this
    ->randomName(8);
  $edit['name'] = $form_name = 'profile_' . $title;
  $edit['category'] = $category;
  $edit['explanation'] = $this
    ->randomName(50);
  $this
    ->drupalPost('admin/config/people/profile/add/' . $type, $edit, t('Save field'));
  $fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(
    ':title' => $title,
  ))
    ->fetchField();
  $this
    ->assertTrue($fid, 'New Profile field has been entered in the database');

  // Check that the new field is appearing on the user edit form.
  $this
    ->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category);

  // Checking field.
  if ($type == 'date') {
    $this
      ->assertField($form_name . '[month]', 'Found month selection field');
    $this
      ->assertField($form_name . '[day]', 'Found day selection field');
    $this
      ->assertField($form_name . '[year]', 'Found day selection field');
  }
  else {
    $this
      ->assertField($form_name, format_string('Found form named @name', array(
      '@name' => $form_name,
    )));
  }

  // Checking name.
  $this
    ->assertText($title, format_string('Checking title for field %title', array(
    '%title' => $title,
  )));

  // Checking explanation.
  $this
    ->assertText($edit['explanation'], format_string('Checking explanation for field %title', array(
    '%title' => $title,
  )));
  return array(
    'fid' => $fid,
    'type' => $type,
    'form_name' => $form_name,
    'title' => $title,
    'category' => $category,
  );
}