Commit b833f73b authored by alexpott's avatar alexpott

Issue #2547357 by sasanikolic, timmillwood, Berdir, mbovan: $error in case of...

Issue #2547357 by sasanikolic, timmillwood, Berdir, mbovan: $error in case of a views query exception
parent 4ba004d2
......@@ -1454,7 +1454,7 @@ function execute(ViewExecutable $view) {
drupal_set_message($e->getMessage(), 'error');
}
else {
throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[$view->storage->id()]: {$e->getMessage()}");
throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[{$view->storage->id()}]: {$e->getMessage()}");
}
}
......
<?php
/**
* @file
* Contains \Drupal\views\Tests\Plugin\ViewsSqlExceptionTest.
*/
namespace Drupal\views\Tests\Plugin;
use Drupal\views\Views;
use Drupal\Core\Database\DatabaseExceptionWrapper;
/**
* Tests the views exception handling.
*
* @group views
*/
class ViewsSqlExceptionTest extends PluginTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_filter');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::viewsData().
*/
protected function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['name']['filter']['id'] = 'test_exception_filter';
return $data;
}
/**
* Test 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', 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);
}
}
}
<?php
/**
* @file
* Contains \Drupal\views_test_data\Plugin\views\filter\FilterExceptionTest.
*/
namespace Drupal\views_test_data\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
/**
* Breaks the query with adding an invalid where expression.
*
* @ViewsFilter("test_exception_filter")
*/
class FilterExceptionTest extends FilterPluginBase {
/**
* {@inheritdoc}
*/
public function query() {
$this->query->addWhereExpression(NULL, "syntax error");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment