protected function DateTimeDayItemTest::setUp in Date time day 8
Set the default field storage backend for fields created during tests.
Overrides FieldKernelTestBase::setUp
File
- tests/
src/ Kernel/ DateTimeDayItemTest.php, line 45
Class
- DateTimeDayItemTest
- Test date_time_day field type via API.
Namespace
Drupal\Tests\date_time_day\KernelCode
protected function setUp() {
parent::setUp();
// Add a date_time_day field.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => mb_strtolower($this
->randomMachineName()),
'entity_type' => 'entity_test',
'type' => 'datetimeday',
'settings' => [
'datetime_type' => DateTimeItem::DATETIME_TYPE_DATE,
'time_type' => DateTimeDayItem::DATEDAY_TIME_DEFAULT_TYPE_FORMAT,
],
]);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
'required' => TRUE,
]);
$this->field
->save();
$display_options = [
'type' => 'datetimeday_default',
'label' => 'hidden',
'settings' => [
'format_type' => 'fallback',
'time_format_type' => 'fallback',
'day_separator' => 'UNTRANSLATED',
'time_separator' => 'UNTRANSLATED',
],
];
EntityViewDisplay::create([
'targetEntityType' => $this->field
->getTargetEntityTypeId(),
'bundle' => $this->field
->getTargetBundle(),
'mode' => 'default',
'status' => TRUE,
])
->setComponent($this->fieldStorage
->getName(), $display_options)
->save();
}