Same name in this branch
- 10 core/modules/views_ui/tests/src/Functional/QueryTest.php \Drupal\Tests\views_ui\Functional\QueryTest
- 10 core/tests/Drupal/KernelTests/Core/Database/QueryTest.php \Drupal\KernelTests\Core\Database\QueryTest
- 10 core/modules/views/tests/src/Kernel/Plugin/QueryTest.php \Drupal\Tests\views\Kernel\Plugin\QueryTest
- 10 core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php \Drupal\Tests\Core\Entity\Query\Sql\QueryTest
Same name and namespace in other branches
- 8.9.x core/modules/views/tests/src/Kernel/Plugin/QueryTest.php \Drupal\Tests\views\Kernel\Plugin\QueryTest
- 9 core/modules/views/tests/src/Kernel/Plugin/QueryTest.php \Drupal\Tests\views\Kernel\Plugin\QueryTest
Tests query plugins.
@group views
Hierarchy
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase extends \Drupal\KernelTests\KernelTestBase uses ViewResultAssertionTrait
- class \Drupal\Tests\views\Kernel\Plugin\QueryTest
Expanded class hierarchy of QueryTest
File
- core/
modules/ views/ tests/ src/ Kernel/ Plugin/ QueryTest.php, line 16
Namespace
Drupal\Tests\views\Kernel\PluginView source
class QueryTest extends ViewsKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_view',
];
protected function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['table']['base']['query_id'] = 'query_test';
return $data;
}
/**
* Tests query plugins.
*/
public function testQuery() {
$this
->_testInitQuery();
$this
->_testQueryExecute();
$this
->queryMethodsTests();
}
/**
* Tests the ViewExecutable::initQuery method.
*/
public function _testInitQuery() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view
->initQuery();
$this
->assertInstanceOf(QueryTestPlugin::class, $view->query);
}
public function _testQueryExecute() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view
->initQuery();
$view->query
->setAllItems($this
->dataSet());
$this
->executeView($view);
$this
->assertNotEmpty($view->result, 'Make sure the view result got filled');
}
/**
* Tests methods provided by the QueryPluginBase.
*
* @see \Drupal\views\Plugin\views\query\QueryPluginBase
*/
protected function queryMethodsTests() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view
->initQuery();
$this
->assertNull($view->query
->getLimit(), 'Default to an empty limit.');
$rand_number = rand(5, 10);
$view->query
->setLimit($rand_number);
$this
->assertEquals($rand_number, $view->query
->getLimit(), 'set_limit adapts the amount of items.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryTest:: |
public static | property |
Views used by this test. Overrides ViewsKernelTestBase:: |
|
QueryTest:: |
protected | function | Tests methods provided by the QueryPluginBase. | |
QueryTest:: |
public | function | Tests query plugins. | |
QueryTest:: |
protected | function |
Returns the views data definition. Overrides ViewsKernelTestBase:: |
|
QueryTest:: |
public | function | Tests the ViewExecutable::initQuery method. | |
QueryTest:: |
public | function | ||
ViewResultAssertionTrait:: |
protected | function | Verifies that a result set returned by a View matches expected values. | |
ViewResultAssertionTrait:: |
protected | function | Performs View result assertions. | |
ViewResultAssertionTrait:: |
protected | function | Verifies that a result set returned by a View differs from certain values. | |
ViewsKernelTestBase:: |
protected static | property | 94 | |
ViewsKernelTestBase:: |
protected | function | Returns a very simple test dataset. | 8 |
ViewsKernelTestBase:: |
protected | function | Executes a view. | |
ViewsKernelTestBase:: |
protected | function | Orders a nested array containing a result set based on a given column. | |
ViewsKernelTestBase:: |
protected | function | Returns the schema definition. | 6 |
ViewsKernelTestBase:: |
protected | function | 66 | |
ViewsKernelTestBase:: |
protected | function | Sets up the configuration and schema of views and views_test_data modules. | 7 |