3 namespace Drupal\Tests\field\Kernel\Uri;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\Tests\field\Kernel\FieldKernelTestBase;
11 * Tests URI field functionality.
13 * @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem
17 class UriItemTest extends FieldKernelTestBase {
20 * A field to use in this test class.
22 * @var \Drupal\field\Entity\FieldStorageConfig
24 protected $fieldStorage;
27 * The field used in this test class.
29 * @var \Drupal\field\Entity\FieldConfig
36 public function testUriField() {
37 $label = $this->randomMachineName();
39 // Create a field with settings to validate.
40 $field_name = mb_strtolower($this->randomMachineName());
41 $this->fieldStorage = FieldStorageConfig::create([
42 'field_name' => $field_name,
43 'entity_type' => 'entity_test',
46 $this->fieldStorage->save();
47 $this->field = FieldConfig::create([
48 'field_name' => $field_name,
49 'entity_type' => 'entity_test',
50 'bundle' => 'entity_test',
60 // Create a form display for the default form mode.
61 entity_get_form_display('entity_test', 'entity_test', 'default')
62 ->setComponent($field_name, [
67 // Test the generateSampleValue() method.
68 $entity = EntityTest::create();
69 $entity->$field_name->generateSampleItems();
70 $this->entityValidateAndSave($entity);