You are here

function TokenProfileTestCase::addProfileField in Token 7

Add a profile field.

Parameters

$type: The profile field type.

$field: (optional) An array of the profile field properties.

Return value

The saved profile field record object.

See also

drupal_form_submit()

1 call to TokenProfileTestCase::addProfileField()
TokenProfileTestCase::testProfileTokens in ./token.test
Test the profile tokens.

File

./token.test, line 834
Test integration for the token module.

Class

TokenProfileTestCase
Test the profile tokens.

Code

function addProfileField($type, array $field = array()) {
  $field += array(
    'type' => $type,
    'category' => 'SimpleTest',
    'title' => $this
      ->randomName(8),
    'name' => 'profile_' . $type,
    'explanation' => $this
      ->randomName(50),
    'autocomplete' => 0,
    'required' => 0,
    'register' => 0,
  );
  drupal_write_record('profile_field', $field);

  // Verify the profile field was created successfully.
  $saved_field = db_query("SELECT * FROM {profile_field} WHERE type = :type AND name = :name", array(
    ':type' => $type,
    ':name' => $field['name'],
  ))
    ->fetchObject();
  if (empty($saved_field)) {
    $this
      ->fail(t('Failed to create profile field @name.', array(
      '@name' => $saved_field->name,
    )));
  }
  return $saved_field;
}