You are here

public function ConfigCreatorTest::testConfigCreate in GatherContent 8.5

Test config creation.

File

tests/src/Kernel/ConfigCreatorTest.php, line 42

Class

ConfigCreatorTest
Class ConfigCreatorTest.

Namespace

Drupal\Tests\gathercontent\Kernel

Code

public function testConfigCreate() {
  foreach (self::CONFIG_NAMES_CONFIG_CREATE_TEST as $templateId => $testFiles) {

    /** @var \Drupal\gathercontent\Entity\MappingInterface $mapping */
    $mapping = MockData::getSpecificMapping($templateId);
    $mappingData = unserialize($mapping
      ->getData());

    /** @var \Drupal\gathercontent\MigrationDefinitionCreator $creator */
    $creator = \Drupal::service('gathercontent.migration_creator');
    $creator
      ->setMapping($mapping)
      ->setMappingData($mappingData)
      ->createMigrationDefinition();
    $configFactory = \Drupal::configFactory();
    foreach ($testFiles as $configName => $testFile) {
      $configCreatedByService = $configFactory
        ->getEditable($configName);
      $testYml = file_get_contents(DRUPAL_ROOT . "/modules/custom/gathercontent/tests/modules/gathercontent_test/test_definition/{$templateId}/" . $testFile);
      if (!$testYml) {
        continue;
      }
      $parsedYml = Yaml::parse($testYml);
      $expected = Migration::create($parsedYml);
      foreach (self::CONFIG_KEYS_TO_CHECK as $key) {
        $actual = $configCreatedByService
          ->get($key);
        self::assertEquals($expected
          ->get($key), $actual, "Failed assertion template: {$templateId} in file: {$testFile} at key: {$key}");
      }
    }
  }
}