ViewsSqlExceptionTest.php in Drupal 9
File
core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
use Drupal\Core\Database\DatabaseExceptionWrapper;
class ViewsSqlExceptionTest extends ViewsKernelTestBase {
public static $testViews = [
'test_filter',
];
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', [
'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);
}
}