You are here

protected function WebTestBase::translatePostValues in Drupal 8

Transforms a nested array into a flat array suitable for WebTestBase::drupalPostForm().

Parameters

array $values: A multi-dimensional form values array to convert.

Return value

array The flattened $edit array suitable for WebTestBase::drupalPostForm().

2 calls to WebTestBase::translatePostValues()
InstallerTestBase::setUpSettings in core/modules/simpletest/src/InstallerTestBase.php
Installer step: Configure settings.
InstallerTestBase::setUpSite in core/modules/simpletest/src/InstallerTestBase.php
Final installer step: Configure site.

File

core/modules/simpletest/src/WebTestBase.php, line 1450

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function translatePostValues(array $values) {
  $edit = [];

  // The easiest and most straightforward way to translate values suitable for
  // WebTestBase::drupalPostForm() is to actually build the POST data string
  // and convert the resulting key/value pairs back into a flat array.
  $query = http_build_query($values);
  foreach (explode('&', $query) as $item) {
    list($key, $value) = explode('=', $item);
    $edit[urldecode($key)] = urldecode($value);
  }
  return $edit;
}