25be0def2411cea61a9d5d53b48213c92860c277
[yaffs-website] / web / core / modules / content_translation / tests / src / Functional / Update / ContentTranslationUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\content_translation\Functional\Update;
4
5 use Drupal\Core\Language\LanguageInterface;
6 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
7 use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
8
9 /**
10  * Tests the upgrade path for the Content Translation module.
11  *
12  * @group Update
13  */
14 class ContentTranslationUpdateTest extends UpdatePathTestBase {
15
16   use EntityDefinitionTestTrait;
17
18   /**
19    * The database connection used.
20    *
21    * @var \Drupal\Core\Database\Connection
22    */
23   protected $database;
24
25   /**
26    * The entity definition update manager.
27    *
28    * @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
29    */
30   protected $entityDefinitionUpdateManager;
31
32   /**
33    * The entity manager service.
34    *
35    * @var \Drupal\Core\Entity\EntityManagerInterface
36    */
37   protected $entityManager;
38
39   /**
40    * The state service.
41    *
42    * @var \Drupal\Core\State\StateInterface
43    */
44   protected $state;
45
46   /**
47    * {@inheritdoc}
48    */
49   protected function setUp() {
50     parent::setUp();
51
52     $this->database = \Drupal::database();
53     $this->entityDefinitionUpdateManager = \Drupal::entityDefinitionUpdateManager();
54     $this->entityManager = \Drupal::entityManager();
55     $this->state = \Drupal::state();
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function setDatabaseDumpFiles() {
62     $this->databaseDumpFiles = [
63       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.0.0-rc1-filled.standard.entity_test_update_mul.php.gz',
64     ];
65   }
66
67   /**
68    * Tests that initial values for metadata fields are populated correctly.
69    */
70   public function testContentTranslationUpdate8400() {
71     $this->updateEntityTypeToTranslatable();
72
73     // The test database dump contains NULL values for
74     // 'content_translation_source', 'content_translation_outdated' and
75     // 'content_translation_status' for the first 50 test entities.
76     // @see _entity_test_update_create_test_entities()
77     $first_entity_record = $this->database->select('entity_test_update_data', 'etud')
78       ->fields('etud')
79       ->condition('etud.id', 1)
80       ->execute()
81       ->fetchAllAssoc('id');
82     $this->assertNull($first_entity_record[1]->content_translation_source);
83     $this->assertNull($first_entity_record[1]->content_translation_outdated);
84     $this->assertNull($first_entity_record[1]->content_translation_status);
85
86     $this->runUpdates();
87
88     // After running the updates, all those fields should be populated with
89     // their default values.
90     $first_entity_record = $this->database->select('entity_test_update_data', 'etud')
91       ->fields('etud')
92       ->condition('etud.id', 1)
93       ->execute()
94       ->fetchAllAssoc('id');
95     $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $first_entity_record[1]->content_translation_source);
96     $this->assertEqual(0, $first_entity_record[1]->content_translation_outdated);
97     $this->assertEqual(1, $first_entity_record[1]->content_translation_status);
98   }
99
100 }