View source
<?php
namespace Drupal\Tests\big_pipe_sessionless\Functional;
use Drupal\big_pipe\Render\BigPipe;
use Drupal\Tests\big_pipe\Functional\BigPipeTest;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
class BigPipeSessionlessTest extends BigPipeTest {
public static $modules = [
'big_pipe_sessionless',
'big_pipe_sessionless_test',
];
public function testBigPipeNoSession() {
$cases = [
'default' => [
'configured max-age' => 0,
'page cache hit cache control' => 'must-revalidate, no-cache, private',
],
'max-age=300' => [
'configured max-age' => 300,
'page cache hit cache control' => 'max-age=300, public',
],
];
foreach ($cases as $case => $expectations) {
$this
->pass("No-session test case: {$case}");
$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();
$this
->assertSessionCookieExists(FALSE);
$this
->assertBigPipeNoJsCookieExists(FALSE);
$this
->pass('First request: Page Cache miss, streamed response by BigPipe', 'Debug');
$this
->drupalGet(Url::fromRoute('big_pipe_sessionless_test'));
$this
->assertFalse($this
->drupalGetHeader('X-Drupal-Cache'), 'No X-Drupal-Cache header.');
$this
->assertBigPipeResponseHeadersPresent();
$this
->assertNoCacheTag('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="<front>">This should be marked inactive</a>');
$cases = $this
->getTestCases();
$this
->assertBigPipeNoJsPlaceholders([
$cases['edge_case__invalid_html']->bigPipeNoJsPlaceholder => $cases['edge_case__invalid_html']->embeddedHtmlResponse,
$cases['html_attribute_value']->bigPipeNoJsPlaceholder => '<form class="big-pipe-test-form" data-drupal-selector="big-pipe-test-form" action="' . base_path() . 'big_pipe_sessionless_test"',
$cases['html']->bigPipeNoJsPlaceholder => NULL,
$cases['edge_case__html_non_lazy_builder']->bigPipeNoJsPlaceholder => $cases['edge_case__html_non_lazy_builder']->embeddedHtmlResponse,
$cases['exception__lazy_builder']->bigPipePlaceholderId => NULL,
$cases['exception__embedded_response']->bigPipePlaceholderId => NULL,
]);
$this
->pass('Verifying there are no BigPipe placeholders & replacements…', 'Debug');
$this
->assertEqual('<none>', $this
->drupalGetHeader('BigPipe-Test-Placeholders'));
$this
->pass('Verifying BigPipe start/stop signals are absent…', 'Debug');
$this
->assertNoRaw(BigPipe::START_SIGNAL, 'BigPipe start signal absent.');
$this
->assertNoRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal absent.');
$this
->pass('Verifying BigPipe assets are absent…', 'Debug');
$this
->assertTrue(empty($this
->getDrupalSettings()), 'drupalSettings and BigPipe asset library absent.');
$this
->assertRaw('</body>', 'Closing body tag present.');
$this
->pass('Repeat request: Page Cache hit, BigPipe not involved', 'Debug');
$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
->assertFalse($this
->drupalGetHeader('Surrogate-Control'), 'No Surrogate-Control header.');
$this
->assertFalse($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="<front>">This should be marked inactive</a>');
Cache::invalidateTags([
'cache_tag_set_in_lazy_builder',
]);
$this
->pass('Verifying BigPipe provides useful error output when an error occurs while rendering a placeholder if verbose error logging is enabled.', 'Debug');
$this
->config('system.logging')
->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)
->save();
$this
->drupalGet(Url::fromRoute('big_pipe_sessionless_test'));
$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
->assertNoRaw('</body>', 'Closing body tag absent: error occurred before then.');
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
Cache::invalidateTags([
'rendered',
]);
}
}
}