ContentTranslationEntityBundleInfoTest.php in Drupal 10
File
core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php
View source
<?php
namespace Drupal\Tests\content_translation\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
class ContentTranslationEntityBundleInfoTest extends KernelTestBase {
protected static $modules = [
'system',
'node',
'user',
'language',
'content_translation_test',
'content_translation',
'entity_test',
];
protected $contentTranslationManager;
protected $bundleInfo;
protected function setUp() : void {
parent::setUp();
$this->contentTranslationManager = $this->container
->get('content_translation.manager');
$this->bundleInfo = $this->container
->get('entity_type.bundle.info');
$this
->installEntitySchema('entity_test_mul');
ConfigurableLanguage::createFromLangcode('it')
->save();
}
public function testHookInvocationOrder() {
$this->contentTranslationManager
->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
$this->bundleInfo
->clearCachedBundles();
$this->bundleInfo
->getAllBundleInfo();
$module_handler = $this->container
->get('module_handler');
$module_list = $module_handler
->getModuleList();
$expected_modules = [
'content_translation_test',
'content_translation',
];
$actual_modules = array_keys(array_intersect_key($module_list, array_flip($expected_modules)));
$this
->assertEquals($expected_modules, $actual_modules);
$state = $this->container
->get('state');
$this
->assertTrue($state
->get('content_translation_test.translatable'));
}
public function testFieldSynchronizationWithDisabledBundle() {
$entity = EntityTestMul::create();
$entity
->save();
$translation = $entity
->addTranslation('it');
$translation
->save();
$this
->assertTrue($entity
->isTranslatable());
}
public function testBundleClearOnLanguageContentSettingInsert() {
$node = $this
->getBundledNode();
$this
->assertFalse($node
->isTranslatable());
$this->contentTranslationManager
->setEnabled('node', 'bundle_test', TRUE);
$this
->assertTrue($node
->isTranslatable(), "Bundle info was not cleared on language_content_settings creation.");
}
public function testBundleClearOnLanguageContentSettingUpdate() {
$node = $this
->getBundledNode();
$this
->assertFalse($node
->isTranslatable());
$this->container
->get('entity_type.manager')
->getStorage('language_content_settings')
->create([
'target_entity_type_id' => 'node',
'target_bundle' => 'bundle_test',
])
->save();
$this
->assertFalse($node
->isTranslatable());
$this->contentTranslationManager
->setEnabled('node', 'bundle_test', TRUE);
$this
->assertTrue($node
->isTranslatable(), "Bundle info was not cleared on language_content_settings update.");
}
protected function getBundledNode() {
$this
->installEntitySchema('node');
$bundle = NodeType::create([
'type' => 'bundle_test',
'label' => 'Bundle Test',
]);
$bundle
->save();
$node = Node::create([
'type' => 'bundle_test',
]);
return $node;
}
}