function ViewsBlockTest::testBuildWithTitleToken

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsBlockTest::testBuildWithTitleToken()
  2. 8.9.x core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsBlockTest::testBuildWithTitleToken()
  3. 11.x core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsBlockTest::testBuildWithTitleToken()

Tests that ViewsBlock::build() produces the right output with title tokens.

See also

\Drupal\views\Plugin\Block::build()

File

core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php, line 60

Class

ViewsBlockTest
Tests native behaviors of the block views plugin.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testBuildWithTitleToken() : void {
    $view = Views::getView('test_view_block');
    $view->setDisplay();
    $sorts = [
        'name' => [
            'id' => 'name',
            'field' => 'name',
            'table' => 'views_test_data',
            'plugin_id' => 'standard',
            'order' => 'asc',
        ],
    ];
    // Set the title to the 'name' field in the first row and add a sort order
    // for consistent results on different databases.
    $view->display_handler
        ->setOption('title', '{{ name }}');
    $view->display_handler
        ->setOption('sorts', $sorts);
    $view->save();
    $plugin_definition = [
        'provider' => 'views',
    ];
    $plugin_id = 'views_block:test_view_block-block_1';
    $views_block = ViewsBlock::create($this->container, [], $plugin_id, $plugin_definition);
    $build = $views_block->build();
    $this->assertEquals('George', $build['#title']['#markup']);
}

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