You are here

public function ViewsSqlExceptionTest::testSqlException in Drupal 8

Same name and namespace in other branches
  1. 9 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 33

Class

ViewsSqlExceptionTest
Tests the views exception handling.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testSqlException() {
  $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
    ->expectExceptionMessageRegExp('/^Exception in Test filters\\[test_filter\\]:/');
  $this
    ->executeView($view);
}