You are here

public function FeedsWebTestBase::addMappings in Feeds 8.2

Adds mappings to a given configuration.

Parameters

string $id: ID of the importer.

array $mappings: An array of mapping arrays. Each mapping array must have a source and an target key and can have a unique key.

bool $test_mappings: (optional) TRUE to automatically test mapping configs. Defaults to TRUE.

21 calls to FeedsWebTestBase::addMappings()
FeedsCSVtoUsersTest::test in lib/Drupal/feeds/Tests/FeedsCSVtoUsersTest.php
Test node creation, refreshing/deleting feeds and feed items.
FeedsFileFetcherTest::testPrivateFiles in lib/Drupal/feeds/Tests/FeedsFileFetcherTest.php
Test uploading private files.
FeedsFileFetcherTest::testPublicFiles in lib/Drupal/feeds/Tests/FeedsFileFetcherTest.php
Test scheduling on cron.
FeedsMapperConfigTest::test in lib/Drupal/feeds/Tests/FeedsMapperConfigTest.php
Basic test of mapping configuration.
FeedsMapperDateMultipleTest::test in lib/Drupal/feeds/Tests/FeedsMapperDateMultipleTest.php
Testing import by loading a 4 item XML file.

... See full list

File

lib/Drupal/feeds/Tests/FeedsWebTestBase.php, line 396
Common functionality for all Feeds tests.

Class

FeedsWebTestBase
Test basic Data API functionality.

Namespace

Drupal\feeds\Tests

Code

public function addMappings($id, $mappings, $test_mappings = TRUE) {
  $path = "admin/structure/feeds/{$id}/mapping";

  // Iterate through all mappings and add the mapping via the form.
  foreach ($mappings as $i => $mapping) {
    if ($test_mappings) {
      $current_mapping_key = $this
        ->mappingExists($id, $i, $mapping['source'], $mapping['target']);
      $this
        ->assertEqual($current_mapping_key, -1, 'Mapping does not exist before addition.');
    }

    // Get unique flag and unset it. Otherwise, drupalPost will complain that
    // Split up config and mapping.
    $config = $mapping;
    unset($config['source'], $config['target']);
    $mapping = array(
      'source' => $mapping['source'],
      'target' => $mapping['target'],
    );

    // Add mapping.
    $this
      ->drupalPost($path, $mapping, t('Save'));

    // If there are other configuration options, set them.
    if ($config) {
      $this
        ->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_' . $i);

      // Set some settings.
      $edit = array();
      foreach ($config as $key => $value) {
        $edit["config[{$i}][settings][{$key}]"] = $value;
      }
      $this
        ->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_' . $i);
      $this
        ->drupalPost(NULL, array(), t('Save'));
    }
    if ($test_mappings) {
      $current_mapping_key = $this
        ->mappingExists($id, $i, $mapping['source'], $mapping['target']);
      $this
        ->assertTrue($current_mapping_key >= 0, 'Mapping exists after addition.');
    }
  }
}