You are here

protected function FeedsJavascriptTestBase::mappingSetMappings in Feeds 8.3

Sets the form values on the mappings page.

Parameters

array $edit: The form values.

3 calls to FeedsJavascriptTestBase::mappingSetMappings()
FeedsJavascriptTestBase::addMappings in tests/src/FunctionalJavascript/FeedsJavascriptTestBase.php
Adds mappings to the given feed type via the UI.
MappingFormTest::testCustomSourceUniqueForUnsavedMappings in tests/src/FunctionalJavascript/Form/MappingFormTest.php
Tests that custom source names are unique for unsaved mappings.
MappingFormTest::testSetMultipleMappingsWithCustomSources in tests/src/FunctionalJavascript/Form/MappingFormTest.php
Tests that multiple new CSV sources can be defined without errors.

File

tests/src/FunctionalJavascript/FeedsJavascriptTestBase.php, line 186

Class

FeedsJavascriptTestBase
Base class for Feeds javascript tests.

Namespace

Drupal\Tests\feeds\FunctionalJavascript

Code

protected function mappingSetMappings(array $edit) {

  // Set the form values, including machine name.
  $assert_session = $this
    ->assertSession();
  $submit_button = $assert_session
    ->buttonExists('Save');
  $form = $assert_session
    ->elementExists('xpath', './ancestor::form', $submit_button);
  foreach ($edit as $name => $value) {
    if (strpos($name, '[__new][machine_name]') !== FALSE) {

      // Make machine name appear.
      $i = preg_replace('/^mappings\\[([0-9]+)\\].+$/', '${1}', $name);
      $key = preg_replace('/^.+\\[map\\]\\[([^\\]]+)\\].+$/', '${1}', $name);
      $key = Html::cleanCssIdentifier($key);
      $base_xpath = 'descendant-or-self::div[@data-drupal-selector=\'edit-mappings-' . $i . '-map-' . $key . '-new\']';

      // First, wait for machine name button to become visible.
      $xpath = $base_xpath . '/descendant-or-self::*/button';
      $assert_session
        ->waitForElementVisible('xpath', $xpath);

      // Click button.
      $this
        ->getSession()
        ->getDriver()
        ->click($xpath);

      // Wait for machine name text field to become visible.
      $xpath = $base_xpath . '/' . $this
        ->cssSelectToXpath('div.form-type-machine-name input.machine-name-target');
      $assert_session
        ->waitForElementVisible('xpath', $xpath);
    }
    $field = $assert_session
      ->fieldExists($name, $form);
    $field
      ->setValue($value);
  }
}