Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Plugin / QueryTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Plugin;
4
5 use Drupal\views\Views;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\views_test_data\Plugin\views\query\QueryTest as QueryTestPlugin;
8
9 /**
10  * Tests query plugins.
11  *
12  * @group views
13  */
14 class QueryTest extends ViewsKernelTestBase {
15
16   /**
17    * Views used by this test.
18    *
19    * @var array
20    */
21   public static $testViews = ['test_view'];
22
23   protected function viewsData() {
24     $data = parent::viewsData();
25     $data['views_test_data']['table']['base']['query_id'] = 'query_test';
26
27     return $data;
28   }
29
30   /**
31    * Tests query plugins.
32    */
33   public function testQuery() {
34     $this->_testInitQuery();
35     $this->_testQueryExecute();
36     $this->queryMethodsTests();
37   }
38
39   /**
40    * Tests the ViewExecutable::initQuery method.
41    */
42   public function _testInitQuery() {
43     $view = Views::getView('test_view');
44     $view->setDisplay();
45
46     $view->initQuery();
47     $this->assertTrue($view->query instanceof QueryTestPlugin, 'Make sure the right query plugin got instantiated.');
48   }
49
50   public function _testQueryExecute() {
51     $view = Views::getView('test_view');
52     $view->setDisplay();
53
54     $view->initQuery();
55     $view->query->setAllItems($this->dataSet());
56
57     $this->executeView($view);
58     $this->assertTrue($view->result, 'Make sure the view result got filled');
59   }
60
61   /**
62    * Test methods provided by the QueryPluginBase.
63    *
64    * @see \Drupal\views\Plugin\views\query\QueryPluginBase
65    */
66   protected function queryMethodsTests() {
67     $view = Views::getView('test_view');
68     $view->setDisplay();
69
70     $view->initQuery();
71     $this->assertFalse($view->query->getLimit(), 'Default to an empty limit.');
72     $rand_number = rand(5, 10);
73     $view->query->setLimit($rand_number);
74     $this->assertEqual($view->query->getLimit(), $rand_number, 'set_limit adapts the amount of items.');
75   }
76
77 }