1 field_example.test protected FieldExampleTest::createField($field_name, $widget_type, $cardinality)

Utility function to create fields on a content type.

Parameters

string $field_name: Name of the field, like field_something

string $widget_type: Widget type, like field_example_3text

int $cardinality: Cardinality

File

modules/examples/field_example/tests/field_example.test, line 142
Tests for Field Example.

Class

FieldExampleTest
Functional tests for the Field Example module.

Code

protected function createField($field_name, $widget_type, $cardinality) {
  // Add a singleton field_example_text field.
  $edit = array(
    'fields[_add_new_field][label]' => $field_name,
    'fields[_add_new_field][field_name]' => $field_name,
    'fields[_add_new_field][type]' => 'field_example_rgb',
    'fields[_add_new_field][widget_type]' => $widget_type,

  );
  $this->backdropPost(NULL, $edit, t('Save'));

  if ($cardinality == FIELD_CARDINALITY_UNLIMITED) {
    $edit = array(
      'field[cardinality]' => FIELD_CARDINALITY_UNLIMITED,
    );
  }
  else {
    $edit = array(
      'field[cardinality]' => 'number',
      'field[cardinality_number]' => (string) $cardinality,
    );
  }
  // There are no settings for this, so just press the button.
  $this->backdropPost(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)));
}