public function ViewsBlockTest::testBuildWithTitleToken in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsBlockTest::testBuildWithTitleToken()
- 9 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\PluginCode
public function testBuildWithTitleToken() {
$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']);
}