class ViewsSqlExceptionTest

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsSqlExceptionTest
  2. 10 core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsSqlExceptionTest
  3. 8.9.x core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsSqlExceptionTest

Tests the views exception handling.

@group views

Hierarchy

Expanded class hierarchy of ViewsSqlExceptionTest

File

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

Namespace

Drupal\Tests\views\Kernel\Plugin
View source
class ViewsSqlExceptionTest extends ViewsKernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'test_filter',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['name']['filter']['id'] = 'test_exception_filter';
    return $data;
  }
  
  /**
   * Tests for the SQL exception.
   */
  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->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.