OptionsFieldUnitTestBase.php in Drupal 10
File
core/modules/options/tests/src/Kernel/OptionsFieldUnitTestBase.php
View source
<?php
namespace Drupal\Tests\options\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase {
protected static $modules = [
'options',
];
protected $fieldName = 'test_options';
protected $fieldStorageDefinition;
protected $fieldStorage;
protected $field;
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();
}
}