You are here

protected function OptionsWidgetsTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/options/src/Tests/OptionsWidgetsTest.php \Drupal\options\Tests\OptionsWidgetsTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides WebTestBase::setUp

File

core/modules/options/src/Tests/OptionsWidgetsTest.php, line 41
Contains \Drupal\options\Tests\OptionsWidgetsTest.

Class

OptionsWidgetsTest
Tests the Options widgets.

Namespace

Drupal\options\Tests

Code

protected function setUp() {
  parent::setUp();

  // Field storage with cardinality 1.
  $this->card1 = entity_create('field_storage_config', [
    '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 = entity_create('field_storage_config', [
    '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();

  // Create a web user.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'view test entity',
    'administer entity_test content',
  ]));
}