3 namespace Drupal\Tests\locale\Functional;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
9 * Adds and configures languages to check field schema definition.
13 class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
20 public static $modules = ['language', 'locale', 'node'];
25 protected function 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();
37 * Tests that translated field descriptions do not affect the update system.
39 public function testTranslatedSchemaDefinition() {
40 /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
41 $stringStorage = \Drupal::service('locale.storage');
43 $source = $stringStorage->createString([
44 'source' => 'Revision ID',
47 $stringStorage->createTranslation([
48 'lid' => $source->lid,
50 'translation' => 'Translated Revision ID',
53 // Ensure that the field is translated when access through the API.
54 $this->assertEqual('Translated Revision ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['vid']->getLabel());
56 // Assert there are no updates.
57 $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates());
61 * Tests that translations do not affect the update system.
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]);
70 /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
71 $stringStorage = \Drupal::service('locale.storage');
72 $sources = $stringStorage->getStrings();
74 // Translate all source strings found.
75 foreach ($sources as $source) {
76 $stringStorage->createTranslation([
77 'lid' => $source->lid,
79 'translation' => $this->randomMachineName(100),
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
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.');