From 26b99df319937f63aedd9a7e599622d24e091a5b Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 4 Feb 2015 11:52:16 +0000 Subject: [PATCH] =?UTF-8?q?Issue=20#2363099=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?Berdir,=20swentel,=20plach:=20Using=20translated=20field=20defi?= =?UTF-8?q?nition=20descriptions=20in=20entity=20schema=20results=20in=20d?= =?UTF-8?q?ifferent=20schema=20definitions,=20resulting=20in=20update.php?= =?UTF-8?q?=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sql/SqlContentEntityStorageSchema.php | 2 - .../TypedData/DataDefinitionInterface.php | 3 + .../LocaleTranslatedSchemaDefinitionTest.php | 93 +++++++++++++++++++ .../Sql/SqlContentEntityStorageSchemaTest.php | 44 --------- .../Sql/SqlContentEntityStorageTest.php | 1 - 5 files changed, 96 insertions(+), 47 deletions(-) create mode 100644 core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 8e4deba2093b..7cf252475fcc 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -1418,7 +1418,6 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st } $field_name = $storage_definition->getName(); - $field_description = $storage_definition->getDescription(); $base_table = $this->storage->getBaseTable(); // A shared table contains rows for entities where the field is empty @@ -1447,7 +1446,6 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st $column_schema = $field_schema['columns'][$field_column_name]; $schema['fields'][$schema_field_name] = $column_schema; - $schema['fields'][$schema_field_name]['description'] = $field_description; $schema['fields'][$schema_field_name]['not null'] = in_array($field_name, $not_null_keys); } diff --git a/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php b/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php index a452475aefa5..33f9db327c74 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php @@ -70,6 +70,9 @@ public function getLabel(); /** * Returns a human readable description. * + * Descriptions are usually used on user interfaces where the data is edited + * or displayed. + * * @return string|null * The description, or NULL if no description is available. */ diff --git a/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php b/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php new file mode 100644 index 000000000000..73a9f25c1d64 --- /dev/null +++ b/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php @@ -0,0 +1,93 @@ +<?php + +/** + * @file + * Contains Drupal\locale\Tests\LocaleTranslatedSchemaDefinitionTest. + */ + +namespace Drupal\locale\Tests; + +use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\simpletest\WebTestBase; + +/** + * Adds and configures languages to check field schema definition. + * + * @group locale + */ +class LocaleTranslatedSchemaDefinitionTest extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('language', 'locale', 'node'); + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + ConfigurableLanguage::createFromLangcode('fr')->save(); + $this->config('system.site')->set('langcode', 'fr')->save(); + // Clear all caches so that the base field definition, its cache in the + // entity manager, the t() cache, etc. are all cleared. + drupal_flush_all_caches(); + } + + /** + * Tests that translated field descriptions do not affect the update system. + */ + function testTranslatedSchemaDefinition() { + /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */ + $stringStorage = \Drupal::service('locale.storage'); + + $source = $stringStorage->createString(array( + 'source' => 'The node ID.', + ))->save(); + + $stringStorage->createTranslation(array( + 'lid' => $source->lid, + 'language' => 'fr', + 'translation' => 'Translated node ID', + ))->save(); + + // Ensure that the field is translated when access through the API. + $this->assertEqual('Translated node ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['nid']->getDescription()); + + // Assert there are no updates. + $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates()); + } + + /** + * Tests that translations do not affect the update system. + */ + function testTranslatedUpdate() { + // Visit the update page to collect any strings that may be translatable. + $user = $this->drupalCreateUser(array('administer software updates')); + $this->drupalLogin($user); + $update_url = $GLOBALS['base_url'] . '/update.php'; + $this->drupalGet($update_url, array('external' => TRUE)); + + /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */ + $stringStorage = \Drupal::service('locale.storage'); + $sources = $stringStorage->getStrings(); + + // Translate all source strings found. + foreach ($sources as $source) { + $stringStorage->createTranslation(array( + 'lid' => $source->lid, + 'language' => 'fr', + 'translation' => $this->randomMachineName(100), + ))->save(); + } + + // Ensure that there are no updates just due to translations. Check for + // markup and a link instead of specific text because text may be + // translated. + $this->drupalGet($update_url . '/selection', array('external' => TRUE)); + $this->assertRaw('messages--status', 'No pending updates.'); + $this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.'); + } +} diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index 699bdba3bfa5..fa5025902105 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -112,11 +112,9 @@ public function testGetSchemaBase() { 'columns' => array( 'value' => array( 'type' => 'text', - 'description' => 'The text value', ), 'format' => array( 'type' => 'varchar', - 'description' => 'The text description', ), ), )); @@ -248,95 +246,77 @@ public function testGetSchemaBase() { 'description' => 'The base table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'serial', 'not null' => TRUE, ), 'name' => array( - 'description' => 'The name field.', 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ), 'description__value' => array( - 'description' => 'The description field.', 'type' => 'text', 'not null' => FALSE, ), 'description__format' => array( - 'description' => 'The description field.', 'type' => 'varchar', 'not null' => FALSE, ), 'uuid' => array( - 'description' => 'The uuid field.', 'type' => 'varchar', 'length' => 128, 'not null' => FALSE, ), 'hash' => array( - 'description' => 'The hash field.', 'type' => 'varchar', 'length' => 20, 'not null' => FALSE, ), 'email__username' => array( - 'description' => 'The email field.', 'type' => 'varchar', 'not null' => FALSE, ), 'email__hostname' => array( - 'description' => 'The email field.', 'type' => 'varchar', 'not null' => FALSE, ), 'email__domain' => array( - 'description' => 'The email field.', 'type' => 'varchar', 'not null' => FALSE, ), 'owner' => array( - 'description' => 'The owner field.', 'type' => 'int', 'not null' => FALSE, ), 'translator' => array( - 'description' => 'The translator field.', 'type' => 'int', 'not null' => FALSE, ), 'location__country' => array( - 'description' => 'The location field.', 'type' => 'varchar', 'not null' => FALSE, ), 'location__state' => array( - 'description' => 'The location field.', 'type' => 'varchar', 'not null' => FALSE, ), 'location__city' => array( - 'description' => 'The location field.', 'type' => 'varchar', 'not null' => FALSE, ), 'editor' => array( - 'description' => 'The editor field.', 'type' => 'int', 'not null' => FALSE, ), 'editor_revision__target_id' => array( - 'description' => 'The editor_revision field.', 'type' => 'int', 'not null' => FALSE, ), 'editor_revision__target_revision_id' => array( - 'description' => 'The editor_revision field.', 'type' => 'int', 'not null' => FALSE, ), 'long_index_name' => array( - 'description' => 'The long_index_name field.', 'type' => 'int', 'not null' => FALSE, ), @@ -439,12 +419,10 @@ public function testGetSchemaRevisionable() { 'description' => 'The base table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'serial', 'not null' => TRUE, ), 'revision_id' => array( - 'description' => 'The revision_id field.', 'type' => 'int', 'not null' => FALSE, ) @@ -465,12 +443,10 @@ public function testGetSchemaRevisionable() { 'description' => 'The revision table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'int', 'not null' => TRUE, ), 'revision_id' => array( - 'description' => 'The revision_id field.', 'type' => 'serial', 'not null' => TRUE, ), @@ -538,12 +514,10 @@ public function testGetSchemaTranslatable() { 'description' => 'The base table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'serial', 'not null' => TRUE, ), 'langcode' => array( - 'description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE, ) @@ -557,12 +531,10 @@ public function testGetSchemaTranslatable() { 'description' => 'The data table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'int', 'not null' => TRUE, ), 'langcode' => array( - 'description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE, ), @@ -645,17 +617,14 @@ public function testGetSchemaRevisionableTranslatable() { 'description' => 'The base table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'serial', 'not null' => TRUE, ), 'revision_id' => array( - 'description' => 'The revision_id field.', 'type' => 'int', 'not null' => FALSE, ), 'langcode' => array( - 'description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE, ) @@ -676,17 +645,14 @@ public function testGetSchemaRevisionableTranslatable() { 'description' => 'The revision table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'int', 'not null' => TRUE, ), 'revision_id' => array( - 'description' => 'The revision_id field.', 'type' => 'serial', 'not null' => TRUE, ), 'langcode' => array( - 'description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE, ), @@ -707,17 +673,14 @@ public function testGetSchemaRevisionableTranslatable() { 'description' => 'The data table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'int', 'not null' => TRUE, ), 'revision_id' => array( - 'description' => 'The revision_id field.', 'type' => 'int', 'not null' => TRUE, ), 'langcode' => array( - 'description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE, ), @@ -738,17 +701,14 @@ public function testGetSchemaRevisionableTranslatable() { 'description' => 'The revision data table for entity_test entities.', 'fields' => array( 'id' => array( - 'description' => 'The id field.', 'type' => 'int', 'not null' => TRUE, ), 'revision_id' => array( - 'description' => 'The revision_id field.', 'type' => 'int', 'not null' => TRUE, ), 'langcode' => array( - 'description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE, ), @@ -1242,10 +1202,6 @@ public function setUpStorageDefinition($field_name, array $schema) { $this->storageDefinitions[$field_name]->expects($this->any()) ->method('getName') ->will($this->returnValue($field_name)); - // getDescription() is called once for each table. - $this->storageDefinitions[$field_name]->expects($this->any()) - ->method('getDescription') - ->will($this->returnValue("The $field_name field.")); // getSchema() is called once for each table. $this->storageDefinitions[$field_name]->expects($this->any()) ->method('getSchema') diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index e90d14512219..ec24b1abe6cd 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -324,7 +324,6 @@ public function testOnEntityTypeCreate() { 'fields' => array( 'id' => array( 'type' => 'serial', - 'description' => NULL, 'not null' => TRUE, ), ), -- GitLab