function OptionsDynamicValuesApiTest::setUp

Same name in other branches
  1. 11.x core/modules/options/tests/src/Kernel/OptionsDynamicValuesApiTest.php \Drupal\Tests\options\Kernel\OptionsDynamicValuesApiTest::setUp()

Overrides OptionsFieldUnitTestBase::setUp

File

core/modules/options/tests/src/Kernel/OptionsDynamicValuesApiTest.php, line 36

Class

OptionsDynamicValuesApiTest
Tests the options allowed values api.

Namespace

Drupal\Tests\options\Kernel

Code

protected function setUp() : void {
    parent::setUp();
    $this->installEntitySchema('entity_test_rev');
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->fieldStorage = FieldStorageConfig::create([
        'field_name' => 'test_options',
        'entity_type' => 'entity_test_rev',
        'type' => 'list_string',
        'cardinality' => 1,
        'settings' => [
            'allowed_values_function' => 'options_test_dynamic_values_callback',
        ],
    ]);
    $this->fieldStorage
        ->save();
    FieldConfig::create([
        'field_name' => 'test_options',
        'entity_type' => 'entity_test_rev',
        'bundle' => 'entity_test_rev',
        'required' => TRUE,
    ])->save();
    \Drupal::service('entity_display.repository')->getFormDisplay('entity_test_rev', 'entity_test_rev')
        ->setComponent('test_options', [
        'type' => 'options_select',
    ])
        ->save();
    // Create an entity and prepare test data that will be used by
    // options_test_dynamic_values_callback().
    $values = [
        'user_id' => 2,
        'name' => $this->randomMachineName(),
    ];
    $this->entity = EntityTestRev::create($values);
    $this->entity
        ->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.