You are here

class ViewsSqlExceptionTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsSqlExceptionTest
  2. 9 core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php \Drupal\Tests\views\Kernel\Plugin\ViewsSqlExceptionTest

Tests the views exception handling.

@group views

Hierarchy

  • class \Drupal\Tests\views\Kernel\Plugin\ViewsSqlExceptionTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase

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

}

Members