function FieldSqlStorageTest::testLongNames in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php \Drupal\system\Tests\Entity\FieldSqlStorageTest::testLongNames()
Tests that long entity type and field names do not break.
File
- core/
modules/ system/ src/ Tests/ Entity/ FieldSqlStorageTest.php, line 274 - Contains \Drupal\system\Tests\Entity\FieldSqlStorageTest.
Class
- FieldSqlStorageTest
- Tests Field SQL Storage .
Namespace
Drupal\system\Tests\EntityCode
function testLongNames() {
// Use one of the longest entity_type names in core.
$entity_type = $bundle = 'entity_test_label_callback';
$storage = $this->container
->get('entity.manager')
->getStorage($entity_type);
// Create two fields and generate random values.
$name_base = Unicode::strtolower($this
->randomMachineName(FieldStorageConfig::NAME_MAX_LENGTH - 1));
$field_names = array();
$values = array();
for ($i = 0; $i < 2; $i++) {
$field_names[$i] = $name_base . $i;
entity_create('field_storage_config', array(
'field_name' => $field_names[$i],
'entity_type' => $entity_type,
'type' => 'test_field',
))
->save();
entity_create('field_config', 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
->load($entity
->id());
foreach ($field_names as $field_name) {
$this
->assertEqual($entity
->get($field_name)->value, $values[$field_name]);
}
}