You are here

public function ViewElementTest::testInvalidView in Drupal 9

Tests that an exception is thrown when an invalid View is passed.

File

core/modules/views/tests/src/Kernel/ViewElementTest.php, line 136

Class

ViewElementTest
Tests the view render element.

Namespace

Drupal\Tests\views\Kernel

Code

public function testInvalidView() {
  $renderer = $this->container
    ->get('renderer');
  $render_element = [
    '#type' => 'view',
    '#name' => 'invalid_view_name',
    '#embed' => FALSE,
  ];
  $this
    ->expectException(ViewRenderElementException::class);
  $this
    ->expectExceptionMessage("Invalid View name ({$render_element['#name']}) given.");
  $renderer
    ->renderRoot($render_element);
}