function OptionsWidgetsTest::setUp
Same name in other branches
- 9 core/modules/options/tests/src/Functional/OptionsWidgetsTest.php \Drupal\Tests\options\Functional\OptionsWidgetsTest::setUp()
- 8.9.x core/modules/options/tests/src/Functional/OptionsWidgetsTest.php \Drupal\Tests\options\Functional\OptionsWidgetsTest::setUp()
- 10 core/modules/options/tests/src/Functional/OptionsWidgetsTest.php \Drupal\Tests\options\Functional\OptionsWidgetsTest::setUp()
Overrides BrowserTestBase::setUp
File
-
core/
modules/ options/ tests/ src/ Functional/ OptionsWidgetsTest.php, line 60
Class
- OptionsWidgetsTest
- Tests the Options widgets.
Namespace
Drupal\Tests\options\FunctionalCode
protected function setUp() : void {
parent::setUp();
// Field storage with cardinality 1.
$this->card1 = FieldStorageConfig::create([
'field_name' => 'card_1',
'entity_type' => 'entity_test',
'type' => 'list_integer',
'cardinality' => 1,
'settings' => [
'allowed_values' => [
// Make sure that 0 works as an option.
0 => 'Zero',
1 => 'One',
// Make sure that option text is properly sanitized.
2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
// Make sure that HTML entities in option text are not double-encoded.
3 => 'Some HTML encoded markup with < & >',
],
],
]);
$this->card1
->save();
// Field storage with cardinality 2.
$this->card2 = FieldStorageConfig::create([
'field_name' => 'card_2',
'entity_type' => 'entity_test',
'type' => 'list_integer',
'cardinality' => 2,
'settings' => [
'allowed_values' => [
// Make sure that 0 works as an option.
0 => 'Zero',
1 => 'One',
// Make sure that option text is properly sanitized.
2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
],
],
]);
$this->card2
->save();
// Field storage with list of float values.
$this->float = FieldStorageConfig::create([
'field_name' => 'float',
'entity_type' => 'entity_test',
'type' => 'list_float',
'cardinality' => 1,
'settings' => [
'allowed_values' => [
'0.0' => '0.0',
'1.5' => '1.5',
'2.0' => '2.0',
],
],
]);
$this->float
->save();
// Create a web user.
$this->drupalLogin($this->drupalCreateUser([
'view test entity',
'administer entity_test content',
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.