You are here

public function SelectOtherInstallTestScript::setup in CCK Select Other 8

Run the code to setup the test environment.

You have access to any API provided by any installed module. For example, to install modules use:

\Drupal::service('module_installer')
  ->install([
  'my_module',
]);

Check out TestSiteInstallTestScript for an example.

Overrides TestSetupInterface::setup

See also

\Drupal\TestSite\TestSiteInstallTestScript

File

tests/src/TestSite/SelectOtherInstallTestScript.php, line 41

Class

SelectOtherInstallTestScript
Setup file used for cck_select_other Nightwatch tests.

Namespace

Drupal\Tests\cck_select_other\TestSite

Code

public function setup() {
  \Drupal::service('module_installer')
    ->install($this->modules);
  $typeId = $this
    ->createContentType([
    'type' => 'page',
    'name' => 'Basic page',
  ]);
  $options = $this
    ->createOptions();
  list($default_value, $label) = $this
    ->getRandomOption($options);
  $storage_values = [
    'field_name' => 'field_random_choice',
    'settings' => [
      'allowed_values' => $options,
    ],
    'cardinality' => 1,
  ];
  $config_values = [
    'field_name' => 'field_random_choice',
    'label' => 'Random choice',
    'required' => 0,
    'default_value' => [
      [
        'value' => $default_value,
      ],
    ],
  ];
  $this
    ->createSelectOtherListField('node', $typeId, 'list_string', $storage_values, $config_values);

  // Delete cache.
  \Drupal::cache()
    ->deleteAll();
}