public function WidgetTest::testFieldWidget in Range 8
Tests widget.
File
- tests/
src/ Kernel/ Widget/ WidgetTest.php, line 62
Class
- WidgetTest
- Tests field widget.
Namespace
Drupal\Tests\range\Kernel\WidgetCode
public function testFieldWidget() {
foreach ($this
->getRangeFieldTypes() as $this->fieldType) {
// Create field and set form display.
$this->fieldName = $this
->getFieldName($this->fieldType);
$this
->createField($this->fieldType);
$this
->createFormDisplay();
$widget_settings = $this
->getWidgetSettings();
$this
->setFormDisplayComponent($this->fieldType, $widget_settings);
// Test field widget.
$entity = EntityTest::create([]);
$content = $this
->renderEntityForm($entity);
$this
->assertFieldByXPath($this
->constructRangeFieldXpath('from'));
$this
->assertFieldByXPath($this
->constructRangeFieldXpath('to'));
$field_settings = $this
->getFieldSettings($this->fieldType);
$this
->assertStringContainsString($widget_settings['label']['from'], $content);
$this
->assertStringContainsString($widget_settings['label']['to'], $content);
$this
->assertStringContainsString($field_settings['field']['prefix'] . $field_settings['from']['prefix'], $content);
$this
->assertStringContainsString($field_settings['from']['suffix'], $content);
$this
->assertStringContainsString($field_settings['to']['prefix'], $content);
$this
->assertStringContainsString($field_settings['to']['suffix'] . $field_settings['field']['suffix'], $content);
// Delete field.
$this
->deleteField();
}
}