3 namespace Drupal\Tests\views\Functional\Plugin;
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Views;
7 use Drupal\Core\Database\DatabaseExceptionWrapper;
10 * Tests the views exception handling.
14 class ViewsSqlExceptionTest extends ViewTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_filter'];
26 protected function setUp($import_test_views = TRUE) {
27 parent::setUp($import_test_views);
29 $this->enableViewsTestModule();
35 protected function viewsData() {
36 $data = parent::viewsData();
37 $data['views_test_data']['name']['filter']['id'] = 'test_exception_filter';
43 * Test for the SQL exception.
45 public function testSqlException() {
46 $view = Views::getView('test_filter');
49 // Adding a filter that will result in an invalid query.
50 $view->displayHandlers->get('default')->overrideOption('filters', [
52 'id' => 'test_exception_filter',
53 'table' => 'views_test_data',
62 $this->executeView($view);
63 $this->fail('Expected exception not thrown.');
65 catch (DatabaseExceptionWrapper $e) {
66 $exception_assert_message = "Exception in {$view->storage->label()}[{$view->storage->id()}]";
67 $this->assertEqual(strstr($e->getMessage(), ':', TRUE), $exception_assert_message);