function ViewElementTest::testInvalidView

Same name and namespace in other branches
  1. 10 core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest::testInvalidView()
  2. 11.x core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest::testInvalidView()

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

File

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

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);
}

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