ViewsSqlExceptionTest.php in Zircon Profile 8
File
core/modules/views/src/Tests/Plugin/ViewsSqlExceptionTest.php
View source
<?php
namespace Drupal\views\Tests\Plugin;
use Drupal\views\Views;
use Drupal\Core\Database\DatabaseExceptionWrapper;
class ViewsSqlExceptionTest extends PluginTestBase {
public static $testViews = array(
'test_filter',
);
protected function setUp() {
parent::setUp();
$this
->enableViewsTestModule();
}
protected function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['name']['filter']['id'] = 'test_exception_filter';
return $data;
}
public function testSqlException() {
$view = Views::getView('test_filter');
$view
->initDisplay();
$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);
}
}
}