ConfigCreatorTest.php in GatherContent 8.5
File
tests/src/Kernel/ConfigCreatorTest.php
View source
<?php
namespace Drupal\Tests\gathercontent\Kernel;
use Drupal\gathercontent_test\MockData;
use Drupal\migrate_plus\Entity\Migration;
use Symfony\Component\Yaml\Yaml;
class ConfigCreatorTest extends GcMigrateTestBase {
const CONFIG_NAMES_CONFIG_CREATE_TEST = [
'821317' => [
'migrate_plus.migration.86701_821317_node_article_en' => 'test1.1.yml',
'migrate_plus.migration.86701_821317_node_article_hu' => 'test1.2.yml',
],
'819462' => [
'migrate_plus.migration.86701_819462_node_simple_test_type_en' => 'test1.1.yml',
'migrate_plus.migration.86701_819462_node_simple_test_type_hu' => 'test1.2.yml',
],
];
const CONFIG_KEYS_TO_CHECK = [
'langcode',
'status',
'dependencies',
'id',
'label',
'source',
'process',
'destination',
'migration_dependencies',
];
public function testConfigCreate() {
foreach (self::CONFIG_NAMES_CONFIG_CREATE_TEST as $templateId => $testFiles) {
$mapping = MockData::getSpecificMapping($templateId);
$mappingData = unserialize($mapping
->getData());
$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}");
}
}
}
}
}