function DevelQueryDebugTest::testEntityQueryDebugTag
Same name in other branches
- 4.x tests/src/Kernel/DevelQueryDebugTest.php \Drupal\Tests\devel\Kernel\DevelQueryDebugTest::testEntityQueryDebugTag()
Tests devel_query_debug_alter() for entity queries.
File
-
tests/
src/ Kernel/ DevelQueryDebugTest.php, line 101
Class
- DevelQueryDebugTest
- Tests query debug.
Namespace
Drupal\Tests\devel\KernelCode
public function testEntityQueryDebugTag() : void {
// Clear the messages stack.
$this->getDrupalMessages();
// Ensures that no debug message is shown to user without the adequate
// permissions.
$query = \Drupal::entityQuery('user')->accessCheck(FALSE);
$query->addTag('debug');
$query->execute();
$messages = $this->getDrupalMessages();
$this->assertEmpty($messages);
// Ensures that the SQL debug message is shown to user with the adequate
// permissions. We expect only one status message containing the SQL for
// the debugged entity query.
\Drupal::currentUser()->setAccount($this->develUser);
$expected_message = '
SELECT base_table.uid AS uid, base_table.uid AS base_table_uid\\n
FROM\\n
{users} base_table
';
$query = \Drupal::entityQuery('user')->accessCheck(FALSE);
$query->addTag('debug');
$query->execute();
$messages = $this->getDrupalMessages();
$this->assertNotEmpty($messages['status']);
$this->assertCount(1, $messages['status']);
$actual_message = strip_tags($messages['status'][0]);
$actual_message = str_replace([
'"',
"'",
], [
'',
'',
], $actual_message);
$this->assertEquals($expected_message, $actual_message);
}