Same name in this branch
  1. 10 core/modules/views_ui/tests/src/Functional/QueryTest.php \Drupal\Tests\views_ui\Functional\QueryTest
  2. 10 core/tests/Drupal/KernelTests/Core/Database/QueryTest.php \Drupal\KernelTests\Core\Database\QueryTest
  3. 10 core/modules/views/tests/src/Kernel/Plugin/QueryTest.php \Drupal\Tests\views\Kernel\Plugin\QueryTest
  4. 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
  1. 8.9.x core/modules/views/tests/src/Kernel/Plugin/QueryTest.php \Drupal\Tests\views\Kernel\Plugin\QueryTest
  2. 9 core/modules/views/tests/src/Kernel/Plugin/QueryTest.php \Drupal\Tests\views\Kernel\Plugin\QueryTest

Tests query plugins.

@group views

Hierarchy

Expanded class hierarchy of QueryTest

File

core/modules/views/tests/src/Kernel/Plugin/QueryTest.php, line 16

Namespace

Drupal\Tests\views\Kernel\Plugin
View 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

Namesort descending Modifiers Type Description Overrides
QueryTest::$testViews public static property Views used by this test. Overrides ViewsKernelTestBase::$testViews
QueryTest::queryMethodsTests protected function Tests methods provided by the QueryPluginBase.
QueryTest::testQuery public function Tests query plugins.
QueryTest::viewsData protected function Returns the views data definition. Overrides ViewsKernelTestBase::viewsData
QueryTest::_testInitQuery public function Tests the ViewExecutable::initQuery method.
QueryTest::_testQueryExecute public function
ViewResultAssertionTrait::assertIdenticalResultset protected function Verifies that a result set returned by a View matches expected values.
ViewResultAssertionTrait::assertIdenticalResultsetHelper protected function Performs View result assertions.
ViewResultAssertionTrait::assertNotIdenticalResultset protected function Verifies that a result set returned by a View differs from certain values.
ViewsKernelTestBase::$modules protected static property 94
ViewsKernelTestBase::dataSet protected function Returns a very simple test dataset. 8
ViewsKernelTestBase::executeView protected function Executes a view.
ViewsKernelTestBase::orderResultSet protected function Orders a nested array containing a result set based on a given column.
ViewsKernelTestBase::schemaDefinition protected function Returns the schema definition. 6
ViewsKernelTestBase::setUp protected function 66
ViewsKernelTestBase::setUpFixtures protected function Sets up the configuration and schema of views and views_test_data modules. 7