3 namespace Drupal\Tests\field\Kernel\Uri;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\entity_test\Entity\EntityTest;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\Tests\field\Kernel\FieldKernelTestBase;
12 * Tests URI field functionality.
14 * @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem
18 class UriItemTest extends FieldKernelTestBase {
21 * A field to use in this test class.
23 * @var \Drupal\field\Entity\FieldStorageConfig
25 protected $fieldStorage;
28 * The field used in this test class.
30 * @var \Drupal\field\Entity\FieldConfig
37 public function testUriField() {
38 $label = $this->randomMachineName();
40 // Create a field with settings to validate.
41 $field_name = Unicode::strtolower($this->randomMachineName());
42 $this->fieldStorage = FieldStorageConfig::create([
43 'field_name' => $field_name,
44 'entity_type' => 'entity_test',
47 $this->fieldStorage->save();
48 $this->field = FieldConfig::create([
49 'field_name' => $field_name,
50 'entity_type' => 'entity_test',
51 'bundle' => 'entity_test',
61 // Create a form display for the default form mode.
62 entity_get_form_display('entity_test', 'entity_test', 'default')
63 ->setComponent($field_name, [
68 // Test the generateSampleValue() method.
69 $entity = EntityTest::create();
70 $entity->$field_name->generateSampleItems();
71 $this->entityValidateAndSave($entity);