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