function DateRangeFieldTest::testFromToSeparatorState
Same name in other branches
- 10 core/modules/datetime_range/tests/src/FunctionalJavascript/DateRangeFieldTest.php \Drupal\Tests\datetime_range\FunctionalJavascript\DateRangeFieldTest::testFromToSeparatorState()
Tests the conditional visibility of the 'Date separator' field.
File
-
core/
modules/ datetime_range/ tests/ src/ FunctionalJavascript/ DateRangeFieldTest.php, line 50
Class
- DateRangeFieldTest
- Tests Daterange field.
Namespace
Drupal\Tests\datetime_range\FunctionalJavascriptCode
public function testFromToSeparatorState() : void {
$field_name = $this->randomMachineName();
$this->drupalCreateContentType([
'type' => 'date_content',
]);
$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,
'bundle' => 'date_content',
]);
$field->save();
\Drupal::service('entity_display.repository')->getViewDisplay('node', 'date_content')
->setComponent($field_name, [
'type' => 'daterange_default',
'label' => 'hidden',
'settings' => [
'format_type' => 'short',
'separator' => 'THE_SEPARATOR',
],
])
->save();
$this->drupalGet("admin/structure/types/manage/date_content/display");
$page = $this->getSession()
->getPage();
$page->pressButton("{$field_name}_settings_edit");
$this->assertSession()
->waitForElement('css', '.ajax-new-content');
$from_to_locator = 'fields[' . $field_name . '][settings_edit_form][settings][from_to]';
$separator = $page->findField('Date separator');
// Assert that date separator field is visible if 'from_to' is set to
// BOTH.
$this->assertSession()
->fieldValueEquals($from_to_locator, DateTimeRangeConstantsInterface::BOTH);
$this->assertTrue($separator->isVisible());
// Assert that the date separator is not visible if 'from_to' is set to
// START_DATE or END_DATE.
$page->selectFieldOption($from_to_locator, DateTimeRangeConstantsInterface::START_DATE);
$this->assertFalse($separator->isVisible());
$page->selectFieldOption($from_to_locator, DateTimeRangeConstantsInterface::END_DATE);
$this->assertFalse($separator->isVisible());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.