You are here

protected function FeedsParaMapperWebTestCase::map in Feeds Paragraphs 7

Maps source fields to target fields.

Parameters

array $targets: Contains the source and the target string names.

2 calls to FeedsParaMapperWebTestCase::map()
FeedsParaMapperMultiValuedMappingTestCase::testSettingsAvailable in tests/mapping.test
Test the user can see paragraphs fields in fields mapping.
FeedsParaMapperWebTestCase::import in tests/FeedsParaMapperWebTestCase.test
Starts importing.

File

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

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

protected function map(array $targets) {
  $this
    ->drupalGet('admin/structure/feeds/' . $this->importer . '/mapping');
  $targets = array_unique($targets);
  $targets['id'] = "nid";
  $config_key = 0;
  $hasSettings = $this->multiValued && $this->multiValuedParagraph;
  foreach ($targets as $source => $target) {
    $edit = array(
      'source' => $source,
      'target' => $target,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $this
      ->assertText(t("Your changes have been saved."));
    $args = array(
      '@source' => $source,
      '@target' => $target,
    );
    $message = format_string("Mapped @source source to @target field", $args);
    $this
      ->assertText(t("Mapping has been added."), $message, 'Mapping');
    if ($target === 'nid') {

      // Set the target as unique:
      $edit = array(
        "config[{$config_key}][settings][unique]" => "1",
      );
    }
    elseif ($hasSettings) {
      $edit = array(
        "config[{$config_key}][settings][max_values]" => "2",
      );
    }
    if ($target === 'nid' || $hasSettings) {

      // Click the gear button so it shows the configuration form:
      $button_name = "mapping_settings_edit_" . $config_key;
      $this
        ->drupalPostAJAX(NULL, array(), $button_name);

      // Click update button.
      $button_name = "mapping_settings_update_" . $config_key;
      $this
        ->drupalPostAJAX(NULL, $edit, $button_name);

      // Save.
      $this
        ->drupalPost(NULL, array(), t('Save'));
    }
    $config_key++;
  }
}