function UriItemTest::testUriField
Same name in other branches
- 9 core/modules/field/tests/src/Kernel/Uri/UriItemTest.php \Drupal\Tests\field\Kernel\Uri\UriItemTest::testUriField()
- 8.9.x core/modules/field/tests/src/Kernel/Uri/UriItemTest.php \Drupal\Tests\field\Kernel\Uri\UriItemTest::testUriField()
- 11.x core/modules/field/tests/src/Kernel/Uri/UriItemTest.php \Drupal\Tests\field\Kernel\Uri\UriItemTest::testUriField()
Tests URI field.
File
-
core/
modules/ field/ tests/ src/ Kernel/ Uri/ UriItemTest.php, line 38
Class
- UriItemTest
- Tests URI field functionality.
Namespace
Drupal\Tests\field\Kernel\UriCode
public function testUriField() : void {
$label = $this->randomMachineName();
// Create a field with settings to validate.
$field_name = $this->randomMachineName();
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'uri',
]);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $label,
'required' => TRUE,
'settings' => [
'size' => 123,
'placeholder' => '',
],
]);
$this->field
->save();
// Create a form display for the default form mode.
\Drupal::service('entity_display.repository')->getFormDisplay('entity_test', 'entity_test')
->setComponent($field_name, [
'type' => 'uri',
])
->save();
// Test the generateSampleValue() method.
$entity = EntityTest::create();
$entity->{$field_name}
->generateSampleItems();
$this->entityValidateAndSave($entity);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.