QueryTest.php

Same filename in this branch
  1. 8.9.x core/modules/views/tests/src/Kernel/Plugin/QueryTest.php
  2. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php
  3. 8.9.x core/modules/views_ui/tests/src/Functional/QueryTest.php
  4. 8.9.x core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
Same filename in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/QueryTest.php
  2. 9 core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php
  3. 9 core/modules/views_ui/tests/src/Functional/QueryTest.php
  4. 9 core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
  5. 9 core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php
  6. 10 core/modules/views/tests/src/Kernel/Plugin/QueryTest.php
  7. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php
  8. 10 core/modules/views_ui/tests/src/Functional/QueryTest.php
  9. 10 core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
  10. 10 core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php
  11. 11.x core/modules/views/tests/src/Kernel/Plugin/QueryTest.php
  12. 11.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php
  13. 11.x core/modules/views_ui/tests/src/Functional/QueryTest.php
  14. 11.x core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
  15. 11.x core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php

Namespace

Drupal\Tests\Core\Entity\Query\Sql

File

core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php

View source
<?php

namespace Drupal\Tests\Core\Entity\Query\Sql;

use Drupal\Core\Entity\EntityType;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\Sql\Query;

/**
 * @coversDefaultClass \Drupal\Core\Entity\Query\Sql\Query
 * @group Entity
 */
class QueryTest extends UnitTestCase {
    
    /**
     * The query object.
     *
     * @var \Drupal\Core\Entity\Query\Sql\Query
     */
    protected $query;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() {
        parent::setUp();
        $entity_type = new EntityType([
            'id' => 'example_entity_query',
        ]);
        $conjunction = 'AND';
        $connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
            ->disableOriginalConstructor()
            ->getMock();
        $namespaces = [
            'Drupal\\Core\\Entity\\Query\\Sql',
        ];
        $this->query = new Query($entity_type, $conjunction, $connection, $namespaces);
    }
    
    /**
     * Tests entity query for entity type without base table.
     *
     * @covers ::prepare
     */
    public function testNoBaseTable() {
        $this->expectException(QueryException::class);
        $this->expectExceptionMessage('No base table for example_entity_query, invalid query.');
        $this->query
            ->execute();
    }
    
    /**
     * Tests revision entity query for entity type without revision table.
     *
     * @covers ::prepare
     */
    public function testNoRevisionTable() {
        $this->expectException(QueryException::class);
        $this->expectExceptionMessage('No revision table for example_entity_query, invalid query.');
        $this->query
            ->allRevisions()
            ->execute();
    }

}

Classes

Title Deprecated Summary
QueryTest @coversDefaultClass \Drupal\Core\Entity\Query\Sql\Query @group Entity

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.