function ViewsSqlExceptionTest::testSqlException

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

Tests for the SQL exception.

File

core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php, line 35

Class

ViewsSqlExceptionTest
Tests the views exception handling.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testSqlException() : void {
    $view = Views::getView('test_filter');
    $view->initDisplay();
    // Adding a filter that will result in an invalid query.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'test_filter' => [
            'id' => 'test_exception_filter',
            'table' => 'views_test_data',
            'field' => 'name',
            'operator' => '=',
            'value' => 'John',
            'group' => 0,
        ],
    ]);
    $this->expectException(DatabaseExceptionWrapper::class);
    $this->expectExceptionMessageMatches('/^Exception in Test filters\\[test_filter\\]:/');
    $this->executeView($view);
}

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