function DisplayBlockTest::testBlockRendering

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php \Drupal\Tests\block\Functional\Views\DisplayBlockTest::testBlockRendering()
  2. 8.9.x core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php \Drupal\Tests\block\Functional\Views\DisplayBlockTest::testBlockRendering()
  3. 10 core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php \Drupal\Tests\block\Functional\Views\DisplayBlockTest::testBlockRendering()

Tests the actual rendering of the views block.

File

core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php, line 263

Class

DisplayBlockTest
Tests the block display plugin.

Namespace

Drupal\Tests\block\Functional\Views

Code

public function testBlockRendering() : void {
    // Create a block and set a custom title.
    $block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', [
        'label' => 'test_view_block-block_1:1',
        'views_label' => 'Custom title',
        'region' => 'sidebar_first',
    ]);
    $block_xpath = $this->assertSession()
        ->buildXPathQuery('//aside[contains(@class, "layout-sidebar-first")]//div[@id = :id]', [
        ':id' => 'block-' . $block->id(),
    ]);
    $this->drupalGet('');
    $this->assertSession()
        ->elementTextEquals('xpath', "{$block_xpath}/h2", 'Custom title');
    $this->assertSession()
        ->elementTextEquals('xpath', "{$block_xpath}//footer", 'Custom title');
    // Don't override the title anymore.
    $plugin = $block->getPlugin();
    $plugin->setConfigurationValue('views_label', '');
    $block->save();
    $this->drupalGet('');
    $this->assertSession()
        ->elementTextEquals('xpath', "{$block_xpath}/h2", 'test_view_block');
    $this->assertSession()
        ->elementTextEquals('xpath', "{$block_xpath}//footer", 'test_view_block');
    // Hide the title.
    $block->getPlugin()
        ->setConfigurationValue('label_display', FALSE);
    $block->save();
    $this->drupalGet('');
    $this->assertSession()
        ->elementNotExists('xpath', "{$block_xpath}/h2");
    $this->assertCacheTags(array_merge($block->getCacheTags(), [
        'block_view',
        'config:block_list',
        'config:system.site',
        'config:views.view.test_view_block',
        'http_response',
        'CACHE_MISS_IF_UNCACHEABLE_HTTP_METHOD:form',
        'rendered',
    ]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.