You are here

abstract class OptionsFieldUnitTestBase in Drupal 10

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

Base class for Options module integration tests.

Hierarchy

Expanded class hierarchy of OptionsFieldUnitTestBase

File

core/modules/options/tests/src/Kernel/OptionsFieldUnitTestBase.php, line 12

Namespace

Drupal\Tests\options\Kernel
View source
abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'options',
  ];

  /**
   * The field name used in the test.
   *
   * @var string
   */
  protected $fieldName = 'test_options';

  /**
   * The field storage definition used to created the field storage.
   *
   * @var array
   */
  protected $fieldStorageDefinition;

  /**
   * The list field storage used in the test.
   *
   * @var \Drupal\field\Entity\FieldStorageConfig
   */
  protected $fieldStorage;

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

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->fieldStorageDefinition = [
      'field_name' => $this->fieldName,
      'entity_type' => 'entity_test',
      'type' => 'list_integer',
      'cardinality' => 1,
      'settings' => [
        'allowed_values' => [
          1 => 'One',
          2 => 'Two',
          3 => 'Three',
        ],
      ],
    ];
    $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
    $this->fieldStorage
      ->save();
    $this->field = FieldConfig::create([
      'field_storage' => $this->fieldStorage,
      'bundle' => 'entity_test',
    ]);
    $this->field
      ->save();
    \Drupal::service('entity_display.repository')
      ->getFormDisplay('entity_test', 'entity_test')
      ->setComponent($this->fieldName, [
      'type' => 'options_buttons',
    ])
      ->save();
  }

}

Members