protected function OfficeHoursItemTest::setUp in Office Hours 8
Set the default field storage backend for fields created during tests.
Overrides FieldKernelTestBase::setUp
File
- tests/
src/ Kernel/ OfficeHoursItemTest.php, line 45
Class
- OfficeHoursItemTest
- Class that tests OfficeHoursField.
Namespace
Drupal\Tests\office_hours\KernelCode
protected function setUp() : void {
parent::setUp();
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_office_hours',
'type' => 'office_hours',
'entity_type' => 'entity_test',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'element_type' => 'office_hours_datelist',
],
]);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
'settings' => [
// @todo Test all settings.
'cardinality_per_day' => 2,
],
'default_value' => [
[
'day' => 0,
'starthours' => 900,
'endhours' => 1730,
'comment' => 'Test comment',
],
[
'day' => 1,
'starthours' => 700,
'endhours' => 1800,
'comment' => 'Test comment',
],
],
]);
$this->field
->save();
/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $entity_display */
$entity_display = EntityViewDisplay::create([
'targetEntityType' => $this->field
->getTargetEntityTypeId(),
'bundle' => $this->field
->getTargetBundle(),
'mode' => 'default',
]);
// Save the office hours field to check if the config schema is valid.
// @todo D9 test
// Table formatter.
$entity_display
->setComponent('field_office_hours', [
'type' => 'office_hours_table',
]);
$entity_display
->save();
// Default formatter.
$entity_display
->setComponent('field_office_hours', [
'type' => 'office_hours',
]);
$entity_display
->save();
}