You are here

public function ViewsSqlExceptionTest::testSqlException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Plugin/ViewsSqlExceptionTest.php \Drupal\views\Tests\Plugin\ViewsSqlExceptionTest::testSqlException()

Test for the SQL exception.

File

core/modules/views/src/Tests/Plugin/ViewsSqlExceptionTest.php, line 49
Contains \Drupal\views\Tests\Plugin\ViewsSqlExceptionTest.

Class

ViewsSqlExceptionTest
Tests the views exception handling.

Namespace

Drupal\views\Tests\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', array(
    'test_filter' => array(
      'id' => 'test_exception_filter',
      'table' => 'views_test_data',
      'field' => 'name',
      'operator' => '=',
      'value' => 'John',
      'group' => 0,
    ),
  ));
  try {
    $this
      ->executeView($view);
    $this
      ->fail('Expected exception not thrown.');
  } catch (DatabaseExceptionWrapper $e) {
    $exception_assert_message = "Exception in {$view->storage->label()}[{$view->storage->id()}]";
    $this
      ->assertEqual(strstr($e
      ->getMessage(), ':', TRUE), $exception_assert_message);
  }
}