dcd596ecf39b72e83668880568f4718d19d44ca3
[yaffs-website] / web / core / modules / content_translation / tests / src / Kernel / ContentTranslationEntityBundleInfoTest.php
1 <?php
2
3 namespace Drupal\Tests\content_translation\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\entity_test\Entity\EntityTestMul;
7 use Drupal\language\Entity\ConfigurableLanguage;
8
9 /**
10  * Tests the Content Translation bundle info logic.
11  *
12  * @group content_translation
13  */
14 class ContentTranslationEntityBundleInfoTest extends KernelTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['user', 'language', 'content_translation_test', 'content_translation', 'entity_test'];
20
21   /**
22    * The content translation manager.
23    *
24    * @var \Drupal\content_translation\ContentTranslationManagerInterface
25    */
26   protected $contentTranslationManager;
27
28   /**
29    * The bundle info service.
30    *
31    * @var \Drupal\Core\Entity\EntityTypeBundleInfo
32    */
33   protected $bundleInfo;
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function setUp() {
39     parent::setUp();
40
41     $this->contentTranslationManager = $this->container->get('content_translation.manager');
42     $this->bundleInfo = $this->container->get('entity_type.bundle.info');
43
44     $this->installEntitySchema('entity_test_mul');
45
46     ConfigurableLanguage::createFromLangcode('it')->save();
47   }
48
49   /**
50    * Tests that modules can know whether bundles are translatable.
51    */
52   public function testHookInvocationOrder() {
53     $this->contentTranslationManager->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
54     $this->bundleInfo->clearCachedBundles();
55     $this->bundleInfo->getAllBundleInfo();
56
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();
62     $expected_modules = [
63       'content_translation_test',
64       'content_translation',
65     ];
66     $actual_modules = array_keys(array_intersect_key($module_list, array_flip($expected_modules)));
67     $this->assertEquals($expected_modules, $actual_modules);
68
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'));
74   }
75
76   /**
77    * Tests that field synchronization is skipped for disabled bundles.
78    */
79   public function testFieldSynchronizationWithDisabledBundle() {
80     $entity = EntityTestMul::create();
81     $entity->save();
82
83     /** @var \Drupal\Core\Entity\ContentEntityInterface $translation */
84     $translation = $entity->addTranslation('it');
85     $translation->save();
86
87     $this->assertTrue($entity->isTranslatable());
88   }
89
90 }