You are here

class UriItemTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/Uri/UriItemTest.php \Drupal\Tests\field\Kernel\Uri\UriItemTest
  2. 9 core/modules/field/tests/src/Kernel/Uri/UriItemTest.php \Drupal\Tests\field\Kernel\Uri\UriItemTest

Tests URI field functionality.

@group field

Hierarchy

  • class \Drupal\Tests\field\Kernel\Uri\UriItemTest extends \Drupal\Tests\field\Kernel\FieldKernelTestBase

Expanded class hierarchy of UriItemTest

See also

\Drupal\Core\Field\Plugin\Field\FieldType\UriItem

File

core/modules/field/tests/src/Kernel/Uri/UriItemTest.php, line 17

Namespace

Drupal\Tests\field\Kernel\Uri
View source
class UriItemTest extends FieldKernelTestBase {

  /**
   * A field to use in this test class.
   *
   * @var \Drupal\field\Entity\FieldStorageConfig
   */
  protected $fieldStorage;

  /**
   * The field used in this test class.
   *
   * @var \Drupal\field\Entity\FieldConfig
   */
  protected $field;

  /**
   * Tests URI field.
   */
  public function testUriField() {
    $label = $this
      ->randomMachineName();

    // Create a field with settings to validate.
    $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();

    // 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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UriItemTest::$field protected property The field used in this test class.
UriItemTest::$fieldStorage protected property A field to use in this test class.
UriItemTest::testUriField public function Tests URI field.