function DateRangeFieldTest::testDateStorageSettings
Same name in other branches
- 9 core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php \Drupal\Tests\datetime_range\Functional\DateRangeFieldTest::testDateStorageSettings()
- 8.9.x core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php \Drupal\Tests\datetime_range\Functional\DateRangeFieldTest::testDateStorageSettings()
- 10 core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php \Drupal\Tests\datetime_range\Functional\DateRangeFieldTest::testDateStorageSettings()
Tests that 'Date' field storage setting form is disabled if field has data.
File
-
core/
modules/ datetime_range/ tests/ src/ Functional/ DateRangeFieldTest.php, line 1375
Class
- DateRangeFieldTest
- Tests Daterange field functionality.
Namespace
Drupal\Tests\datetime_range\FunctionalCode
public function testDateStorageSettings() : void {
// Create a test content type.
$this->drupalCreateContentType([
'type' => 'date_content',
]);
// Create a field storage with settings to validate.
$field_name = $this->randomMachineName();
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'daterange',
'settings' => [
'datetime_type' => DateRangeItem::DATETIME_TYPE_DATE,
],
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'field_name' => $field_name,
'bundle' => 'date_content',
]);
$field->save();
\Drupal::service('entity_display.repository')->getFormDisplay('node', 'date_content')
->setComponent($field_name, [
'type' => 'datetime_default',
])
->save();
$edit = [
'title[0][value]' => $this->randomString(),
'body[0][value]' => $this->randomString(),
$field_name . '[0][value][date]' => '2016-04-01',
$field_name . '[0][end_value][date]' => '2016-04-02',
];
$this->drupalGet('node/add/date_content');
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name);
$this->assertSession()
->elementsCount('xpath', "//*[@name='field_storage[subform][settings][datetime_type]' and contains(@disabled, 'disabled')]", 1);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.