You are here

public function ViewsBlockTest::testBuildWithTitleOverride in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsBlockTest::testBuildWithTitleOverride()

Tests ViewsBlock::build() with a title override.

See also

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

File

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

Class

ViewsBlockTest
Tests native behaviors of the block views plugin.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testBuildWithTitleOverride() {
  $view = Views::getView('test_view_block');
  $view
    ->setDisplay();

  // Add a fixed argument that sets a title and save the view.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('arguments', [
    'name' => [
      'default_action' => 'default',
      'title_enable' => TRUE,
      'title' => 'Overridden title',
      'default_argument_type' => 'fixed',
      'default_argument_options' => [
        'argument' => 'fixed',
      ],
      'validate' => [
        'type' => 'none',
        'fail' => 'not found',
      ],
      'id' => 'name',
      'table' => 'views_test_data',
      'field' => 'name',
      'plugin_id' => 'string',
    ],
  ]);
  $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('Overridden title', $build['#title']['#markup']);
}