You are here

protected function FeedsParaMapperWebTestCase::createField in Feeds Paragraphs 7

Utility function to create fields on a content type/paragraph bundle.

Parameters

string $field_name: Name of the field, like field_something.

int $cardinality: Cardinality.

string $type: Field type.

string $widget: Field widget.

array $bundles: The allowed bundles if it's a paragraph field.

2 calls to FeedsParaMapperWebTestCase::createField()
FeedsParaMapperWebTestCase::createBundle in tests/FeedsParaMapperWebTestCase.test
Creates a paragraph bundle.
FeedsParaMapperWebTestCase::createContentType in tests/FeedsParaMapperWebTestCase.test
Utility function to create a content type.

File

tests/FeedsParaMapperWebTestCase.test, line 233
Common functionality for all Paragraphs Mapper tests.

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

protected function createField($field_name, $cardinality, $type, $widget, array $bundles = array()) {

  // 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]' => $type,
    'fields[_add_new_field][widget_type]' => $widget,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // 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,
  );
  if (isset($bundles) && count($bundles)) {
    foreach ($bundles as $bundle) {
      $edit['instance[settings][allowed_bundles_table][' . $bundle . '][enabled]'] = "1";
    }
  }

  // Using all the default settings, so press the button.
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));
  $message = format_string("Field @field added successfully", array(
    "@field" => $field_name,
  ));
  $this
    ->assertText(t('Saved @name configuration.', array(
    '@name' => $field_name,
  )), $message, "Setup");
}