function TemporaryQueryTestBase::testTemporaryQuery

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/TemporaryQueryTestBase.php \Drupal\KernelTests\Core\Database\TemporaryQueryTestBase::testTemporaryQuery()

Confirms that temporary tables work.

3 calls to TemporaryQueryTestBase::testTemporaryQuery()
TemporaryQueryTest::testTemporaryQuery in core/modules/sqlite/tests/src/Kernel/sqlite/TemporaryQueryTest.php
Confirms that temporary tables work.
TemporaryQueryTest::testTemporaryQuery in core/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php
Confirms that temporary tables work.
TemporaryQueryTest::testTemporaryQuery in core/modules/pgsql/tests/src/Kernel/pgsql/TemporaryQueryTest.php
Confirms that temporary tables work.
3 methods override TemporaryQueryTestBase::testTemporaryQuery()
TemporaryQueryTest::testTemporaryQuery in core/modules/sqlite/tests/src/Kernel/sqlite/TemporaryQueryTest.php
Confirms that temporary tables work.
TemporaryQueryTest::testTemporaryQuery in core/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php
Confirms that temporary tables work.
TemporaryQueryTest::testTemporaryQuery in core/modules/pgsql/tests/src/Kernel/pgsql/TemporaryQueryTest.php
Confirms that temporary tables work.

File

core/tests/Drupal/KernelTests/Core/Database/TemporaryQueryTestBase.php, line 33

Class

TemporaryQueryTestBase
Tests the temporary query functionality.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testTemporaryQuery() : void {
    $connection = $this->getConnection();
    // Now try to run two temporary queries in the same request.
    $table_name_test = $connection->queryTemporary('SELECT [name] FROM {test}', []);
    $table_name_task = $connection->queryTemporary('SELECT [pid] FROM {test_task}', []);
    $this->assertEquals($this->countTableRows('test'), $this->countTableRows($table_name_test), 'A temporary table was created successfully in this request.');
    $this->assertEquals($this->countTableRows('test_task'), $this->countTableRows($table_name_task), 'A second temporary table was created successfully in this request.');
    // Check that leading whitespace and comments do not cause problems
    // in the modified query.
    $sql = "\n      -- Let's select some rows into a temporary table\n      SELECT [name] FROM {test}\n    ";
    $table_name_test = $connection->queryTemporary($sql, []);
    $this->assertEquals($this->countTableRows('test'), $this->countTableRows($table_name_test), 'Leading white space and comments do not interfere with temporary table creation.');
}

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