Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\locale\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@0
|
6 use Drupal\Tests\BrowserTestBase;
|
Chris@18
|
7 use Drupal\Tests\RequirementsPageTrait;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Adds and configures languages to check field schema definition.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group locale
|
Chris@0
|
13 */
|
Chris@0
|
14 class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
|
Chris@0
|
15
|
Chris@18
|
16 use RequirementsPageTrait;
|
Chris@18
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Modules to enable.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @var array
|
Chris@0
|
22 */
|
Chris@0
|
23 public static $modules = ['language', 'locale', 'node'];
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * {@inheritdoc}
|
Chris@0
|
27 */
|
Chris@0
|
28 protected function setUp() {
|
Chris@0
|
29 parent::setUp();
|
Chris@0
|
30 ConfigurableLanguage::createFromLangcode('fr')->save();
|
Chris@0
|
31 $this->config('system.site')->set('default_langcode', 'fr')->save();
|
Chris@18
|
32
|
Chris@0
|
33 // Clear all caches so that the base field definition, its cache in the
|
Chris@0
|
34 // entity manager, the t() cache, etc. are all cleared.
|
Chris@0
|
35 drupal_flush_all_caches();
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 /**
|
Chris@0
|
39 * Tests that translated field descriptions do not affect the update system.
|
Chris@0
|
40 */
|
Chris@0
|
41 public function testTranslatedSchemaDefinition() {
|
Chris@0
|
42 /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
|
Chris@0
|
43 $stringStorage = \Drupal::service('locale.storage');
|
Chris@0
|
44
|
Chris@0
|
45 $source = $stringStorage->createString([
|
Chris@0
|
46 'source' => 'Revision ID',
|
Chris@0
|
47 ])->save();
|
Chris@0
|
48
|
Chris@0
|
49 $stringStorage->createTranslation([
|
Chris@0
|
50 'lid' => $source->lid,
|
Chris@0
|
51 'language' => 'fr',
|
Chris@0
|
52 'translation' => 'Translated Revision ID',
|
Chris@0
|
53 ])->save();
|
Chris@0
|
54
|
Chris@0
|
55 // Ensure that the field is translated when access through the API.
|
Chris@0
|
56 $this->assertEqual('Translated Revision ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['vid']->getLabel());
|
Chris@0
|
57
|
Chris@0
|
58 // Assert there are no updates.
|
Chris@0
|
59 $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates());
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * Tests that translations do not affect the update system.
|
Chris@0
|
64 */
|
Chris@0
|
65 public function testTranslatedUpdate() {
|
Chris@0
|
66 // Visit the update page to collect any strings that may be translatable.
|
Chris@0
|
67 $user = $this->drupalCreateUser(['administer software updates']);
|
Chris@0
|
68 $this->drupalLogin($user);
|
Chris@0
|
69 $update_url = $GLOBALS['base_url'] . '/update.php';
|
Chris@0
|
70 $this->drupalGet($update_url, ['external' => TRUE]);
|
Chris@0
|
71
|
Chris@0
|
72 /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
|
Chris@0
|
73 $stringStorage = \Drupal::service('locale.storage');
|
Chris@0
|
74 $sources = $stringStorage->getStrings();
|
Chris@0
|
75
|
Chris@0
|
76 // Translate all source strings found.
|
Chris@0
|
77 foreach ($sources as $source) {
|
Chris@0
|
78 $stringStorage->createTranslation([
|
Chris@0
|
79 'lid' => $source->lid,
|
Chris@0
|
80 'language' => 'fr',
|
Chris@0
|
81 'translation' => $this->randomMachineName(100),
|
Chris@0
|
82 ])->save();
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 // Ensure that there are no updates just due to translations. Check for
|
Chris@0
|
86 // markup and a link instead of specific text because text may be
|
Chris@0
|
87 // translated.
|
Chris@0
|
88 $this->drupalGet($update_url . '/selection', ['external' => TRUE]);
|
Chris@18
|
89 $this->updateRequirementsProblem();
|
Chris@18
|
90 $this->drupalGet($update_url . '/selection', ['external' => TRUE]);
|
Chris@0
|
91 $this->assertRaw('messages--status', 'No pending updates.');
|
Chris@0
|
92 $this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.');
|
Chris@0
|
93 }
|
Chris@0
|
94
|
Chris@0
|
95 }
|