3 namespace Drupal\Tests\views\Kernel\Plugin;
5 use Drupal\views\Views;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\views_test_data\Plugin\views\query\QueryTest as QueryTestPlugin;
10 * Tests query plugins.
14 class QueryTest extends ViewsKernelTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_view'];
23 protected function viewsData() {
24 $data = parent::viewsData();
25 $data['views_test_data']['table']['base']['query_id'] = 'query_test';
31 * Tests query plugins.
33 public function testQuery() {
34 $this->_testInitQuery();
35 $this->_testQueryExecute();
36 $this->queryMethodsTests();
40 * Tests the ViewExecutable::initQuery method.
42 public function _testInitQuery() {
43 $view = Views::getView('test_view');
47 $this->assertTrue($view->query instanceof QueryTestPlugin, 'Make sure the right query plugin got instantiated.');
50 public function _testQueryExecute() {
51 $view = Views::getView('test_view');
55 $view->query->setAllItems($this->dataSet());
57 $this->executeView($view);
58 $this->assertTrue($view->result, 'Make sure the view result got filled');
62 * Test methods provided by the QueryPluginBase.
64 * @see \Drupal\views\Plugin\views\query\QueryPluginBase
66 protected function queryMethodsTests() {
67 $view = Views::getView('test_view');
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.');