066be3e56daa3c08bae9efdac5b70d398b0af257
[yaffs-website] / web / core / modules / views_ui / src / Tests / QueryTest.php
1 <?php
2
3 namespace Drupal\views_ui\Tests;
4
5 use Drupal\views\Views;
6 use Drupal\views\Entity\View;
7
8 /**
9  * Tests query plugins.
10  *
11  * @group views_ui
12  */
13 class QueryTest extends UITestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_view'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function viewsData() {
26     $data = parent::viewsData();
27     $data['views_test_data']['table']['base']['query_id'] = 'query_test';
28
29     return $data;
30   }
31
32   /**
33    * Tests query plugins settings.
34    */
35   public function testQueryUI() {
36     $view = View::load('test_view');
37     $display = &$view->getDisplay('default');
38     $display['display_options']['query'] = ['type' => 'query_test'];
39     $view->save();
40
41     // Save some query settings.
42     $query_settings_path = "admin/structure/views/nojs/display/test_view/default/query";
43     $random_value = $this->randomMachineName();
44     $this->drupalPostForm($query_settings_path, ['query[options][test_setting]' => $random_value], t('Apply'));
45     $this->drupalPostForm(NULL, [], t('Save'));
46
47     // Check that the settings are saved into the view itself.
48     $view = Views::getView('test_view');
49     $view->initDisplay();
50     $view->initQuery();
51     $this->assertEqual($random_value, $view->query->options['test_setting'], 'Query settings got saved');
52   }
53
54 }