You are here

protected function GenericFieldTest::formCreateField in Examples for Developers 7

Create a field using the content type management form.

Parameters

mixed $manage_path: Path to our content type management form.

mixed $field_type: The type of field we're adding.

mixed $field_name: The name of the field instance we want.

mixed $widget_type: Which widget would we like?

mixed $cardinality: Cardinality for this field instance.

1 call to GenericFieldTest::formCreateField()
GenericFieldTest::formAddAllFields in field_permission_example/tests/field_permission_example.test
Add all fields using Form API.

File

field_permission_example/tests/field_permission_example.test, line 295
Tests for Field Permission Example.

Class

GenericFieldTest
A generic field testing class.

Code

protected function formCreateField($manage_path, $field_type, $field_name, $widget_type, $cardinality) {

  // $manage_path is the field edit form for our content type.
  $this
    ->drupalGet($manage_path);
  $edit = array(
    'fields[_add_new_field][label]' => $field_name,
    'fields[_add_new_field][field_name]' => $field_name,
    'fields[_add_new_field][type]' => $field_type,
    'fields[_add_new_field][widget_type]' => $widget_type,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Assume there are no settings for this,
  // so just press the button.
  $this
    ->drupalPost(NULL, array(), t('Save field settings'));
  $edit = array(
    'field[cardinality]' => (string) $cardinality,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));
  debug(t('Saved settings for field !field_name with widget !widget_type and cardinality !cardinality', array(
    '!field_name' => $field_name,
    '!widget_type' => $widget_type,
    '!cardinality' => $cardinality,
  )));
  $this
    ->assertText(t('Saved @name configuration.', array(
    '@name' => $field_name,
  )));
}