You are here

protected function FeedsJavascriptTestBase::assertMappings in Feeds 8.3

Asserts that the given feed type has the expected mappings.

Parameters

array $mappings: The expected mappings.

\Drupal\feeds\FeedTypeInterface $feed_type: The feed type to check.

2 calls to FeedsJavascriptTestBase::assertMappings()
FeedsJavascriptTestBase::addMappings in tests/src/FunctionalJavascript/FeedsJavascriptTestBase.php
Adds mappings to the given feed type via the UI.
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 252

Class

FeedsJavascriptTestBase
Base class for Feeds javascript tests.

Namespace

Drupal\Tests\feeds\FunctionalJavascript

Code

protected function assertMappings(array $mappings, FeedTypeInterface $feed_type) {

  // Get the saved mappings.
  $saved_mappings = $feed_type
    ->getMappings();
  foreach ($mappings as $i => $mapping) {

    // Assert target.
    $this
      ->assertEquals($mapping['target'], $saved_mappings[$i]['target']);

    // Assert map.
    foreach ($mapping['map'] as $key => $source) {
      if (is_array($source)) {
        $this
          ->assertEquals($source['machine_name'], $saved_mappings[$i]['map'][$key]);

        // Assert custom source.
        $custom_source = $feed_type
          ->getCustomSource($source['machine_name']);
        foreach ($source as $source_key => $source_value) {
          $this
            ->assertEquals($source_value, $custom_source[$source_key]);
        }
      }
      else {
        $this
          ->assertEquals($source, $saved_mappings[$i]['map'][$key]);
      }
    }

    // Assert unique.
    if (isset($mapping['unique'])) {
      $this
        ->assertEquals($mapping['unique'], $saved_mappings[$i]['unique']);
    }

    // Assert settings.
    if (!empty($mapping['settings'])) {
      foreach ($mapping['settings'] as $settings_key => $settings_value) {
        $this
          ->assertEquals($settings_value, $saved_mappings[$i]['settings'][$settings_key]);
      }
    }
  }
}