setUpRequest example


  protected function setUp(): void {
    $this->rendererConfig['debug'] = TRUE;

    parent::setUp();
  }

  /** * Test render debug output. */
  public function testDebugOutput() {
    $this->setUpRequest();
    $this->setupMemoryCache();

    $element = [
      '#cache' => [
        'keys' => ['render_cache_test_key'],
        'tags' => ['render_cache_test_tag', 'render_cache_test_tag1'],
        'max-age' => 10,
      ],
      '#markup' => 'Test 1',
    ];
    $markup = $this->renderer->renderRoot($element);

    
/** * @covers ::render * @covers ::doRender * @covers \Drupal\Core\Render\RenderCache::get * @covers \Drupal\Core\Render\RenderCache::set * @covers \Drupal\Core\Render\RenderCache::createCacheID * * @dataProvider providerRenderCache */
  public function testRenderCache($child_access$expected_tags) {
    $this->setUpRequest();
    $this->setupMemoryCache();

    // Create an empty element.     $test_element = [
      '#cache' => [
        'keys' => ['render_cache_test'],
        'tags' => ['render_cache_tag'],
      ],
      '#markup' => '',
      'child' => [
        '#access' => $child_access,
        
// Disable the required cache contexts, so that this test can test just the     // bubbling behavior.     $this->rendererConfig['required_cache_contexts'] = [];

    parent::setUp();
  }

  /** * Tests bubbling of assets when NOT using #pre_render callbacks. */
  public function testBubblingWithoutPreRender() {
    $this->setUpRequest();
    $this->setupMemoryCache();

    $this->cacheContextsManager->expects($this->any())
      ->method('convertTokensToKeys')
      ->willReturnArgument(0);

    // Create an element with a child and subchild. Each element loads a     // different library using #attached.     $element = [
      '#type' => 'container',
      '#cache' => [
        

  public function testUncacheableParent($element$args, array $expected_placeholder_render_array$placeholder_cid_parts, array $bubbled_cache_contexts, array $bubbled_cache_tags, array $placeholder_expected_render_cache_array) {
    if ($placeholder_cid_parts) {
      $this->setupMemoryCache();
    }
    else {
      $this->setUpUnusedCache();
    }

    $this->setUpRequest('GET');

    // No #cache on parent element.     $element['#prefix'] = '<p>#cache disabled</p>';
    $output = $this->renderer->renderRoot($element);
    $this->assertSame('<p>#cache disabled</p><p>This is a rendered placeholder!</p>', (string) $output, 'Output is overridden.');
    $this->assertSame('<p>#cache disabled</p><p>This is a rendered placeholder!</p>', (string) $element['#markup'], '#markup is overridden.');
    $expected_js_settings = [
      'foo' => 'bar',
      'dynamic_animal' => $args[0],
    ];
    $this->assertSame($element['#attached']['drupalSettings']$expected_js_settings, '#attached is modified; both the original JavaScript setting and the one added by the placeholder #lazy_builder callback exist.');
    
/** * ::renderRoot() may not be called inside of another ::renderRoot() call. * * @covers ::renderRoot * @covers ::render * @covers ::doRender */
  public function testRenderRecursionWithNestedRenderRoot() {
    [$complex_child_markup$parent_markup$complex_child_template] = $this->setUpRenderRecursionComplexElements();
    $renderer = $this->renderer;
    $this->setUpRequest();

    $complex_child = $complex_child_template;
    $callable = function D) use ($renderer$complex_child) {
      $this->expectException(\LogicException::class);
      $renderer->renderRoot($complex_child);
    };

    $page = [
      'content' => [
        '#pre_render' => [
          $callable,
        ],
Home | Imprint | This part of the site doesn't use cookies.