Commit 0b0cdc29 authored by webchick's avatar webchick
Browse files

Issue #2306539 by swentel, alexpott, sun: Fixed...

Issue #2306539 by swentel, alexpott, sun: Fixed FieldUnitTestBase::createFieldWithInstance() pollutes test class with arbitrary properties.
parent 73a65a36
......@@ -29,21 +29,21 @@ public function setUp() {
parent::setUp();
// Create a field with settings to validate.
$this->fieldStorage = entity_create('field_storage_config', array(
$field_storage = entity_create('field_storage_config', array(
'name' => 'field_datetime',
'type' => 'datetime',
'entity_type' => 'entity_test',
'settings' => array('datetime_type' => 'date'),
));
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array(
'field_storage' => $this->fieldStorage,
$field_storage->save();
$instance = entity_create('field_instance_config', array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'settings' => array(
'default_value' => 'blank',
),
));
$this->instance->save();
$instance->save();
}
/**
......
......@@ -64,7 +64,6 @@ public function setUp() {
// Install the Filter module.
$this->installSchema('system', 'url_alias');
$this->enableModules(array('user', 'filter'));
// Enable the Text Editor and Text Editor Test module.
$this->enableModules(array('editor', 'editor_test'));
......@@ -130,23 +129,23 @@ public function testEditorSelection() {
$this->editorSelector = $this->container->get('quickedit.editor.selector');
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->value = 'Hello, world!';
$this->entity->{$this->field_name}->format = 'filtered_html';
$this->entity->save();
$entity = entity_create('entity_test');
$entity->{$this->field_name}->value = 'Hello, world!';
$entity->{$this->field_name}->format = 'filtered_html';
$entity->save();
// Editor selection w/ cardinality 1, text format w/o associated text editor.
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
// Editor selection w/ cardinality 1, text format w/ associated text editor.
$this->entity->{$this->field_name}->format = 'full_html';
$this->entity->save();
$this->assertEqual('editor', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality 1, and the full_html text format, the 'editor' editor is selected.");
$entity->{$this->field_name}->format = 'full_html';
$entity->save();
$this->assertEqual('editor', $this->getSelectedEditor($entity->id(), $this->field_name), "With cardinality 1, and the full_html text format, the 'editor' editor is selected.");
// Editor selection with text processing, cardinality >1
$this->field_textarea_field_storage->cardinality = 2;
$this->field_textarea_field_storage->save();
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
$this->fields->field_textarea_field_storage->cardinality = 2;
$this->fields->field_textarea_field_storage->save();
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
/**
......@@ -159,11 +158,11 @@ public function testMetadata() {
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create an entity with values for the field.
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->value = 'Test';
$this->entity->{$this->field_name}->format = 'full_html';
$this->entity->save();
$entity = entity_load('entity_test', $this->entity->id());
$entity = entity_create('entity_test');
$entity->{$this->field_name}->value = 'Test';
$entity->{$this->field_name}->format = 'full_html';
$entity->save();
$entity = entity_load('entity_test', $entity->id());
// Verify metadata.
$items = $entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED)->get($this->field_name);
......@@ -197,11 +196,11 @@ public function testAttachments() {
*/
public function testGetUntransformedTextCommand() {
// Create an entity with values for the field.
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->value = 'Test';
$this->entity->{$this->field_name}->format = 'full_html';
$this->entity->save();
$entity = entity_load('entity_test', $this->entity->id());
$entity = entity_create('entity_test');
$entity->{$this->field_name}->value = 'Test';
$entity->{$this->field_name}->format = 'full_html';
$entity->save();
$entity = entity_load('entity_test', $entity->id());
// Verify AJAX response.
$controller = new EditorController();
......
......@@ -24,6 +24,16 @@ class ConfigFieldDefinitionTest extends FieldUnitTestBase {
*/
protected $entityManager;
/**
* @var string
*/
private $entityType;
/**
* @var string
*/
private $bundle;
/**
* {@inheritdoc}
*/
......@@ -46,10 +56,10 @@ public function setUp() {
*/
public function testBundleFieldDefinition() {
$definitions = $this->entityManager->getFieldDefinitions($this->entityType, $this->bundle);
$this->assertTrue(isset($definitions[$this->instance->getName()]));
$this->assertTrue($definitions[$this->instance->getName()] instanceof FieldDefinitionInterface);
$this->assertTrue(isset($definitions[$this->fieldTestData->instance->getName()]));
$this->assertTrue($definitions[$this->fieldTestData->instance->getName()] instanceof FieldDefinitionInterface);
// Make sure no field for the instance on another entity type is exposed.
$this->assertFalse(isset($definitions[$this->instance_rev->getName()]));
$this->assertFalse(isset($definitions[$this->fieldTestData->instance_rev->getName()]));
}
/**
......@@ -57,11 +67,11 @@ public function testBundleFieldDefinition() {
*/
public function testFieldStorageDefinition() {
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityType);
$this->assertTrue(isset($field_storage_definitions[$this->instance->getName()]));
$this->assertTrue($field_storage_definitions[$this->instance->getName()] instanceof FieldStorageDefinitionInterface);
$this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->instance->getName()]));
$this->assertTrue($field_storage_definitions[$this->fieldTestData->instance->getName()] instanceof FieldStorageDefinitionInterface);
// Make sure no storage field for the instance on another entity type is
// exposed.
$this->assertFalse(isset($field_storage_definitions[$this->instance_rev->getName()]));
$this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->instance_rev->getName()]));
}
}
......@@ -278,66 +278,66 @@ function testDelete() {
// TODO: Also test deletion of the data stored in the field ?
// Create two fields (so we can test that only one is deleted).
$this->field = array(
$field = array(
'name' => 'field_1',
'type' => 'test_field',
'entity_type' => 'entity_test',
);
entity_create('field_storage_config', $this->field)->save();
$this->another_field = array(
entity_create('field_storage_config', $field)->save();
$another_field = array(
'name' => 'field_2',
'type' => 'test_field',
'entity_type' => 'entity_test',
);
entity_create('field_storage_config', $this->another_field)->save();
entity_create('field_storage_config', $another_field)->save();
// Create instances for each.
$this->instance_definition = array(
'field_name' => $this->field['name'],
$instance_definition = array(
'field_name' => $field['name'],
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
entity_create('field_instance_config', $this->instance_definition)->save();
$another_instance_definition = $this->instance_definition;
$another_instance_definition['field_name'] = $this->another_field['name'];
entity_create('field_instance_config', $instance_definition)->save();
$another_instance_definition = $instance_definition;
$another_instance_definition['field_name'] = $another_field['name'];
entity_create('field_instance_config', $another_instance_definition)->save();
// Test that the first field is not deleted, and then delete it.
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE)));
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field['name'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($field_storage) && empty($field_storage->deleted), 'A new field is not marked for deletion.');
FieldStorageConfig::loadByName('entity_test', $this->field['name'])->delete();
FieldStorageConfig::loadByName('entity_test', $field['name'])->delete();
// Make sure that the field is marked as deleted when it is specifically
// loaded.
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE)));
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field['name'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($field_storage->deleted), 'A deleted field is marked for deletion.');
// Make sure that this field's instance is marked as deleted when it is
// specifically loaded.
$instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE)));
$instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $instance_definition['field_name'], 'bundle' => $instance_definition['bundle'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($instance->deleted), 'An instance for a deleted field is marked for deletion.');
// Try to load the field normally and make sure it does not show up.
$field_storage = entity_load('field_storage_config', 'entity_test.' . $this->field['name']);
$field_storage = entity_load('field_storage_config', 'entity_test.' . $field['name']);
$this->assertTrue(empty($field_storage), 'A deleted field is not loaded by default.');
// Try to load the instance normally and make sure it does not show up.
$instance = entity_load('field_instance_config', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']);
$instance = entity_load('field_instance_config', 'entity_test.' . '.' . $instance_definition['bundle'] . '.' . $instance_definition['field_name']);
$this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.');
// Make sure the other field (and its field instance) are not deleted.
$another_field_storage = entity_load('field_storage_config', 'entity_test.' . $this->another_field['name']);
$another_field_storage = entity_load('field_storage_config', 'entity_test.' . $another_field['name']);
$this->assertTrue(!empty($another_field_storage) && empty($another_field_storage->deleted), 'A non-deleted field is not marked for deletion.');
$another_instance = entity_load('field_instance_config', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']);
$this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'An instance of a non-deleted field is not marked for deletion.');
// Try to create a new field the same name as a deleted field and
// write data into it.
entity_create('field_storage_config', $this->field)->save();
entity_create('field_instance_config', $this->instance_definition)->save();
$field_storage = entity_load('field_storage_config', 'entity_test.' . $this->field['name']);
entity_create('field_storage_config', $field)->save();
entity_create('field_instance_config', $instance_definition)->save();
$field_storage = entity_load('field_storage_config', 'entity_test.' . $field['name']);
$this->assertTrue(!empty($field_storage) && empty($field_storage->deleted), 'A new field with a previously used name is created.');
$instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name'] );
$instance = entity_load('field_instance_config', 'entity_test.' . $instance_definition['bundle'] . '.' . $instance_definition['field_name'] );
$this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new instance for a previously used field name is created.');
// Save an entity with data for the field
......
......@@ -18,21 +18,7 @@
*/
class FieldAttachOtherTest extends FieldUnitTestBase {
/**
* Field name to use in the test.
*
* @var string
*/
protected $field_name;
/**
* Field name to use in the test.
*
* @var string
*/
protected $field_name_2;
public function setUp() {
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->createFieldWithInstance();
......@@ -48,10 +34,10 @@ function testEntityDisplayBuild() {
$entity_init = entity_create($entity_type);
// Populate values to be displayed.
$values = $this->_generateTestFieldValues($this->field_storage->getCardinality());
$entity_init->{$this->field_name}->setValue($values);
$values_2 = $this->_generateTestFieldValues($this->field_storage_2->getCardinality());
$entity_init->{$this->field_name_2}->setValue($values_2);
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
$entity_init->{$this->fieldTestData->field_name}->setValue($values);
$values_2 = $this->_generateTestFieldValues($this->fieldTestData->field_storage_2->getCardinality());
$entity_init->{$this->fieldTestData->field_name_2}->setValue($values_2);
// Simple formatter, label displayed.
$entity = clone($entity_init);
......@@ -65,7 +51,7 @@ function testEntityDisplayBuild() {
'test_formatter_setting' => $formatter_setting,
),
);
$display->setComponent($this->field_name, $display_options);
$display->setComponent($this->fieldTestData->field_name, $display_options);
$formatter_setting_2 = $this->randomName();
$display_options_2 = array(
......@@ -75,16 +61,16 @@ function testEntityDisplayBuild() {
'test_formatter_setting' => $formatter_setting_2,
),
);
$display->setComponent($this->field_name_2, $display_options_2);
$display->setComponent($this->fieldTestData->field_name_2, $display_options_2);
// View all fields.
$content = $display->build($entity);
$this->render($content);
$this->assertRaw($this->instance->getLabel(), "First field's label is displayed.");
$this->assertRaw($this->fieldTestData->instance->getLabel(), "First field's label is displayed.");
foreach ($values as $delta => $value) {
$this->assertRaw("$formatter_setting|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
}
$this->assertRaw($this->instance_2->getLabel(), "Second field's label is displayed.");
$this->assertRaw($this->fieldTestData->instance_2->getLabel(), "Second field's label is displayed.");
foreach ($values_2 as $delta => $value) {
$this->assertRaw("$formatter_setting_2|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
}
......@@ -92,17 +78,17 @@ function testEntityDisplayBuild() {
// Label hidden.
$entity = clone($entity_init);
$display_options['label'] = 'hidden';
$display->setComponent($this->field_name, $display_options);
$display->setComponent($this->fieldTestData->field_name, $display_options);
$content = $display->build($entity);
$this->render($content);
$this->assertNoRaw($this->instance->getLabel(), "Hidden label: label is not displayed.");
$this->assertNoRaw($this->fieldTestData->instance->getLabel(), "Hidden label: label is not displayed.");
// Field hidden.
$entity = clone($entity_init);
$display->removeComponent($this->field_name);
$display->removeComponent($this->fieldTestData->field_name);
$content = $display->build($entity);
$this->render($content);
$this->assertNoRaw($this->instance->getLabel(), "Hidden field: label is not displayed.");
$this->assertNoRaw($this->fieldTestData->instance->getLabel(), "Hidden field: label is not displayed.");
foreach ($values as $delta => $value) {
$this->assertNoRaw("$formatter_setting|{$value['value']}", "Hidden field: value $delta is not displayed.");
}
......@@ -110,7 +96,7 @@ function testEntityDisplayBuild() {
// Multiple formatter.
$entity = clone($entity_init);
$formatter_setting = $this->randomName();
$display->setComponent($this->field_name, array(
$display->setComponent($this->fieldTestData->field_name, array(
'label' => 'above',
'type' => 'field_test_multiple',
'settings' => array(
......@@ -128,7 +114,7 @@ function testEntityDisplayBuild() {
// Test a formatter that uses hook_field_formatter_prepare_view().
$entity = clone($entity_init);
$formatter_setting = $this->randomName();
$display->setComponent($this->field_name, array(
$display->setComponent($this->fieldTestData->field_name, array(
'label' => 'above',
'type' => 'field_test_with_prepare_view',
'settings' => array(
......@@ -152,21 +138,21 @@ function testEntityDisplayBuild() {
function testEntityDisplayViewMultiple() {
// Use a formatter that has a prepareView() step.
$display = entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($this->field_name, array(
->setComponent($this->fieldTestData->field_name, array(
'type' => 'field_test_with_prepare_view',
));
// Create two entities.
$entity1 = entity_create('entity_test', array('id' => 1, 'type' => 'entity_test'));
$entity1->{$this->field_name}->setValue($this->_generateTestFieldValues(1));
$entity1->{$this->fieldTestData->field_name}->setValue($this->_generateTestFieldValues(1));
$entity2 = entity_create('entity_test', array('id' => 2, 'type' => 'entity_test'));
$entity2->{$this->field_name}->setValue($this->_generateTestFieldValues(1));
$entity2->{$this->fieldTestData->field_name}->setValue($this->_generateTestFieldValues(1));
// Run buildMultiple(), and check that the entities come out as expected.
$display->buildMultiple(array($entity1, $entity2));
$item1 = $entity1->{$this->field_name}[0];
$item1 = $entity1->{$this->fieldTestData->field_name}[0];
$this->assertEqual($item1->additional_formatter_value, $item1->value + 1, 'Entity 1 ran through the prepareView() formatter method.');
$item2 = $entity2->{$this->field_name}[0];
$item2 = $entity2->{$this->fieldTestData->field_name}[0];
$this->assertEqual($item2->additional_formatter_value, $item2->value + 1, 'Entity 2 ran through the prepareView() formatter method.');
}
......@@ -178,8 +164,8 @@ function testEntityDisplayViewMultiple() {
*/
function testEntityCache() {
// Initialize random values and a test entity.
$entity_init = entity_create('entity_test', array('type' => $this->instance->bundle));
$values = $this->_generateTestFieldValues($this->field_storage->getCardinality());
$entity_init = entity_create('entity_test', array('type' => $this->fieldTestData->instance->bundle));
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
// Non-cacheable entity type.
$entity_type = 'entity_test';
......@@ -190,7 +176,7 @@ function testEntityCache() {
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name}->setValue($values);
$entity->{$this->fieldTestData->field_name}->setValue($values);
$entity = $this->entitySaveReload($entity);
$cid = "values:$entity_type:" . $entity->id();
$this->assertFalse(\Drupal::cache('entity')->get($cid), 'Non-cached: no cache entry on insert and load');
......@@ -209,7 +195,7 @@ function testEntityCache() {
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name_2} = $values;
$entity->{$this->fieldTestData->field_name_2} = $values;
$entity->save();
$cid = "values:$entity_type:" . $entity->id();
......@@ -222,8 +208,8 @@ function testEntityCache() {
$this->assertEqual($cache->data, $cached_entity, 'Cached: correct cache entry on load');
// Update with different values, and check that the cache entry is wiped.
$values = $this->_generateTestFieldValues($this->field_storage_2->getCardinality());
$entity->{$this->field_name_2} = $values;
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage_2->getCardinality());
$entity->{$this->fieldTestData->field_name_2} = $values;
$entity->save();
$this->assertFalse(\Drupal::cache('entity')->get($cid), 'Cached: no cache entry on update');
......@@ -234,8 +220,8 @@ function testEntityCache() {
$this->assertEqual($cache->data, $cached_entity, 'Cached: correct cache entry on load');
// Create a new revision, and check that the cache entry is wiped.
$values = $this->_generateTestFieldValues($this->field_storage_2->getCardinality());
$entity->{$this->field_name_2} = $values;
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage_2->getCardinality());
$entity->{$this->fieldTestData->field_name_2} = $values;
$entity->setNewRevision();
$entity->save();
$this->assertFalse(\Drupal::cache('entity')->get($cid), 'Cached: no cache entry on new revision creation');
......@@ -261,29 +247,29 @@ function testEntityFormDisplayBuildForm() {
$this->createFieldWithInstance('_2');
$entity_type = 'entity_test';
$entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance->bundle));
$entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->instance->bundle));
// Test generating widgets for all fields.
$display = entity_get_form_display($entity_type, $this->instance->bundle, 'default');
$display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'default');
$form = array();
$form_state = new FormState();
$display->buildForm($entity, $form, $form_state);
$this->assertEqual($form[$this->field_name]['widget']['#title'], $this->instance->getLabel(), "First field's form title is {$this->instance->getLabel()}");
$this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2->getLabel(), "Second field's form title is {$this->instance_2->getLabel()}");
for ($delta = 0; $delta < $this->field_storage->getCardinality(); $delta++) {
$this->assertEqual($form[$this->fieldTestData->field_name]['widget']['#title'], $this->fieldTestData->instance->getLabel(), "First field's form title is {$this->fieldTestData->instance->getLabel()}");
$this->assertEqual($form[$this->fieldTestData->field_name_2]['widget']['#title'], $this->fieldTestData->instance_2->getLabel(), "Second field's form title is {$this->fieldTestData->instance_2->getLabel()}");
for ($delta = 0; $delta < $this->fieldTestData->field_storage->getCardinality(); $delta++) {
// field_test_widget uses 'textfield'
$this->assertEqual($form[$this->field_name]['widget'][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield");
$this->assertEqual($form[$this->fieldTestData->field_name]['widget'][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield");
}
for ($delta = 0; $delta < $this->field_storage_2->getCardinality(); $delta++) {
for ($delta = 0; $delta < $this->fieldTestData->field_storage_2->getCardinality(); $delta++) {
// field_test_widget uses 'textfield'
$this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield");
$this->assertEqual($form[$this->fieldTestData->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield");
}
// Test generating widgets for all fields.
$display = entity_get_form_display($entity_type, $this->instance->bundle, 'default');
$display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'default');
foreach ($display->getComponents() as $name => $options) {
if ($name != $this->field_name_2) {
if ($name != $this->fieldTestData->field_name_2) {
$display->removeComponent($name);
}
}
......@@ -291,11 +277,11 @@ function testEntityFormDisplayBuildForm() {
$form_state = new FormState();
$display->buildForm($entity, $form, $form_state);
$this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form');
$this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2->getLabel(), "Second field's form title is {$this->instance_2->getLabel()}");
for ($delta = 0; $delta < $this->field_storage_2->getCardinality(); $delta++) {
$this->assertFalse(isset($form[$this->fieldTestData->field_name]), 'The first field does not exist in the form');
$this->assertEqual($form[$this->fieldTestData->field_name_2]['widget']['#title'], $this->fieldTestData->instance_2->getLabel(), "Second field's form title is {$this->fieldTestData->instance_2->getLabel()}");
for ($delta = 0; $delta < $this->fieldTestData->field_storage_2->getCardinality(); $delta++) {
// field_test_widget uses 'textfield'
$this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield");
$this->assertEqual($form[$this->fieldTestData->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield");
}
}
......@@ -306,10 +292,10 @@ function testEntityFormDisplayExtractFormValues() {
$this->createFieldWithInstance('_2');
$entity_type = 'entity_test';
$entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance->bundle));
$entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->instance->bundle));
// Build the form for all fields.
$display = entity_get_form_display($entity_type, $this->instance->bundle, 'default');
$display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'default');
$form = array();
$form_state = new FormState();
$display->buildForm($entity_init, $form, $form_state);
......@@ -318,11 +304,11 @@ function testEntityFormDisplayExtractFormValues() {
// First field.
$values = array();
$weights = array();
for ($delta = 0; $delta < $this->field_storage->getCardinality(); $delta++) {
for ($delta = 0; $delta < $this->fieldTestData->field_storage->getCardinality(); $delta++) {
$values[$delta]['value'] = mt_rand(1, 127);
// Assign random weight.
do {
$weight = mt_rand(0, $this->field_storage->getCardinality());
$weight = mt_rand(0, $this->fieldTestData->field_storage->getCardinality());
} while (in_array($weight, $weights));
$weights[$delta] = $weight;
$values[$delta]['_weight'] = $weight;
......@@ -332,11 +318,11 @@ function testEntityFormDisplayExtractFormValues() {
// Second field.
$values_2 = array();
$weights_2 = array();
for ($delta = 0; $delta < $this->field_storage_2->getCardinality(); $delta++) {
for ($delta = 0; $delta < $this->fieldTestData->field_storage_2->getCardinality(); $delta++) {
$values_2[$delta]['value'] = mt_rand(1, 127);
// Assign random weight.
do {
$weight = mt_rand(0, $this->field_storage_2->getCardinality());
$weight = mt_rand(0, $this->fieldTestData->field_storage_2->getCardinality());
} while (in_array($weight, $weights_2));
$weights_2[$delta] = $weight;
$values_2[$delta]['_weight'] = $weight;
......@@ -348,8 +334,8 @@ function testEntityFormDisplayExtractFormValues() {
$form_state['build_info']['callback_object'] = \Drupal::entityManager()->getFormObject($entity_type, 'default');
\Drupal::formBuilder()->prepareForm('field_test_entity_form', $form, $form_state);
drupal_process_form('field_test_entity_form', $form, $form_state);
$form_state['values'][$this->field_name] = $values;
$form_state['values'][$this->field_name_2] = $values_2;
$form_state['values'][$this->fieldTestData->field_name] = $values;
$form_state['values'][$this->fieldTestData->field_name_2] = $values_2;
// Extract values for all fields.
$entity = clone($entity_init);
......@@ -364,17 +350,17 @@ function testEntityFormDisplayExtractFormValues() {
$expected_values[] = array('value' => $values[$key]['value']);
}
}
$this->assertIdentical($entity->{$this->field_name}->getValue(), $expected_values, 'Submit filters empty values');
$this->assertIdentical($entity->{$this->fieldTestData->field_name}->getValue(), $expected_values, 'Submit filters empty values');
foreach ($weights_2 as $key => $value) {
if ($key != 1) {
$expected_values_2[] = array('value' => $values_2[$key]['value']);
}
}
$this->assertIdentical($entity->{$this->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values');
$this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values');
// Call EntityFormDisplayInterface::extractFormValues() for a single field (the second field).
foreach ($display->getComponents() as $name => $options) {
if ($name != $this->field_name_2) {
if ($name != $this->fieldTestData->field_name_2) {
$display->removeComponent($name);
}
}
......@@ -386,8 +372,8 @@ function testEntityFormDisplayExtractFormValues() {
$expected_values_2[] = array('value' => $values_2[$key]['value']);
}
}
$this->assertTrue($entity->{$this->field_name}->isEmpty(), 'The first field is empty in the entity object');
$this->assertIdentical($entity->{$this->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values');
$this->assertTrue($entity->{$this->fieldTestData->field_name}->isEmpty(), 'The first field is empty in the entity object');
$this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values');
}
}
......@@ -16,20 +16,6 @@
*/
class FieldAttachStorageTest extends FieldUnitTestBase {
/**
* The field instance.
*
* @var \Drupal\field\Entity\FieldInstanceConfig
*/
protected $instance;
/**