protected function DisplayApiTest::setUp in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/DisplayApiTest.php \Drupal\field\Tests\DisplayApiTest::setUp()
Set the default field storage backend for fields created during tests.
Overrides FieldUnitTestBase::setUp
File
- core/
modules/ field/ src/ Tests/ DisplayApiTest.php, line 61 - Contains \Drupal\field\Tests\DisplayApiTest.
Class
- DisplayApiTest
- Tests the field display API.
Namespace
Drupal\field\TestsCode
protected function setUp() {
parent::setUp();
// Create a field and its storage.
$this->fieldName = 'test_field';
$this->label = $this
->randomMachineName();
$this->cardinality = 4;
$field_storage = array(
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'test_field',
'cardinality' => $this->cardinality,
);
$field = array(
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $this->label,
);
$this->displayOptions = array(
'default' => array(
'type' => 'field_test_default',
'settings' => array(
'test_formatter_setting' => $this
->randomMachineName(),
),
),
'teaser' => array(
'type' => 'field_test_default',
'settings' => array(
'test_formatter_setting' => $this
->randomMachineName(),
),
),
);
entity_create('field_storage_config', $field_storage)
->save();
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->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->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->fieldName}
->setValue($this->values);
$this->entity
->save();
}