src/Tests/BigPipeNoJsDetectionTest.php | 85 +++++++++++++++++----- .../src/EventSubscriber/BigPipeTestSubscriber.php | 2 +- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/src/Tests/BigPipeNoJsDetectionTest.php b/src/Tests/BigPipeNoJsDetectionTest.php index 75366d0..8a0cfb2 100644 --- a/src/Tests/BigPipeNoJsDetectionTest.php +++ b/src/Tests/BigPipeNoJsDetectionTest.php @@ -32,7 +32,7 @@ class BigPipeNoJsDetectionTest extends WebTestBase { * * @var array */ - public static $modules = ['big_pipe']; + public static $modules = ['big_pipe', 'big_pipe_test']; /** * {@inheritdoc} @@ -93,10 +93,6 @@ class BigPipeNoJsDetectionTest extends WebTestBase { * Tests BigPipe-delivered HTML responses when JavaScript is enabled. */ public function testBigPipe() { - $this->container->get('module_installer')->install(['big_pipe_test']); - $this->rebuildContainer(); - $this->rebuildAll(); - $this->drupalLogin($this->rootUser); $this->assertSessionCookieExists(TRUE); $this->assertBigPipeNoJsCookieExists(FALSE); @@ -167,7 +163,7 @@ class BigPipeNoJsDetectionTest extends WebTestBase { ]; $this->pass('Verifying BigPipe no-JS placeholders & replacements…', 'Debug'); - $this->assertSetsEqual(array_keys($expected_big_pipe_nojs_placeholders), explode(' ', $this->drupalGetHeader('BigPipe-Test-No-Js-Placeholders'))); + $this->assertSetsEqual(array_keys($expected_big_pipe_nojs_placeholders), array_map('rawurldecode', explode(' ', $this->drupalGetHeader('BigPipe-Test-No-Js-Placeholders')))); foreach ($expected_big_pipe_nojs_placeholders as $big_pipe_nojs_placeholder => $expected_replacement) { $this->pass('Checking whether the replacement for the BigPipe no-JS placeholder "' . $big_pipe_nojs_placeholder . '" is present:'); $this->assertRaw($expected_replacement); @@ -221,6 +217,63 @@ class BigPipeNoJsDetectionTest extends WebTestBase { $this->assertEqual($expected_stream_order, array_values($actual_stream_order)); } + /** + * Tests BigPipe-delivered HTML responses when JavaScript is disabled. + */ + public function testBigPipeNoJs() { + $this->drupalLogin($this->rootUser); + $this->assertSessionCookieExists(TRUE); + $this->assertBigPipeNoJsCookieExists(FALSE); + + // By calling checkForMetaRefresh() manually here, we simulate JavaScript + // being disabled, because as far as the BigPipe module is concerned, it is + // enabled in the browser when the BigPipe no-JS cookie is set. + // @see setUp() + $this->doMetaRefresh(); + $this->assertBigPipeNoJsCookieExists(TRUE); + + $this->drupalGet(Url::fromRoute('big_pipe_test')); + + // Ensure we can generate CSRF tokens for the current user's session. + $session_data = $this->container->get('session_handler.write_safe')->read($this->cookies[$this->getSessionName()]['value']); + $csrf_token_seed = unserialize(explode('_sf2_meta|', $session_data)[1])['s']; + $this->container->get('session_manager.metadata_bag')->setCsrfTokenSeed($csrf_token_seed); + + $this->pass('Verifying BigPipe response headers…', 'Debug'); + $this->assertTrue(FALSE !== strpos($this->drupalGetHeader('Cache-Control'), 'private'), 'Cache-Control header set to "private".'); + $this->assertEqual('no-store, content="BigPipe/1.0"', $this->drupalGetHeader('Surrogate-Control')); + $this->assertEqual('no', $this->drupalGetHeader('X-Accel-Buffering')); + + // Keys: BigPipe no-JS placeholder markup. Values: expected replacement markup. + $expected_big_pipe_nojs_placeholders = [ + 'big_pipe_nojs_placeholder_attribute_safe:<hello' => '', + 'big_pipe_nojs_placeholder_attribute_safe:form_action_cc611e1d' => '