Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Functional / Plugin / ViewsSqlExceptionTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Plugin;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Views;
7 use Drupal\Core\Database\DatabaseExceptionWrapper;
8
9 /**
10  * Tests the views exception handling.
11  *
12  * @group views
13  */
14 class ViewsSqlExceptionTest extends ViewTestBase {
15
16   /**
17    * Views used by this test.
18    *
19    * @var array
20    */
21   public static $testViews = ['test_filter'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp($import_test_views = TRUE) {
27     parent::setUp($import_test_views);
28
29     $this->enableViewsTestModule();
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function viewsData() {
36     $data = parent::viewsData();
37     $data['views_test_data']['name']['filter']['id'] = 'test_exception_filter';
38
39     return $data;
40   }
41
42   /**
43    * Test for the SQL exception.
44    */
45   public function testSqlException() {
46     $view = Views::getView('test_filter');
47     $view->initDisplay();
48
49     // Adding a filter that will result in an invalid query.
50     $view->displayHandlers->get('default')->overrideOption('filters', [
51       'test_filter' => [
52         'id' => 'test_exception_filter',
53         'table' => 'views_test_data',
54         'field' => 'name',
55         'operator' => '=',
56         'value' => 'John',
57         'group' => 0,
58       ],
59     ]);
60
61     try {
62       $this->executeView($view);
63       $this->fail('Expected exception not thrown.');
64     }
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);
68     }
69   }
70
71 }