UriItemTest.php in Drupal 10
File
core/modules/field/tests/src/Kernel/Uri/UriItemTest.php
View source
<?php
namespace Drupal\Tests\field\Kernel\Uri;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
class UriItemTest extends FieldKernelTestBase {
protected $fieldStorage;
protected $field;
public function testUriField() {
$label = $this
->randomMachineName();
$field_name = mb_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();
\Drupal::service('entity_display.repository')
->getFormDisplay('entity_test', 'entity_test')
->setComponent($field_name, [
'type' => 'uri',
])
->save();
$entity = EntityTest::create();
$entity->{$field_name}
->generateSampleItems();
$this
->entityValidateAndSave($entity);
}
}