Commit 1a85cc4c authored by Wim Leers's avatar Wim Leers Committed by Wim Leers
Browse files

Issue #3296639 by Wim Leers, Project Update Bot, reenaraghavan: Drupal 10 compatibility

parent 6ac2a969
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ name: Sessionless BigPipe
type: module
description: 'Accelerates Page Cache misses using the BigPipe technique.'
package: 'Performance and scalability'
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
dependencies:
  - drupal:big_pipe
  - drupal:page_cache
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ class BigPipeSessionless extends BigPipe {
    // do what they need to do. This is f.e. necessary for the cache tags header
    // for debugging purposes and for modules that integrate with reverse
    // proxies that support cache tags.
    $fake_request = $this->requestStack->getMasterRequest()->duplicate();
    $fake_request = $this->requestStack->getMainRequest()->duplicate();
    $streamed_response = $this->filterResponse($fake_request, HttpKernelInterface::MASTER_REQUEST, $streamed_response);

    // Prime Page Cache.
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ class BigPipeSessionlessTestController extends BigPipeTestController {
  public function test() {
    $build = parent::test();

    $has_session = \Drupal::service('session_configuration')->hasSession(\Drupal::requestStack()->getMasterRequest());
    $has_session = \Drupal::service('session_configuration')->hasSession(\Drupal::requestStack()->getMainRequest());

    // We can't test CSRF tokens for no-session requests.
    if (!$has_session) {
+2 −2
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ class BigPipeSessionlessRegressionTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  public static $modules = [
  protected static $modules = [
    'big_pipe',
    'big_pipe_sessionless',
  ];
+30 −30
Original line number Diff line number Diff line
@@ -24,11 +24,12 @@ use Drupal\Core\Url;
class BigPipeSessionlessTest extends BigPipeTest {

  /**
   * Modules to enable.
   *
   * @var array
   * {@inheritdoc}
   */
  public static $modules = ['big_pipe_sessionless', 'big_pipe_sessionless_test'];
  protected static $modules = [
    'big_pipe_sessionless',
    'big_pipe_sessionless_test',
  ];

  /**
   * Tests BigPipe-delivered HTML responses for requests with no session.
@@ -53,8 +54,6 @@ class BigPipeSessionlessTest extends BigPipeTest {
    ];

    foreach ($cases as $case => $expectations) {
      $this->pass("No-session test case: $case");

      // Simulate production.
      $this->config('system.logging')->set('error_level', ERROR_REPORTING_HIDE)->save();
      $this->config('system.performance')->set('cache.page.max_age', $expectations['configured max-age'])->save();
@@ -62,13 +61,13 @@ class BigPipeSessionlessTest extends BigPipeTest {
      $this->assertSessionCookieExists(FALSE);
      $this->assertBigPipeNoJsCookieExists(FALSE);

      $this->pass('First request: Page Cache miss, streamed response by BigPipe');
      // First request: Page Cache miss, streamed response by BigPipe.
      $this->drupalGet(Url::fromRoute('big_pipe_sessionless_test'));
      $this->assertNull($this->drupalGetHeader('X-Drupal-Cache'), 'No X-Drupal-Cache header.');
      $this->assertNull($this->getSession()->getResponseHeader('X-Drupal-Cache'), 'No X-Drupal-Cache header.');
      $this->assertBigPipeResponseHeadersPresent();
      $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'cache_tag_set_in_lazy_builder');
      $this->assertRaw('<a href="' . base_path() . 'big_pipe_sessionless_test" data-drupal-link-system-path="big_pipe_sessionless_test" class="is-active">This should be marked active</a>');
      $this->assertRaw('<a href="' . base_path() . '" data-drupal-link-system-path="&lt;front&gt;">This should be marked inactive</a>');
      $this->assertSession()->responseContains('<a href="' . base_path() . 'big_pipe_sessionless_test" data-drupal-link-system-path="big_pipe_sessionless_test" class="is-active">This should be marked active</a>');
      $this->assertSession()->responseContains('<a href="' . base_path() . '" data-drupal-link-system-path="&lt;front&gt;">This should be marked inactive</a>');

      $cases = $this->getTestCases();
      $this->assertBigPipeNoJsPlaceholders([
@@ -80,28 +79,28 @@ class BigPipeSessionlessTest extends BigPipeTest {
        $cases['exception__embedded_response']->bigPipePlaceholderId => NULL,
      ]);

      $this->pass('Verifying there are no BigPipe placeholders & replacements.');
      $this->assertEqual('<none>', $this->drupalGetHeader('BigPipe-Test-Placeholders'));
      $this->pass('Verifying BigPipe start/stop signals are absent.');
      // Verifying there are no BigPipe placeholders & replacements.
      $this->assertEquals('<none>', $this->getSession()->getResponseHeader('BigPipe-Test-Placeholders'));
      // BigPipe start signal absent.
      $this->assertNoRaw(BigPipe::START_SIGNAL);
      $this->assertSession()->responseNotContains(BigPipe::START_SIGNAL);
      // BigPipe stop signal absent.
      $this->assertNoRaw(BigPipe::STOP_SIGNAL);
      $this->assertSession()->responseNotContains(BigPipe::STOP_SIGNAL);

      $this->pass('Verifying BigPipe assets are absent.');
      // Verifying BigPipe assets are absent.
      $this->assertTrue(empty($this->getDrupalSettings()), 'drupalSettings and BigPipe asset library absent.');

      // Closing body tag present.
      $this->assertRaw('</body>');
      $this->assertSession()->responseContains('</body>');

      $this->pass('Repeat request: Page Cache hit, BigPipe not involved');
      // Repeat request: Page Cache hit, BigPipe not involved.
      $this->drupalGet(Url::fromRoute('big_pipe_sessionless_test'));
      $this->assertIdentical('HIT', $this->drupalGetHeader('X-Drupal-Cache'), 'Page cache hit.');
      $this->assertIdentical($expectations['page cache hit cache control'], $this->drupalGetHeader('Cache-Control'));
      $this->assertNull($this->drupalGetHeader('Surrogate-Control'), 'No Surrogate-Control header.');
      $this->assertNull($this->drupalGetHeader('X-Accel-Buffering'), 'No X-Accel-Buffering header.');
      $this->assertCacheTag('cache_tag_set_in_lazy_builder');
      $this->assertRaw('<a href="' . base_path() . 'big_pipe_sessionless_test" data-drupal-link-system-path="big_pipe_sessionless_test" class="is-active">This should be marked active</a>');
      $this->assertRaw('<a href="' . base_path() . '" data-drupal-link-system-path="&lt;front&gt;">This should be marked inactive</a>');
      $this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Cache'), 'Page cache hit.');
      $this->assertSame($expectations['page cache hit cache control'], $this->getSession()->getResponseHeader('Cache-Control'));
      $this->assertNull($this->getSession()->getResponseHeader('Surrogate-Control'), 'No Surrogate-Control header.');
      $this->assertNull($this->getSession()->getResponseHeader('X-Accel-Buffering'), 'No X-Accel-Buffering header.');
      $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'cache_tag_set_in_lazy_builder');
      $this->assertSession()->responseContains('<a href="' . base_path() . 'big_pipe_sessionless_test" data-drupal-link-system-path="big_pipe_sessionless_test" class="is-active">This should be marked active</a>');
      $this->assertSession()->responseContains('<a href="' . base_path() . '" data-drupal-link-system-path="&lt;front&gt;">This should be marked inactive</a>');

      // Clear the Page Cache. Note that we use a cache tag that exists on this
      // response, despite it being absent from both the Page Cache miss
@@ -110,15 +109,16 @@ class BigPipeSessionlessTest extends BigPipeTest {
      // minus the streaming).
      Cache::invalidateTags(['cache_tag_set_in_lazy_builder']);

      // Simulate development.
      $this->pass('Verifying BigPipe provides useful error output when an error occurs while rendering a placeholder if verbose error logging is enabled.');
      // Simulate development: verifying BigPipe provides useful error output
      // when an error occurs while rendering a placeholder if verbose error
      // logging is enabled.
      $this->config('system.logging')->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)->save();
      $this->drupalGet(Url::fromRoute('big_pipe_sessionless_test'));
      // The 'edge_case__html_exception' case throws an exception.
      $this->assertRaw('The website encountered an unexpected error. Please try again later');
      $this->assertRaw('You are not allowed to say llamas are not cool!');
      $this->assertSession()->responseContains('The website encountered an unexpected error. Please try again later');
      $this->assertSession()->responseContains('You are not allowed to say llamas are not cool!');
      // Closing body tag absent: error occurred before then.
      $this->assertNoRaw('</body>');
      $this->assertSession()->responseNotContains('</body>');
      // The exception is expected. Do not interpret it as a test failure.
      unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');