class OptionsDynamicValuesTestBase
Same name and namespace in other branches
- 11.x core/modules/options/tests/src/Functional/OptionsDynamicValuesTestBase.php \Drupal\Tests\options\Functional\OptionsDynamicValuesTestBase
Base class for testing allowed values of options fields.
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\field\Functional\FieldTestBase implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\options\Functional\OptionsDynamicValuesTestBase implements \Drupal\Tests\field\Functional\FieldTestBase
- class \Drupal\Tests\field\Functional\FieldTestBase implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of OptionsDynamicValuesTestBase
File
-
core/
modules/ options/ tests/ src/ Functional/ OptionsDynamicValuesTestBase.php, line 13
Namespace
Drupal\Tests\options\FunctionalView source
abstract class OptionsDynamicValuesTestBase extends FieldTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'options',
'entity_test',
'options_test',
];
/**
* The created entity.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $entity;
/**
* The field storage.
*
* @var \Drupal\Core\Field\FieldStorageDefinitionInterface
*/
protected $fieldStorage;
/**
* @var int
*/
protected $field;
/**
* Test data.
*
* @var array
*/
protected $test;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$field_name = 'test_options';
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test_rev',
'type' => 'list_string',
'cardinality' => 1,
'settings' => [
'allowed_values_function' => 'options_test_dynamic_values_callback',
],
]);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_name' => $field_name,
'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($field_name, [
'type' => 'options_select',
])
->save();
// Create an entity and prepare test data that will be used by
// options_test_dynamic_values_callback().
$values = [
'user_id' => mt_rand(1, 10),
'name' => $this->randomMachineName(),
];
$this->entity = EntityTestRev::create($values);
$this->entity
->save();
$this->test = [
'label' => $this->entity
->label(),
'uuid' => $this->entity
->uuid(),
'bundle' => $this->entity
->bundle(),
'uri' => $this->entity
->toUrl()
->toString(),
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.