diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php index 8340c98..a3ab7dc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Entity\DatabaseStorageController; use Drupal\field\FieldException; +use Drupal\field\Plugin\Core\Entity\Field; use Drupal\system\Tests\Entity\EntityUnitTestBase; use PDO; @@ -17,7 +18,7 @@ * Tests field storage. * * Field_sql_storage.module implements the default back-end storage plugin - * for the Field Strage API. + * for the Field Storage API. */ class FieldSqlStorageTest extends EntityUnitTestBase { @@ -91,7 +92,7 @@ function setUp() { /** * Tests field loading works correctly by inserting directly in the tables. */ - function atestFieldLoad() { + function testFieldLoad() { $entity_type = $bundle = 'entity_test_rev'; $storage_controller = $this->container->get('plugin.manager.entity')->getStorageController($entity_type); @@ -160,9 +161,6 @@ function atestFieldLoad() { $this->assertFalse(array_key_exists($unavailable_langcode, $entity->{$this->field_name})); } - // @todo test fields with exceeding names & clashes. - - /** * Tests field saving works correctly by reading directly from the tables. */ @@ -256,6 +254,44 @@ function testFieldWrite() { } /** + * Tests that long entity type and field names do not break. + */ + function testLongNames() { + // Use one of the longest entity_type names in core. + $entity_type = $bundle = 'entity_test_label_callback'; + $storage_controller = $this->container->get('plugin.manager.entity')->getStorageController($entity_type); + + // Create two fields with instances, and generate randome values. + $name_base = drupal_strtolower($this->randomName(Field::NAME_MAX_LENGTH - 1)); + $field_names = array(); + $values = array(); + for ($i = 0; $i < 2; $i++) { + $field_names[$i] = $name_base . $i; + entity_create('field_entity', array( + 'name' => $field_names[$i], + 'entity_type' => $entity_type, + 'type' => 'test_field', + ))->save(); + entity_create('field_instance', array( + 'field_name' => $field_names[$i], + 'entity_type' => $entity_type, + 'bundle' => $bundle, + ))->save(); + $values[$field_names[$i]] = mt_rand(1, 127); + } + + // Save an entity with values. + $entity = entity_create($entity_type, $values); + $entity->save(); + + // Load the entity back and check the values. + $entity = $storage_controller->load($entity->id()); + foreach ($field_names as $field_name) { + $this->assertEqual($entity->get($field_name)->value, $values[$field_name]); + } + } + + /** * Test trying to update a field with data. */ function testUpdateFieldSchemaWithData() {