You are here

public function BigPipeSessionlessStrategyTest::placeholdersProvider 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::placeholdersProvider()

See also

\Drupal\big_pipe_test\BigPipePlaceholderTestCases

File

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

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 placeholdersProvider() {
  $cases = BigPipePlaceholderTestCases::cases();

  // Generate $placeholders variable as expected by
  // \Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface::processPlaceholders().
  $placeholders = [
    $cases['html']->placeholder => $cases['html']->placeholderRenderArray,
    $cases['html_attribute_value']->placeholder => $cases['html_attribute_value']->placeholderRenderArray,
    $cases['html_attribute_value_subset']->placeholder => $cases['html_attribute_value_subset']->placeholderRenderArray,
    $cases['edge_case__invalid_html']->placeholder => $cases['edge_case__invalid_html']->placeholderRenderArray,
    $cases['edge_case__html_non_lazy_builder']->placeholder => $cases['edge_case__html_non_lazy_builder']->placeholderRenderArray,
    $cases['exception__lazy_builder']->placeholder => $cases['exception__lazy_builder']->placeholderRenderArray,
    $cases['exception__embedded_response']->placeholder => $cases['exception__embedded_response']->placeholderRenderArray,
  ];

  // In the 'no session' cases, BigPipe *always* use no-JS placeholders, so
  // the 'cookies:big_pipe_nojs' cache context is unnecessary.
  $remove_no_js_cookie_cache_context = function (array $render_array) {
    $render_array['#cache']['contexts'] = array_diff($render_array['#cache']['contexts'], [
      'cookies:big_pipe_nojs',
    ]);
    return $render_array;
  };
  return [
    '_no_big_pipe absent, no session, no-JS cookie absent: no-JS BigPipe placeholder used for HTML placeholders' => [
      $placeholders,
      'GET',
      FALSE,
      FALSE,
      FALSE,
      [
        $cases['html']->placeholder => $remove_no_js_cookie_cache_context($cases['html']->bigPipeNoJsPlaceholderRenderArray),
        $cases['html_attribute_value']->placeholder => $remove_no_js_cookie_cache_context($cases['html_attribute_value']->bigPipeNoJsPlaceholderRenderArray),
        $cases['html_attribute_value_subset']->placeholder => $remove_no_js_cookie_cache_context($cases['html_attribute_value_subset']->bigPipeNoJsPlaceholderRenderArray),
        $cases['edge_case__invalid_html']->placeholder => $remove_no_js_cookie_cache_context($cases['edge_case__invalid_html']->bigPipeNoJsPlaceholderRenderArray),
        $cases['edge_case__html_non_lazy_builder']->placeholder => $remove_no_js_cookie_cache_context($cases['edge_case__html_non_lazy_builder']->bigPipeNoJsPlaceholderRenderArray),
        $cases['exception__lazy_builder']->placeholder => $remove_no_js_cookie_cache_context($cases['exception__lazy_builder']->bigPipeNoJsPlaceholderRenderArray),
        $cases['exception__embedded_response']->placeholder => $remove_no_js_cookie_cache_context($cases['exception__embedded_response']->bigPipeNoJsPlaceholderRenderArray),
      ],
    ],
    '_no_big_pipe absent, no session, no-JS cookie present: no-JS BigPipe placeholder used for HTML placeholders' => [
      $placeholders,
      'GET',
      FALSE,
      FALSE,
      TRUE,
      [
        $cases['html']->placeholder => $remove_no_js_cookie_cache_context($cases['html']->bigPipeNoJsPlaceholderRenderArray),
        $cases['html_attribute_value']->placeholder => $remove_no_js_cookie_cache_context($cases['html_attribute_value']->bigPipeNoJsPlaceholderRenderArray),
        $cases['html_attribute_value_subset']->placeholder => $remove_no_js_cookie_cache_context($cases['html_attribute_value_subset']->bigPipeNoJsPlaceholderRenderArray),
        $cases['edge_case__invalid_html']->placeholder => $remove_no_js_cookie_cache_context($cases['edge_case__invalid_html']->bigPipeNoJsPlaceholderRenderArray),
        $cases['edge_case__html_non_lazy_builder']->placeholder => $remove_no_js_cookie_cache_context($cases['edge_case__html_non_lazy_builder']->bigPipeNoJsPlaceholderRenderArray),
        $cases['exception__lazy_builder']->placeholder => $remove_no_js_cookie_cache_context($cases['exception__lazy_builder']->bigPipeNoJsPlaceholderRenderArray),
        $cases['exception__embedded_response']->placeholder => $remove_no_js_cookie_cache_context($cases['exception__embedded_response']->bigPipeNoJsPlaceholderRenderArray),
      ],
    ],
    '_no_big_pipe present, no session, no-JS cookie absent' => [
      $placeholders,
      'GET',
      TRUE,
      FALSE,
      FALSE,
      [],
    ],
    '_no_big_pipe present, no session, no-JS cookie present' => [
      $placeholders,
      'GET',
      TRUE,
      FALSE,
      TRUE,
      [],
    ],
    '_no_big_pipe present, session, no-JS cookie absent' => [
      $placeholders,
      'GET',
      TRUE,
      TRUE,
      FALSE,
      [],
    ],
    '_no_big_pipe present, session, no-JS cookie present' => [
      $placeholders,
      'GET',
      TRUE,
      TRUE,
      TRUE,
      [],
    ],
    '_no_big_pipe absent, session, no-JS cookie absent: (JS-powered) BigPipe placeholder used for HTML placeholders' => [
      $placeholders,
      'GET',
      FALSE,
      TRUE,
      FALSE,
      [],
    ],
    '_no_big_pipe absent, session, no-JS cookie absent: (JS-powered) BigPipe placeholder used for HTML placeholders — but unsafe method' => [
      $placeholders,
      'POST',
      FALSE,
      TRUE,
      FALSE,
      [],
    ],
    '_no_big_pipe absent, session, no-JS cookie present: no-JS BigPipe placeholder used for HTML placeholders' => [
      $placeholders,
      'GET',
      FALSE,
      TRUE,
      TRUE,
      [],
    ],
    '_no_big_pipe absent, session, no-JS cookie present: no-JS BigPipe placeholder used for HTML placeholders — but unsafe method' => [
      $placeholders,
      'POST',
      FALSE,
      TRUE,
      TRUE,
      [],
    ],
  ];
}