public function DevelQueryDebugTest::testSelectQueryDebugTag in Devel 8
Same name and namespace in other branches
- 8.3 tests/src/Kernel/DevelQueryDebugTest.php \Drupal\Tests\devel\Kernel\DevelQueryDebugTest::testSelectQueryDebugTag()
- 8.2 tests/src/Kernel/DevelQueryDebugTest.php \Drupal\Tests\devel\Kernel\DevelQueryDebugTest::testSelectQueryDebugTag()
- 4.x tests/src/Kernel/DevelQueryDebugTest.php \Drupal\Tests\devel\Kernel\DevelQueryDebugTest::testSelectQueryDebugTag()
Tests devel_query_debug_alter() for select queries.
File
- tests/
src/ Kernel/ DevelQueryDebugTest.php, line 54
Class
- DevelQueryDebugTest
- Tests query debug.
Namespace
Drupal\Tests\devel\KernelCode
public function testSelectQueryDebugTag() {
// Clear the messages stack.
$this
->getDrupalMessages();
// Ensures that no debug message is shown to user without the adequate
// permissions.
$query = \Drupal::database()
->select('users', 'u');
$query
->fields('u', [
'uid',
]);
$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 query.
\Drupal::currentUser()
->setAccount($this->develUser);
$expected_message = "SELECT u.uid AS uid\nFROM\n{users} u";
$query = \Drupal::database()
->select('users', 'u');
$query
->fields('u', [
'uid',
]);
$query
->addTag('debug');
$query
->execute();
$messages = $this
->getDrupalMessages();
$this
->assertTrue(!empty($messages['status']));
$this
->assertCount(1, $messages['status']);
$this
->assertEquals(strip_tags($messages['status'][0]), $expected_message);
}