diff --git a/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php index 7b5c33f7ec..52cf605dac 100644 --- a/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php +++ b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php @@ -90,7 +90,7 @@ public static function cases(ContainerInterface $container = NULL, AccountInterf 'command' => 'insert', 'method' => 'replaceWith', 'selector' => '[data-big-pipe-placeholder-id="callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&args%5B0%5D&token=_HAdUpwWmet0TOTe2PSiJuMntExoshbm1kh2wQzzzAA"]', - 'data' => ' ' . "\n ", + 'data' => ' ' . "\n ", 'settings' => NULL, ], ]; diff --git a/core/modules/big_pipe/src/Tests/BigPipeTest.php b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php similarity index 90% rename from core/modules/big_pipe/src/Tests/BigPipeTest.php rename to core/modules/big_pipe/tests/src/Functional/BigPipeTest.php index a4d5562008..a2600aaa76 100644 --- a/core/modules/big_pipe/src/Tests/BigPipeTest.php +++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php @@ -1,14 +1,16 @@ getSession()->getDriver()->getClient()->followRedirects(FALSE); $this->maximumMetaRefreshCount = 1; $this->checkForMetaRefresh(); $this->maximumMetaRefreshCount = 0; $this->metaRefreshCount = 0; + $this->getSession()->getDriver()->getClient()->followRedirects(TRUE); } /** @@ -95,9 +99,7 @@ public function testNoJsDetection() { $this->drupalLogout(); // Close the prior connection and remove the collected state. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; + $this->getSession()->reset(); // 3. Session (anonymous). $this->drupalGet(Url::fromRoute('user.login', [], ['query' => ['trigger_session' => 1]])); @@ -112,9 +114,7 @@ public function testNoJsDetection() { $this->assertRaw($no_js_to_js_markup); // Close the prior connection and remove the collected state. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; + $this->getSession()->reset(); // Edge case: route with '_no_big_pipe' option. $this->drupalGet(Url::fromRoute('no_big_pipe')); @@ -138,7 +138,7 @@ public function testNoJsDetection() { * - \Drupal\big_pipe\Render\BigPipe * - \Drupal\big_pipe\Render\BigPipe::sendPlaceholders() * - * @see \Drupal\big_pipe\Tests\BigPipePlaceholderTestCases + * @see \Drupal\Tests\big_pipe\Functional\BigPipePlaceholderTestCases */ public function testBigPipe() { // Simulate production. @@ -218,7 +218,7 @@ public function testBigPipe() { * - \Drupal\big_pipe\Render\BigPipe * - \Drupal\big_pipe\Render\BigPipe::sendNoJsPlaceholders() * - * @see \Drupal\big_pipe\Tests\BigPipePlaceholderTestCases + * @see \Drupal\Tests\big_pipe\Functional\BigPipePlaceholderTestCases */ public function testBigPipeNoJs() { // Simulate production. @@ -369,14 +369,14 @@ protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholde $this->assertNoRaw($expected_placeholder_replacement); continue; } - $this->assertEqual($expected_ajax_response, trim((string) $result[0])); + $this->assertEqual($expected_ajax_response, trim($result[0]->getText())); $this->assertRaw($expected_placeholder_replacement); $pos = strpos($this->getRawContent(), $expected_placeholder_replacement); $placeholder_replacement_positions[$pos] = $big_pipe_placeholder_id; } ksort($placeholder_positions, SORT_NUMERIC); $this->assertEqual(array_keys($expected_big_pipe_placeholders), array_values($placeholder_positions)); - $placeholders = array_map(function(\SimpleXMLElement $element) { return (string) $element['data-big-pipe-placeholder-id']; }, $this->cssSelect('[data-big-pipe-placeholder-id]')); + $placeholders = array_map(function(NodeElement $element) { return $element->getAttribute('data-big-pipe-placeholder-id'); }, $this->cssSelect('[data-big-pipe-placeholder-id]')); $this->assertEqual(count($expected_big_pipe_placeholders), count(array_unique($placeholders))); $expected_big_pipe_placeholders_with_replacements = []; foreach ($expected_big_pipe_placeholder_stream_order as $big_pipe_placeholder_id) { @@ -409,7 +409,7 @@ protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholde * Ensures CSRF tokens can be generated for the current user's session. */ protected function setCsrfTokenSeedInTestEnvironment() { - $session_data = $this->container->get('session_handler.write_safe')->read($this->cookies[$this->getSessionName()]['value']); + $session_data = $this->container->get('session_handler.write_safe')->read($this->getSession()->getCookie($this->getSessionName())); $csrf_token_seed = unserialize(explode('_sf2_meta|', $session_data)[1])['s']; $this->container->get('session_manager.metadata_bag')->setCsrfTokenSeed($csrf_token_seed); } @@ -446,33 +446,34 @@ protected function assertSessionCookieExists($expected) { * Asserts whether a cookie exists on the client or not. */ protected function assertCookieExists($cookie_name, $expected, $cookie_label) { - $non_deleted_cookies = array_filter($this->cookies, function ($item) { return $item['value'] !== 'deleted'; }); - $this->assertEqual($expected, isset($non_deleted_cookies[$cookie_name]), $expected ? "$cookie_label cookie exists." : "$cookie_label cookie does not exist."); + $this->assertEqual($expected, !empty($this->getSession()->getCookie($cookie_name)), $expected ? "$cookie_label cookie exists." : "$cookie_label cookie does not exist."); } /** * Calls ::performMetaRefresh() and asserts the responses. */ protected function assertBigPipeNoJsMetaRefreshRedirect() { - $original_url = $this->url; - $this->performMetaRefresh(); - - $this->assertEqual($original_url, $this->url, 'Redirected back to the original location.'); + $original_url = $this->getSession()->getCurrentUrl(); - $headers = $this->drupalGetHeaders(TRUE); - $this->assertEqual(2, count($headers), 'Two requests were made upon following the refresh, there are headers for two responses.'); + // Perform the MetaRefresh without following any additional redirects. + $this->performMetaRefresh(); + $headers[0] = $this->getSession()->getResponseHeaders(); // First response: redirect. - $this->assertEqual('HTTP/1.1 302 Found', $headers[0][':status'], 'The first response was a 302 (redirect).'); - $this->assertIdentical(0, strpos($headers[0]['set-cookie'], 'big_pipe_nojs=1'), 'The first response sets the big_pipe_nojs cookie.'); - $this->assertEqual($original_url, $headers[0]['location'], 'The first response redirected back to the original page.'); - $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['x-drupal-cache-contexts']))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'); - $this->assertFalse(isset($headers[0]['surrogate-control']), 'The first response has no "Surrogate-Control" header.'); + $this->assertResponse(302); + $this->assertIdentical(0, strpos($headers[0]['Set-Cookie'][0], 'big_pipe_nojs=1'), 'The first response sets the big_pipe_nojs cookie.'); + $this->assertEqual($original_url, $headers[0]['Location'][0], 'The first response redirected back to the original page.'); + $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'); + $this->assertFalse(isset($headers[0]['Surrogate-Control']), 'The first response has no "Surrogate-Control" header.'); + + $this->drupalGet($original_url); + $this->assertEquals($original_url, $this->getSession()->getCurrentUrl(), 'Redirected back to the original location.'); + $headers[1] = $this->getSession()->getResponseHeaders(); // Second response: redirect followed. - $this->assertEqual('HTTP/1.1 200 OK', $headers[1][':status'], 'The second response was a 200.'); - $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['x-drupal-cache-contexts']))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'); - $this->assertEqual('no-store, content="BigPipe/1.0"', $headers[1]['surrogate-control'], 'The second response has a "Surrogate-Control" header.'); + $this->assertResponse(200); + $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'); + $this->assertEqual('no-store, content="BigPipe/1.0"', $headers[1]['Surrogate-Control'][0], 'The second response has a "Surrogate-Control" header.'); $this->assertNoRaw('