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