Commit 1f37397d authored by alexpott's avatar alexpott

Issue #2392669 by hussainweb, Mile23, rteijeiro, subhojit777, AjitS: Clean-up...

Issue #2392669 by hussainweb, Mile23, rteijeiro, subhojit777, AjitS: Clean-up field module test members - ensure property definition and use of camelCase naming convention
parent 95dc3178
......@@ -31,7 +31,7 @@ class BooleanFieldTest extends WebTestBase {
*
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $field_storage;
protected $fieldStorage;
/**
* The field used in this test class.
......@@ -46,13 +46,12 @@ class BooleanFieldTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array(
$this->drupalLogin($this->drupalCreateUser(array(
'view test entity',
'administer entity_test content',
'administer entity_test form display',
'administer entity_test fields',
));
$this->drupalLogin($this->web_user);
)));
}
/**
......@@ -65,12 +64,12 @@ function testBooleanField() {
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$this->field_storage = FieldStorageConfig::create(array(
$this->fieldStorage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'boolean',
));
$this->field_storage->save();
$this->fieldStorage->save();
$this->field = FieldConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
......
......@@ -36,7 +36,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
*
* @var array
*/
protected $entities_by_bundles;
protected $entitiesByBundles;
/**
* The bundles for the entities used in this test.
......@@ -48,9 +48,9 @@ class BulkDeleteTest extends FieldUnitTestBase {
/**
* The entity type to be used in the test classes.
*
* @var array
* @var string
*/
protected $entity_type = 'entity_test';
protected $entityTypeId = 'entity_test';
/**
* Tests that the expected hooks have been invoked on the expected entities.
......@@ -96,7 +96,7 @@ protected function setUp() {
$this->fieldStorages = array();
$this->entities = array();
$this->entities_by_bundles = array();
$this->entitiesByBundles = array();
// Create two bundles.
$this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2');
......@@ -107,7 +107,7 @@ protected function setUp() {
// Create two field storages.
$field_storage = entity_create('field_storage_config', array(
'field_name' => 'bf_1',
'entity_type' => $this->entity_type,
'entity_type' => $this->entityTypeId,
'type' => 'test_field',
'cardinality' => 1
));
......@@ -115,7 +115,7 @@ protected function setUp() {
$this->fieldStorages[] = $field_storage;
$field_storage = entity_create('field_storage_config', array(
'field_name' => 'bf_2',
'entity_type' => $this->entity_type,
'entity_type' => $this->entityTypeId,
'type' => 'test_field',
'cardinality' => 4
));
......@@ -132,14 +132,14 @@ protected function setUp() {
))->save();
}
for ($i = 0; $i < 10; $i++) {
$entity = entity_create($this->entity_type, array('type' => $bundle));
$entity = entity_create($this->entityTypeId, array('type' => $bundle));
foreach ($this->fieldStorages as $field_storage) {
$entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality()));
}
$entity->save();
}
}
$this->entities = entity_load_multiple($this->entity_type);
$this->entities = entity_load_multiple($this->entityTypeId);
foreach ($this->entities as $entity) {
// This test relies on the entities having stale field definitions
// so that the deleted field can be accessed on them. Access the field
......@@ -147,7 +147,7 @@ protected function setUp() {
$entity->bf_1->value;
// Also keep track of the entities per bundle.
$this->entities_by_bundles[$entity->bundle()][$entity->id()] = $entity;
$this->entitiesByBundles[$entity->bundle()][$entity->id()] = $entity;
}
}
......@@ -172,7 +172,7 @@ function testDeleteField() {
$this->assertEqual(count($found), 10, 'Correct number of entities found before deleting');
// Delete the field.
$field = FieldConfig::loadByName($this->entity_type, $bundle, $field_name);
$field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name);
$field->delete();
// The field still exists, deleted.
......@@ -182,7 +182,7 @@ function testDeleteField() {
$this->assertEqual($field->bundle, $bundle, 'The deleted field is for the correct bundle');
// Check that the actual stored content did not change during delete.
$storage = \Drupal::entityManager()->getStorage($this->entity_type);
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $storage->getTableMapping();
$table = $table_mapping->getDedicatedDataTableName($field_storage);
......@@ -225,7 +225,7 @@ function testPurgeField() {
$field_name = $field_storage->getName();
// Delete the field.
$field = FieldConfig::loadByName($this->entity_type, $bundle, $field_name);
$field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name);
$field->delete();
// No field hooks were called.
......@@ -250,7 +250,7 @@ function testPurgeField() {
// bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->entities_by_bundles[$bundle];
$entities = $this->entitiesByBundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_delete'][] = $entity;
}
......@@ -286,7 +286,7 @@ function testPurgeFieldStorage() {
// Delete the first field.
$bundle = reset($this->bundles);
$field = FieldConfig::loadByName($this->entity_type, $bundle, $field_name);
$field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name);
$field->delete();
// Assert that FieldItemInterface::delete() was not called yet.
......@@ -301,7 +301,7 @@ function testPurgeFieldStorage() {
// bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->entities_by_bundles[$bundle];
$entities = $this->entitiesByBundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_delete'][] = $entity;
}
......@@ -323,7 +323,7 @@ function testPurgeFieldStorage() {
// Delete the second field.
$bundle = next($this->bundles);
$field = FieldConfig::loadByName($this->entity_type, $bundle, $field_name);
$field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name);
$field->delete();
// Assert that FieldItemInterface::delete() was not called yet.
......@@ -336,7 +336,7 @@ function testPurgeFieldStorage() {
// Check hooks invocations (same as above, for the 2nd bundle).
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->entities_by_bundles[$bundle];
$entities = $this->entitiesByBundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_delete'][] = $entity;
}
......
......@@ -21,7 +21,7 @@ class DisplayApiTest extends FieldUnitTestBase {
*
* @var string
*/
protected $field_name;
protected $fieldName;
/**
* The field label to use in this test.
......@@ -42,7 +42,7 @@ class DisplayApiTest extends FieldUnitTestBase {
*
* @var array
*/
protected $display_options;
protected $displayOptions;
/**
* The test entity.
......@@ -62,24 +62,24 @@ protected function setUp() {
parent::setUp();
// Create a field and its storage.
$this->field_name = 'test_field';
$this->fieldName = 'test_field';
$this->label = $this->randomMachineName();
$this->cardinality = 4;
$field_storage = array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'test_field',
'cardinality' => $this->cardinality,
);
$field = array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $this->label,
);
$this->display_options = array(
$this->displayOptions = array(
'default' => array(
'type' => 'field_test_default',
'settings' => array(
......@@ -98,18 +98,18 @@ protected function setUp() {
entity_create('field_config', $field)->save();
// Create a display for the default view mode.
entity_get_display($field['entity_type'], $field['bundle'], 'default')
->setComponent($this->field_name, $this->display_options['default'])
->setComponent($this->fieldName, $this->displayOptions['default'])
->save();
// Create a display for the teaser view mode.
EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save();
entity_get_display($field['entity_type'], $field['bundle'], 'teaser')
->setComponent($this->field_name, $this->display_options['teaser'])
->setComponent($this->fieldName, $this->displayOptions['teaser'])
->save();
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->setValue($this->values);
$this->entity->{$this->fieldName}->setValue($this->values);
$this->entity->save();
}
......@@ -117,7 +117,7 @@ protected function setUp() {
* Tests the FieldItemListInterface::view() method.
*/
function testFieldItemListView() {
$items = $this->entity->get($this->field_name);
$items = $this->entity->get($this->fieldName);
// No display settings: check that default display settings are used.
$build = $items->view();
......@@ -192,7 +192,7 @@ function testFieldItemListView() {
// are used.
$build = $items->view('teaser');
$this->render($build);
$setting = $this->display_options['teaser']['settings']['test_formatter_setting'];
$setting = $this->displayOptions['teaser']['settings']['test_formatter_setting'];
$this->assertText($this->label, 'Label was displayed.');
foreach ($this->values as $delta => $value) {
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -202,7 +202,7 @@ function testFieldItemListView() {
// are used.
$build = $items->view('unknown_view_mode');
$this->render($build);
$setting = $this->display_options['default']['settings']['test_formatter_setting'];
$setting = $this->displayOptions['default']['settings']['test_formatter_setting'];
$this->assertText($this->label, 'Label was displayed.');
foreach ($this->values as $delta => $value) {
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -217,7 +217,7 @@ function testFieldItemView() {
$settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings('field_test_default');
$setting = $settings['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[$delta];
$item = $this->entity->{$this->fieldName}[$delta];
$build = $item->view();
$this->render($build);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -232,7 +232,7 @@ function testFieldItemView() {
);
$setting = $display['settings']['test_formatter_setting_multiple'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[$delta];
$item = $this->entity->{$this->fieldName}[$delta];
$build = $item->view($display);
$this->render($build);
$this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -247,16 +247,16 @@ function testFieldItemView() {
);
$setting = $display['settings']['test_formatter_setting_additional'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[$delta];
$item = $this->entity->{$this->fieldName}[$delta];
$build = $item->view($display);
$this->render($build);
$this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
}
// View mode: check that display settings specified in the field are used.
$setting = $this->display_options['teaser']['settings']['test_formatter_setting'];
$setting = $this->displayOptions['teaser']['settings']['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[$delta];
$item = $this->entity->{$this->fieldName}[$delta];
$build = $item->view('teaser');
$this->render($build);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -264,9 +264,9 @@ function testFieldItemView() {
// Unknown view mode: check that display settings for 'default' view mode
// are used.
$setting = $this->display_options['default']['settings']['test_formatter_setting'];
$setting = $this->displayOptions['default']['settings']['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[$delta];
$item = $this->entity->{$this->fieldName}[$delta];
$build = $item->view('unknown_view_mode');
$this->render($build);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -287,16 +287,16 @@ function testFieldEmpty() {
);
// $this->entity is set by the setUp() method and by default contains 4
// numeric values. We only want to test the display of this one field.
$build = $this->entity->get($this->field_name)->view($display);
$build = $this->entity->get($this->fieldName)->view($display);
$this->render($build);
// The test field by default contains values, so should not display the
// default "empty" text.
$this->assertNoText($display['settings']['test_empty_string']);
// Now remove the values from the test field and retest.
$this->entity->{$this->field_name} = array();
$this->entity->{$this->fieldName} = array();
$this->entity->save();
$build = $this->entity->get($this->field_name)->view($display);
$build = $this->entity->get($this->fieldName)->view($display);
$this->render($build);
// This time, as the field values have been removed, we *should* show the
// default "empty" text.
......
......@@ -41,12 +41,11 @@ class EmailFieldTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array(
$this->drupalLogin($this->drupalCreateUser(array(
'view test entity',
'administer entity_test content',
'administer content types',
));
$this->drupalLogin($this->web_user);
)));
}
/**
......
......@@ -33,7 +33,7 @@ class FieldAccessTest extends FieldTestBase {
*
* @var string
*/
protected $test_view_field_value;
protected $testViewFieldValue;
protected function setUp() {
parent::setUp();
......@@ -66,11 +66,11 @@ protected function setUp() {
}
// Create test node.
$this->test_view_field_value = 'This is some text';
$this->testViewFieldValue = 'This is some text';
$settings = array();
$settings['type'] = $content_type;
$settings['title'] = 'Field view access test';
$settings['test_view_field'] = array(array('value' => $this->test_view_field_value));
$settings['test_view_field'] = array(array('value' => $this->testViewFieldValue));
$this->node = $this->drupalCreateNode($settings);
}
......@@ -81,13 +81,13 @@ function testFieldAccess() {
// Assert the text is visible.
$this->drupalGet('node/' . $this->node->id());
$this->assertText($this->test_view_field_value);
$this->assertText($this->testViewFieldValue);
// Assert the text is not visible for anonymous users.
// The field_test module implements hook_entity_field_access() which will
// specifically target the 'test_view_field' field.
$this->drupalLogout();
$this->drupalGet('node/' . $this->node->id());
$this->assertNoText($this->test_view_field_value);
$this->assertNoText($this->testViewFieldValue);
}
}
......@@ -27,7 +27,7 @@ class FieldDataCountTest extends FieldUnitTestBase {
/**
* @var \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface
*/
protected $storage_rev;
protected $storageRev;
/**
* {@inheritdoc}
......@@ -36,7 +36,7 @@ protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->storage = \Drupal::entityManager()->getStorage('entity_test');
$this->storage_rev = \Drupal::entityManager()->getStorage('entity_test_rev');
$this->storageRev = \Drupal::entityManager()->getStorage('entity_test_rev');
}
/**
......@@ -112,7 +112,7 @@ public function testEntityCountAndHasData() {
$cardinality = $this->fieldTestData->field_storage_2->getCardinality();
$this->assertIdentical($this->fieldTestData->field_storage_2->hasData(), FALSE, 'There are no entities with field data.');
$this->assertIdentical($this->storage_rev->countFieldData($this->fieldTestData->field_storage_2), 0, 'There are 0 entities with field data.');
$this->assertIdentical($this->storageRev->countFieldData($this->fieldTestData->field_storage_2), 0, 'There are 0 entities with field data.');
// Create 1 entity with the field.
$entity = clone($entity_init);
......@@ -123,7 +123,7 @@ public function testEntityCountAndHasData() {
$first_revision = $entity->getRevisionId();
$this->assertIdentical($this->fieldTestData->field_storage_2->hasData(), TRUE, 'There are entities with field data.');
$this->assertIdentical($this->storage_rev->countFieldData($this->fieldTestData->field_storage_2), 1, 'There is 1 entity with field data.');
$this->assertIdentical($this->storageRev->countFieldData($this->fieldTestData->field_storage_2), 1, 'There is 1 entity with field data.');
$entity->{$this->fieldTestData->field_name_2} = array();
$entity->setNewRevision();
......
......@@ -28,8 +28,7 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('synchronize configuration'));
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->drupalCreateUser(array('synchronize configuration')));
}
/**
......
......@@ -24,18 +24,17 @@ class NumberFieldTest extends WebTestBase {
*/
public static $modules = array('node', 'entity_test', 'field_ui');
/**
* A user with permission to view and manage entities and content types.
*
* @var \Drupal\user\UserInterface
*/
protected $web_user;
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content', 'administer content types', 'administer node fields', 'administer node display', 'bypass node access', 'administer entity_test fields'));
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->drupalCreateUser(array(
'view test entity',
'administer entity_test content',
'administer content types',
'administer node fields',
'administer node display',
'bypass node access',
'administer entity_test fields',
)));
}
/**
......
......@@ -29,20 +29,20 @@ class ShapeItemTest extends FieldUnitTestBase {
*
* @var string
*/
protected $field_name = 'field_shape';
protected $fieldName = 'field_shape';
protected function setUp() {
parent::setUp();
// Create a 'shape' field and storage for validation.
entity_create('field_storage_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'shape',
))->save();
entity_create('field_config', array(
'entity_type' => 'entity_test',
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'bundle' => 'entity_test',
))->save();
}
......@@ -55,34 +55,34 @@ public function testShapeItem() {
$entity = entity_create('entity_test');
$shape = 'cube';
$color = 'blue';
$entity->{$this->field_name}->shape = $shape;
$entity->{$this->field_name}->color = $color;
$entity->{$this->fieldName}->shape = $shape;
$entity->{$this->fieldName}->color = $color;
$entity->name->value = $this->randomMachineName();
$entity->save();
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertTrue($entity->{$this->field_name} instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->{$this->field_name}[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->{$this->field_name}->shape, $shape);
$this->assertEqual($entity->{$this->field_name}->color, $color);
$this->assertEqual($entity->{$this->field_name}[0]->shape, $shape);
$this->assertEqual($entity->{$this->field_name}[0]->color, $color);
$this->assertTrue($entity->{$this->fieldName} instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->{$this->fieldName}[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->{$this->fieldName}->shape, $shape);
$this->assertEqual($entity->{$this->fieldName}->color, $color);
$this->assertEqual($entity->{$this->fieldName}[0]->shape, $shape);
$this->assertEqual($entity->{$this->fieldName}[0]->color, $color);
// Verify changing the field value.
$new_shape = 'circle';
$new_color = 'red';
$entity->{$this->field_name}->shape = $new_shape;
$entity->{$this->field_name}->color = $new_color;
$this->assertEqual($entity->{$this->field_name}->shape, $new_shape);
$this->assertEqual($entity->{$this->field_name}->color, $new_color);
$entity->{$this->fieldName}->shape = $new_shape;
$entity->{$this->fieldName}->color = $new_color;
$this->assertEqual($entity->{$this->fieldName}->shape, $new_shape);
$this->assertEqual($entity->{$this->fieldName}->color, $new_color);
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->{$this->field_name}->shape, $new_shape);
$this->assertEqual($entity->{$this->field_name}->color, $new_color);
$this->assertEqual($entity->{$this->fieldName}->shape, $new_shape);
$this->assertEqual($entity->{$this->fieldName}->color, $new_color);
}
}
......@@ -30,20 +30,20 @@ class TestItemTest extends FieldUnitTestBase {
*
* @var string
*/
protected $field_name = 'field_test';
protected $fieldName = 'field_test';
protected function setUp() {
parent::setUp();
// Create a 'test_field' field and storage for validation.
entity_create('field_storage_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'test_field',
))->save();
entity_create('field_config', array(
'entity_type' => 'entity_test',
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'bundle' => 'entity_test',
))->save();
}
......@@ -62,20 +62,20 @@ public function testTestItem() {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertTrue($entity->{$this->field_name} instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->{$this->field_name}[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->{$this->field_name}->value, $value);
$this->assertEqual($entity->{$this->field_name}[0]->value, $value);
$this->assertTrue($entity->{$this->fieldName} instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->{$this->fieldName}[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->{$this->fieldName}->value, $value);
$this->assertEqual($entity->{$this->fieldName}[0]->value, $value);
// Verify changing the field value.
$new_value = rand(1, 10);
$entity->field_test->value = $new_value;
$this->assertEqual($entity->{$this->field_name}->value, $new_value);
$this->assertEqual($entity->{$this->fieldName}->value, $new_value);
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->{$this->field_name}->value, $new_value);
$this->assertEqual($entity->{$this->fieldName}->value, $new_value);
// Test the schema for this field type.
$expected_schema = array(
......
......@@ -26,7 +26,7 @@ class TestItemWithDependenciesTest extends FieldUnitTestBase {
*
* @var string
*/
protected $field_name = 'field_test';
protected $fieldName = 'field_test';
/**
* Tests that field types can add dependencies to field config entities.
......@@ -34,13 +34,13 @@ class TestItemWithDependenciesTest extends FieldUnitTestBase {
public function testTestItemWithDepenencies() {
// Create a 'test_field_with_dependencies' field and storage for validation.
entity_create('field_storage_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'test_field_with_dependencies',
))->save();
$field = entity_create('field_config', array(
'entity_type' => 'entity_test',
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'bundle' => 'entity_test',
));
$field->save();
......
......@@ -33,28 +33,28 @@ class TranslationTest extends FieldUnitTestBase {
*
* @var string
*/
protected $field_name;
protected $fieldName;
/**
* The name of the entity type to use in this test.
*
* @var string
*/
protected $entity_type = 'test_entity';
protected $entityType = 'test_entity';
/**
* An array defining the field storage to use in this test.
*
* @var array
*/
protected $field_storage_definition;
protected $fieldStorageDefinition;
/**
* An array defining the field to use in this test.
*
* @var array
*/
protected $field_definition;
protected $fieldDefinition;
/**
* The field storage to use in this test.
......@@ -78,24 +78,24 @@ protected function setUp() {
$this->installConfig(array('language'));
$this->field_name = Unicode::strtolower($this->randomMachineName());
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$this->entity_type = 'entity_test';
$this->entityType = 'entity_test';
$this->field_storage_definition = array(
'field_name' => $this->field_name,
'entity_type' => $this->entity_type,
$this->fieldStorageDefinition = array(
'field_name' => $this->fieldName,
'entity_type' => $this->entityType,
'type' => 'test_field',
'cardinality' => 4,
);
$this->fieldStorage = entity_create('field_storage_config', $this->field_storage_definition);
$this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->field_definition = array(
$this->fieldDefinition = array(
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
);
$this->field = entity_create('field_config', $this->field_definition);
$this->field = entity_create('field_config', $this->fieldDefinition);
$this->field->save();
for ($i = 0; $i < 3; ++$i) {
......@@ -124,7 +124,7 @@ function testTranslatableFieldSaveLoad() {
$entity->langcode->value = reset($available_langcodes);
foreach ($available_langcodes as $langcode) {
$field_translations[$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality());
$entity->getTranslation($langcode)->{$this->field_name}->setValue($field_translations[$langcode]);
$entity->getTranslation($langcode)->{$this->fieldName}->setValue($field_translations[$langcode]);
}
// Save and reload the field translations.
......@@ -134,19 +134,19 @@ function testTranslatableFieldSaveLoad() {
foreach ($field_translations as $langcode => $items) {
$result = TRUE;
foreach ($items as $delta => $item) {
$result = $result && $item['value'] == $entity->getTranslation($langcode)->{$this->field_name}[$delta]->value;
$result = $result && $item['value'] == $entity->getTranslation($langcode)->{$this->fieldName}[$delta]->value;
}