$display_repository = \Drupal::
service('entity_display.repository'
);
// Change the widget to a datelist widget.
$display_repository->
getFormDisplay($this->field->
getTargetEntityTypeId(),
$this->field->
getTargetBundle()) ->
setComponent($field_name,
[ 'type' => 'daterange_datelist',
'settings' =>
[ 'date_order' => 'YMD',
],
]) ->
save();
\Drupal::
service('entity_field.manager'
)->
clearCachedFieldDefinitions();
// Display creation form.
$this->
drupalGet('entity_test/add'
);
$this->
assertSession()->
elementTextContains('xpath', '//fieldset[@id="edit-' .
$field_name . '-0"]/legend',
$field_label);
$this->
assertSession()->
elementExists('xpath', '//fieldset[@aria-describedby="edit-' .
$field_name . '-0--description"]'
);
$this->
assertSession()->
elementExists('xpath', '//div[@id="edit-' .
$field_name . '-0--description"]'
);
// Assert that Hour and Minute Elements do not appear on Date Only.
$this->
assertSession()->
elementNotExists('xpath', "//*[@id=\"edit-
$field_name-0-value-hour\"]"
);
$this->
assertSession()->
elementNotExists('xpath', "//*[@id=\"edit-
$field_name-0-value-minute\"]"
);
$this->
assertSession()->
elementNotExists('xpath', "//*[@id=\"edit-
$field_name-0-end-value-hour\"]"
);