diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 754f9d9..0f8c57c 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -651,6 +651,43 @@ protected function drupalGet($path, array $options = [], array $headers = []) { } /** + * Retrieves a Drupal path or an absolute path and JSON decodes the result. + * + * @param \Drupal\Core\Url|string $path + * Drupal path or URL to request AJAX from. + * @param array $options + * Array of URL options. + * @param array $headers + * Array of headers. Eg array('Accept: application/vnd.drupal-ajax'). + * + * @return array + * Decoded json. + */ + protected function drupalGetJSON($path, array $options = [], array $headers = []) { + return Json::decode($this->drupalGetWithFormat($path, 'json', $options, $headers)); + } + + /** + * Retrieves a Drupal path or an absolute path for a given format. + * + * @param \Drupal\Core\Url|string $path + * Drupal path or URL to request given format from. + * @param string $format + * The wanted request format. + * @param array $options + * Array of URL options. + * @param array $headers + * Array of headers. + * + * @return mixed + * The result of the request. + */ + protected function drupalGetWithFormat($path, $format, array $options = [], array $headers = []) { + $options += ['query' => ['_format' => $format]]; + return $this->drupalGet($path, $options, $headers); + } + + /** * Takes a path and returns an absolute path. * * @param string $path