You are here

public function BigPipeSessionlessStrategyTest::testProcessPlaceholders in Sessionless BigPipe 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Render/Placeholder/BigPipeSessionlessStrategyTest.php \Drupal\Tests\big_pipe_sessionless\Unit\Render\Placeholder\BigPipeSessionlessStrategyTest::testProcessPlaceholders()

@covers ::processPlaceholders

@dataProvider placeholdersProvider

File

tests/src/Unit/Render/Placeholder/BigPipeSessionlessStrategyTest.php, line 28

Class

BigPipeSessionlessStrategyTest
@coversDefaultClass \Drupal\big_pipe_sessionless\Render\Placeholder\BigPipeSessionlessStrategy @group big_pipe_sessionless

Namespace

Drupal\Tests\big_pipe_sessionless\Unit\Render\Placeholder

Code

public function testProcessPlaceholders(array $placeholders, $method, $route_match_has_no_big_pipe_option, $request_has_session, $request_has_big_pipe_nojs_cookie, array $expected_big_pipe_placeholders) {
  $request = new Request();
  $request
    ->setMethod($method);
  if ($request_has_big_pipe_nojs_cookie) {
    $request->cookies
      ->set(BigPipeSessionlessStrategy::NOJS_COOKIE, 1);
  }
  $request_stack = $this
    ->prophesize(RequestStack::class);
  $request_stack
    ->getCurrentRequest()
    ->willReturn($request);
  $session_configuration = $this
    ->prophesize(SessionConfigurationInterface::class);
  $session_configuration
    ->hasSession(Argument::type(Request::class))
    ->willReturn($request_has_session);
  $route = $this
    ->prophesize(Route::class);
  $route
    ->getOption('_no_big_pipe')
    ->willReturn($route_match_has_no_big_pipe_option);
  $route_match = $this
    ->prophesize(RouteMatchInterface::class);
  $route_match
    ->getRouteObject()
    ->willReturn($route);
  $big_pipe_strategy = new BigPipeSessionlessStrategy($session_configuration
    ->reveal(), $request_stack
    ->reveal(), $route_match
    ->reveal());
  $processed_placeholders = $big_pipe_strategy
    ->processPlaceholders($placeholders);
  if ($request
    ->isMethodCacheable() && !$route_match_has_no_big_pipe_option && !$request_has_session) {
    $this
      ->assertSameSize($expected_big_pipe_placeholders, $processed_placeholders, 'BigPipe is able to deliver all placeholders.');
    foreach (array_keys($placeholders) as $placeholder) {
      $this
        ->assertSame($expected_big_pipe_placeholders[$placeholder], $processed_placeholders[$placeholder], "Verifying how BigPipeStrategy handles the placeholder '{$placeholder}'");
    }
  }
  else {
    $this
      ->assertSame(0, count($processed_placeholders));
  }
}