Commit 89b381fe authored by alexpott's avatar alexpott

Issue #2851746 by Berdir, Wim Leers: Support xdebug header in ResourceTestBase...

Issue #2851746 by Berdir, Wim Leers: Support xdebug header in ResourceTestBase and move htttpClient property to right place
parent 1816bcd9
......@@ -110,11 +110,6 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
*/
protected static $secondCreatedEntityId = 3;
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* The main entity used for testing.
*
......@@ -165,10 +160,6 @@ public function setUp() {
$this->entityStorage = $this->container->get('entity_type.manager')
->getStorage(static::$entityTypeId);
// Set up a HTTP client that accepts relative URLs.
$this->httpClient = $this->container->get('http_client_factory')
->fromOptions(['base_uri' => $this->baseUrl]);
// Create an entity.
$this->entity = $this->createEntity();
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\rest\Functional;
use Behat\Mink\Driver\BrowserKitDriver;
use Drupal\Core\Url;
use Drupal\rest\RestResourceConfigInterface;
use Drupal\Tests\BrowserTestBase;
......@@ -83,6 +84,11 @@ abstract class ResourceTestBase extends BrowserTestBase {
*/
public static $modules = ['rest'];
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* {@inheritdoc}
*/
......@@ -120,6 +126,10 @@ public function setUp() {
// Ensure there's a clean slate: delete all REST resource config entities.
$this->resourceConfigStorage->delete($this->resourceConfigStorage->loadMultiple());
$this->refreshTestStateAfterRestConfigChange();
// Set up a HTTP client that accepts relative URLs.
$this->httpClient = $this->container->get('http_client_factory')
->fromOptions(['base_uri' => $this->baseUrl]);
}
/**
......@@ -325,6 +335,7 @@ protected function grantPermissionsToTestedRole(array $permissions) {
*/
protected function request($method, Url $url, array $request_options) {
$request_options[RequestOptions::HTTP_ERRORS] = FALSE;
$request_options = $this->decorateWithXdebugCookie($request_options);
return $this->httpClient->request($method, $url->toString(), $request_options);
}
......@@ -366,4 +377,30 @@ protected function assertResourceErrorResponse($expected_status_code, $expected_
$this->assertResourceResponse($expected_status_code, $expected_body, $response);
}
/**
* Adds the Xdebug cookie to the request options.
*
* @param array $request_options
* The request options.
*
* @return array
* Request options updated with the Xdebug cookie if present.
*/
protected function decorateWithXdebugCookie(array $request_options) {
$session = $this->getSession();
$driver = $session->getDriver();
if ($driver instanceof BrowserKitDriver) {
$client = $driver->getClient();
foreach ($client->getCookieJar()->all() as $cookie) {
if (isset($request_options[RequestOptions::HEADERS]['Cookie'])) {
$request_options[RequestOptions::HEADERS]['Cookie'] .= '; ' . $cookie->getName() . '=' . $cookie->getValue();
}
else {
$request_options[RequestOptions::HEADERS]['Cookie'] = $cookie->getName() . '=' . $cookie->getValue();
}
}
}
return $request_options;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment