View source
<?php
namespace Drupal\lingotek\Tests\Kernel;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\KernelTests\KernelTestBase;
class LingotekConfigImportTest extends KernelTestBase {
protected $configImporter;
public static $modules = [
'config_test',
'system',
'user',
'entity_test',
'language',
'locale',
'content_translation',
'config_translation',
'lingotek',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
]);
$this
->installEntitySchema('entity_test_mul');
}
public function testConfigImportUpdates() {
$content_entity = EntityTestMul::create([]);
$content_entity
->save();
$storage = $this->container
->get('entity_type.manager')
->getStorage('config_test');
$entity1 = $storage
->create([
'id' => 'entity1',
'dependencies' => [
'enforced' => [
'content' => [
$content_entity
->getConfigDependencyName(),
],
],
],
]);
$entity1
->save();
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
$entity_type_id = 'entity_test_mul';
$config_name = 'lingotek.settings';
$config_id = $entity_type_id . '.' . $entity_type_id;
$storage = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
\Drupal::service('content_translation.manager')
->setEnabled($entity_type_id, $entity_type_id, TRUE);
$this
->assertIdentical($storage
->exists($config_name), FALSE, $config_name . ' not found.');
$data = [
'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
'langcode' => 'en',
'status' => TRUE,
'dependencies' => [
'module' => [
'content_translation',
],
],
'id' => $config_id,
'target_entity_type_id' => 'entity_test_mul',
'target_bundle' => 'entity_test_mul',
'default_langcode' => 'site_default',
'language_alterable' => FALSE,
'third_party_settings' => [
'content_translation' => [
'enabled' => TRUE,
],
],
];
$sync
->write('language.content_settings.' . $config_id, $data);
$data = [
'translate' => [
'entity' => [
$entity_type_id => [
$entity_type_id => [
'enabled' => TRUE,
'field' => [
'name' => TRUE,
'field_test_text' => TRUE,
],
'profile' => 'automatic',
],
],
],
],
];
$sync
->write($config_name, $data);
$this
->assertIdentical($sync
->exists($config_name), TRUE, $config_name . ' found.');
$this
->configImporter()
->import();
$config = $this
->config($config_name);
$this
->assertIdentical($config
->get('translate.entity.entity_test_mul.entity_test_mul.field.field_test_text'), TRUE);
$lingotek_config = \Drupal::service('lingotek.configuration');
$this
->assertIdentical($lingotek_config
->isEnabled($entity_type_id), TRUE);
}
}