annotate core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php @ 2:92f882872392

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