function BrowserTestBase::translatePostValues

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::translatePostValues()
  2. 10 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::translatePostValues()
  3. 8.9.x core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::translatePostValues()

Transforms a nested array into a flat array suitable for submitForm().

Parameters

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

Return value

array The flattened $edit array suitable for BrowserTestBase::submitForm().

1 call to BrowserTestBase::translatePostValues()
SettingsTest::testCredentialForm in core/modules/migrate_drupal_ui/tests/src/FunctionalJavascript/SettingsTest.php
Test the Credential form with defaults in settings.php.

File

core/tests/Drupal/Tests/BrowserTestBase.php, line 702

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\Tests

Code

protected function translatePostValues(array $values) {
  $edit = [];
  // The easiest and most straightforward way to translate values suitable for
  // BrowserTestBase::submitForm() 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) {
    [$key, $value] = explode('=', $item);
    $edit[urldecode($key)] = urldecode($value);
  }
  return $edit;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.