protected function SerialFieldTest::setUp in Serial Field 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ SerialFieldTest.php, line 69
Class
- SerialFieldTest
- Tests the creation of serial fields.
Namespace
Drupal\Tests\serial\FunctionalCode
protected function setUp() {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'access content',
'view test entity',
'administer entity_test content',
'administer entity_test form display',
'administer content types',
'administer node fields',
]);
$this
->drupalLogin($this->webUser);
$field_name = 'field_serial';
$type = 'serial';
$widget_type = 'serial_default_widget';
$formatter_type = 'serial_default_formatter';
// Add the serial field to the entity test.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $type,
'settings' => [
'start_value' => 1,
'init_existing_entities' => FALSE,
],
]);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'label' => 'Serial',
'bundle' => 'entity_test',
'required' => TRUE,
]);
$this->field
->save();
EntityFormDisplay::load('entity_test.entity_test.default')
->setComponent($field_name, [
'type' => $widget_type,
])
->save();
$this->displayOptions = [
'type' => $formatter_type,
'label' => 'hidden',
];
EntityViewDisplay::create([
'targetEntityType' => $this->field
->getTargetEntityTypeId(),
'bundle' => $this->field
->getTargetBundle(),
'mode' => 'full',
'status' => TRUE,
])
->setComponent($field_name, $this->displayOptions)
->save();
}