You are here

protected function FeedsParaMapperTestBase::createField in Feeds Paragraphs 8

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 FeedsParaMapperTestBase::createField()
FeedsParaMapperTestBase::createBundle in tests/src/Functional/FeedsParaMapperTestBase.php
Creates a paragraph bundle.
FeedsParaMapperTestBase::createCT in tests/src/Functional/FeedsParaMapperTestBase.php
Utility function to create a content type.

File

tests/src/Functional/FeedsParaMapperTestBase.php, line 239

Class

FeedsParaMapperTestBase
Test basic functionality via BrowserTestBase. @todo: tests are failing because some dependencies modules use PrivateTempStore, see https://www.drupal.org/project/feeds/issues/3012342 @todo: for now we applied the patch in the issue, waiting for module…

Namespace

Drupal\Tests\feeds_para_mapper\Functional

Code

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

  // Add a singleton field_example_text field.
  $this
    ->drupalGet($form_path);
  $edit = array(
    'new_storage_type' => $type,
    'label' => $field_name,
    'field_name' => $field_name,
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save and continue'));
  $edit = array(
    'cardinality_number' => (string) $cardinality,
  );
  if ($cardinality === -1) {
    $edit = array(
      'cardinality' => "-1",
    );
  }
  $this
    ->drupalPostForm(NULL, $edit, t('Save field settings'));

  // There are no settings for this, so just press the button.
  $edit = array();
  if (isset($bundles) && count($bundles)) {
    foreach ($bundles as $bundle) {
      $edit['settings[handler_settings][target_bundles_drag_drop][' . $bundle . '][enabled]'] = '1';
    }
  }

  // Using all the default settings, so press the button.
  $this
    ->drupalPostForm(NULL, $edit, t('Save settings'));

  #$message = format_string("Field @field added successfully", array("@field" => $field_name));
  $this
    ->assertSession()
    ->pageTextContains(t('Saved @name configuration.', array(
    '@name' => $field_name,
  )));
}