3 namespace Drupal\Tests\options\Functional;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\entity_test\Entity\EntityTestRev;
8 use Drupal\Tests\field\Functional\FieldTestBase;
11 * Base class for testing allowed values of options fields.
13 abstract class OptionsDynamicValuesTestBase extends FieldTestBase {
20 public static $modules = ['options', 'entity_test', 'options_test'];
25 * @var \Drupal\Core\Entity\Entity
32 * @var \Drupal\Core\Field\FieldStorageDefinitionInterface
34 protected $fieldStorage;
36 protected function setUp() {
39 $field_name = 'test_options';
40 $this->fieldStorage = FieldStorageConfig::create([
41 'field_name' => $field_name,
42 'entity_type' => 'entity_test_rev',
43 'type' => 'list_string',
46 'allowed_values_function' => 'options_test_dynamic_values_callback',
49 $this->fieldStorage->save();
51 $this->field = FieldConfig::create([
52 'field_name' => $field_name,
53 'entity_type' => 'entity_test_rev',
54 'bundle' => 'entity_test_rev',
57 entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')
58 ->setComponent($field_name, [
59 'type' => 'options_select',
63 // Create an entity and prepare test data that will be used by
64 // options_test_dynamic_values_callback().
66 'user_id' => mt_rand(1, 10),
67 'name' => $this->randomMachineName(),
69 $this->entity = EntityTestRev::create($values);
70 $this->entity->save();
72 'label' => $this->entity->label(),
73 'uuid' => $this->entity->uuid(),
74 'bundle' => $this->entity->bundle(),
75 'uri' => $this->entity->url(),