You are here

public function FeedsWebTestCase::addMappings in Feeds 7.2

Same name and namespace in other branches
  1. 6 tests/feeds.test \FeedsWebTestCase::addMappings()
  2. 7 tests/feeds.test.inc \FeedsWebTestCase::addMappings()

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.

111 calls to FeedsWebTestCase::addMappings()
FeedsAccountSwitcherTest::setUp in tests/FeedsAccountSwitcherTest.test
Sets up a Drupal site for running functional and integration tests.
FeedsAccountSwitcherTest::testAuthorizedImport in tests/FeedsAccountSwitcherTest.test
Tests if an extra account switch happens on authorized imports.
FeedsAccountSwitcherTest::testRunImportAsFeedNodeAuthorInUI in tests/FeedsAccountSwitcherTest.test
Tests if the import is ran as the feed node author when using the UI.
FeedsAccountSwitcherTest::testRunImportAsFeedNodeAuthorOnCron in tests/FeedsAccountSwitcherTest.test
Tests if the import is ran as the feed node author when using cron.
FeedsContentTypeTest::setUp in tests/feeds_content_type.test
Sets up a Drupal site for running functional and integration tests.

... See full list

File

tests/feeds.test, line 523
Common functionality for all Feeds tests.

Class

FeedsWebTestCase
Test basic Data API functionality.

Code

public function addMappings($id, array $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) {
        if (is_array($value)) {
          foreach ($value as $subkey => $subvalue) {
            $edit["config[{$i}][settings][{$key}][{$subkey}]"] = $subvalue;
          }
        }
        else {
          $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.');
    }
  }
}