public function UriItemTest::testUriField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/Uri/UriItemTest.php \Drupal\field\Tests\Uri\UriItemTest::testUriField()
Tests URI field.
File
- core/
modules/ field/ src/ Tests/ Uri/ UriItemTest.php, line 41 - Contains \Drupal\field\Tests\Uri\UriItemTest.
Class
- UriItemTest
- Tests URI field functionality.
Namespace
Drupal\field\Tests\UriCode
public function testUriField() {
$label = $this
->randomMachineName();
// Create a field with settings to validate.
$field_name = Unicode::strtolower($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.
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, [
'type' => 'uri',
])
->save();
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity->{$field_name}
->generateSampleItems();
$this
->entityValidateAndSave($entity);
}