You are here

protected function OptionsWidgetsTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 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 57

Class

OptionsWidgetsTest
Tests the Options widgets.

Namespace

Drupal\Tests\options\Functional

Code

protected function setUp() {
  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 &lt; &amp; &gt;',
      ],
    ],
  ]);
  $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',
  ]));
}