3 namespace Drupal\Tests\content_translation\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\entity_test\Entity\EntityTestMul;
7 use Drupal\language\Entity\ConfigurableLanguage;
10 * Tests the Content Translation bundle info logic.
12 * @group content_translation
14 class ContentTranslationEntityBundleInfoTest extends KernelTestBase {
19 public static $modules = ['user', 'language', 'content_translation_test', 'content_translation', 'entity_test'];
22 * The content translation manager.
24 * @var \Drupal\content_translation\ContentTranslationManagerInterface
26 protected $contentTranslationManager;
29 * The bundle info service.
31 * @var \Drupal\Core\Entity\EntityTypeBundleInfo
33 protected $bundleInfo;
38 protected function setUp() {
41 $this->contentTranslationManager = $this->container->get('content_translation.manager');
42 $this->bundleInfo = $this->container->get('entity_type.bundle.info');
44 $this->installEntitySchema('entity_test_mul');
46 ConfigurableLanguage::createFromLangcode('it')->save();
50 * Tests that modules can know whether bundles are translatable.
52 public function testHookInvocationOrder() {
53 $this->contentTranslationManager->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
54 $this->bundleInfo->clearCachedBundles();
55 $this->bundleInfo->getAllBundleInfo();
57 // Verify that the test module comes first in the module list, which would
58 // normally make its hook implementation to be invoked first.
59 /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
60 $module_handler = $this->container->get('module_handler');
61 $module_list = $module_handler->getModuleList();
63 'content_translation_test',
64 'content_translation',
66 $actual_modules = array_keys(array_intersect_key($module_list, array_flip($expected_modules)));
67 $this->assertEquals($expected_modules, $actual_modules);
69 // Check that the "content_translation_test" hook implementation has access
70 // to the "translatable" bundle info property.
71 /** @var \Drupal\Core\State\StateInterface $state */
72 $state = $this->container->get('state');
73 $this->assertTrue($state->get('content_translation_test.translatable'));
77 * Tests that field synchronization is skipped for disabled bundles.
79 public function testFieldSynchronizationWithDisabledBundle() {
80 $entity = EntityTestMul::create();
83 /** @var \Drupal\Core\Entity\ContentEntityInterface $translation */
84 $translation = $entity->addTranslation('it');
87 $this->assertTrue($entity->isTranslatable());