diff -u b/core/modules/page_cache/tests/src/Functional/PageCacheTest.php b/core/modules/page_cache/tests/src/Functional/PageCacheTest.php --- b/core/modules/page_cache/tests/src/Functional/PageCacheTest.php +++ b/core/modules/page_cache/tests/src/Functional/PageCacheTest.php @@ -7,8 +7,8 @@ use Drupal\Core\Url; use Drupal\entity_test\Entity\EntityTest; use Drupal\Core\Cache\Cache; -use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait; use Drupal\user\RoleInterface; /** @@ -191,7 +191,7 @@ // Verify the page is not printed twice when the cache is cold. $this->assertNoPattern('#drupalHead(''); + $this->drupalGet(''); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $etag = $this->drupalGetHeader('ETag'); $last_modified = $this->drupalGetHeader('Last-Modified'); @@ -199,10 +199,16 @@ $this->drupalGet('', [], ['If-Modified-Since' => $last_modified, 'If-None-Match' => $etag]); $this->assertResponse(304, 'Conditional request returned 304 Not Modified.'); - $this->drupalGet('', [], ['If-Modified-Since' => gmdate(DATE_RFC822, strtotime($last_modified)), 'If-None-Match' => $etag]); + $this->drupalGet('', [], [ + 'If-Modified-Since' => gmdate(DATE_RFC822, strtotime($last_modified)), + 'If-None-Match' => $etag, + ]); $this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'); - $this->drupalGet('', [], ['If-Modified-Since' => gmdate(DATE_RFC850, strtotime($last_modified)), 'If-None-Match' => $etag]); + $this->drupalGet('', [], [ + 'If-Modified-Since' => gmdate(DATE_RFC850, strtotime($last_modified)), + 'If-None-Match' => $etag, + ]); $this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'); $this->drupalGet('', [], ['If-Modified-Since' => $last_modified, 'If-None-Match' => NULL]); @@ -211,7 +217,10 @@ $this->assertResponse(200, 'Conditional request without If-None-Match returned 200 OK.'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); - $this->drupalGet('', [], ['If-Modified-Since' => gmdate(DateTimePlus::RFC7231, strtotime($last_modified) + 1), 'If-None-Match' => $etag]); + $this->drupalGet('', [], [ + 'If-Modified-Since' => gmdate(DateTimePlus::RFC7231, strtotime($last_modified) + 1), + 'If-None-Match' => $etag, + ]); $this->assertResponse(200, 'Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); @@ -521,29 +530,30 @@ * Tests that HEAD requests are treated the same as GET requests. */ public function testHead() { - /** @var \GuzzleHttp\Client $client */ + /** @var \GuzzleHttp\ClientInterface $client */ $client = $this->getSession()->getDriver()->getClient()->getClient(); + // GET, then HEAD. $url_a = $this->buildUrl('system-test/set-header', ['query' => ['name' => 'Foo', 'value' => 'bar']]); - $response = $this->drupalGet($url_a); + $response_body = $this->drupalGet($url_a); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.'); - $this->assertEqual('The following header was set: Foo: bar', $response); + $this->assertEqual('The following header was set: Foo: bar', $response_body); $response = $client->request('HEAD', $url_a); - $this->assertEquals(['HIT'], $response->getHeader('X-Drupal-Cache'), 'Page was cached.'); - $this->assertEquals(['bar'], $response->getHeader('Foo'), 'Custom header was sent.'); - $this->assertEqual('', (string) $response->getBody()); + $this->assertEqual($response->getHeaderLine('X-Drupal-Cache'), 'HIT', 'Page was cached.'); + $this->assertEqual($response->getHeaderLine('Foo'), 'bar', 'Custom header was sent.'); + $this->assertEqual('', $response->getBody()->getContents()); // HEAD, then GET. $url_b = $this->buildUrl('system-test/set-header', ['query' => ['name' => 'Foo', 'value' => 'baz']]); $response = $client->request('HEAD', $url_b); - $this->assertEquals(['MISS'], $response->getHeader('X-Drupal-Cache'), 'Page was not cached.'); - $this->assertEquals(['baz'], $response->getHeader('Foo'), 'Custom header was sent.'); - $this->assertEqual('', (string) $response->getBody()); - $response = $this->drupalGet($url_b); + $this->assertEqual($response->getHeaderLine('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); + $this->assertEqual($response->getHeaderLine('Foo'), 'baz', 'Custom header was sent.'); + $this->assertEqual('', $response->getBody()->getContents()); + $response_body = $this->drupalGet($url_b); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $this->assertEqual($this->drupalGetHeader('Foo'), 'baz', 'Custom header was sent.'); - $this->assertEqual('The following header was set: Foo: baz', $response); + $this->assertEqual('The following header was set: Foo: baz', $response_body); } /** @@ -563,8 +573,4 @@ ], [ - $url . '?', - $url . '', - ], - [ $url . '?a=b+c', $url . '?a=b%20c', reverted: --- b/core/tests/Drupal/Tests/BrowserTestBase.php +++ a/core/tests/Drupal/Tests/BrowserTestBase.php @@ -1419,44 +1419,4 @@ return FALSE; } - /** - * Retrieves only the headers for a Drupal path or an absolute path. - * - * @param \Drupal\Core\Url|string $path - * Drupal path or URL to load into internal browser. - * @param array $options - * Options to be forwarded to the url generator. - * @param array $headers - * An array containing additional HTTP request headers, each formatted as - * "name: value". - * - * @return array - * The retrieved headers, also available as $this->getRawContent() - */ - protected function drupalHead($path, array $options = [], array $headers = []) { - $options['absolute'] = TRUE; - $url = $this->buildUrl($path, $options); - $session = $this->getSession(); - $this->prepareRequest(); - foreach ($headers as $header_name => $header_value) { - $session->setRequestHeader($header_name, $header_value); - } - $session->visit($url); - $out = $session->getResponseHeaders(); - - // Ensure that any changes to variables in the other thread are picked up. - $this->refreshVariables(); - - // Log only for JavascriptTestBase tests because for Goutte we log with - // ::getResponseLogHandler. - if ($this->htmlOutputEnabled && !($this->getSession()->getDriver() instanceof GoutteDriver)) { - $html_output = 'GET request to: ' . $url . - '
Ending URL: ' . $this->getSession()->getCurrentUrl(); - $html_output .= '
' . $out; - $html_output .= $this->getHtmlOutputHeaders(); - $this->htmlOutput($html_output); - } - return $out; - } - }