You are here

protected function ConditionalFieldDateTimeTest::setUp in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldDateTimeTest::setUp()

Overrides ConditionalFieldTestBase::setUp

File

tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php, line 51

Class

ConditionalFieldDateTimeTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $this->fieldSelector = "[name=\"{$this->fieldName}[0][value][date]\"]";
  $fieldStorageDefinition = [
    'field_name' => $this->fieldName,
    'entity_type' => 'node',
    'type' => 'datetime',
    'settings' => [
      'datetime_type' => 'date',
    ],
  ];
  $fieldStorage = FieldStorageConfig::create($fieldStorageDefinition);
  $fieldStorage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $fieldStorage,
    'bundle' => 'article',
  ]);
  $field
    ->save();
  EntityFormDisplay::load('node.article.default')
    ->setComponent($this->fieldName, [
    'type' => 'datetime_default',
  ])
    ->save();
  $defaultSettings = [
    'timezone_override' => '',
  ];
  $this->displayOptions = [
    'type' => 'datetime_default',
    'label' => 'hidden',
    'settings' => [
      'format_type' => 'medium',
    ] + $defaultSettings,
  ];
  $view_display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load($field
    ->getTargetEntityTypeId() . '.' . $field
    ->getTargetBundle() . '.' . 'full');
  if (!$view_display) {
    $view_display = EntityViewDisplay::create([
      'targetEntityType' => $field
        ->getTargetEntityTypeId(),
      'bundle' => $field
        ->getTargetBundle(),
      'mode' => 'full',
      'status' => TRUE,
    ]);
  }
  if ($view_display instanceof EntityDisplayInterface) {
    $view_display
      ->setComponent($this->fieldName, $this->displayOptions)
      ->save();
  }
}