You are here

protected function OptionsDynamicValuesTestBase::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/options/src/Tests/OptionsDynamicValuesTestBase.php \Drupal\options\Tests\OptionsDynamicValuesTestBase::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/OptionsDynamicValuesTestBase.php, line 38
Contains \Drupal\options\Tests\OptionsDynamicValuesTestBase.

Class

OptionsDynamicValuesTestBase
Base class for testing allowed values of options fields.

Namespace

Drupal\options\Tests

Code

protected function setUp() {
  parent::setUp();
  $field_name = 'test_options';
  $this->fieldStorage = entity_create('field_storage_config', [
    '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 = entity_create('field_config', [
    'field_name' => $field_name,
    'entity_type' => 'entity_test_rev',
    'bundle' => 'entity_test_rev',
    'required' => TRUE,
  ])
    ->save();
  entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')
    ->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 = entity_create('entity_test_rev', $values);
  $this->entity
    ->save();
  $this->test = [
    'label' => $this->entity
      ->label(),
    'uuid' => $this->entity
      ->uuid(),
    'bundle' => $this->entity
      ->bundle(),
    'uri' => $this->entity
      ->url(),
  ];
}