You are here

public function DevelQueryDebugTest::testEntityQueryDebugTag in Devel 8.3

Same name and namespace in other branches
  1. 8 tests/src/Kernel/DevelQueryDebugTest.php \Drupal\Tests\devel\Kernel\DevelQueryDebugTest::testEntityQueryDebugTag()
  2. 8.2 tests/src/Kernel/DevelQueryDebugTest.php \Drupal\Tests\devel\Kernel\DevelQueryDebugTest::testEntityQueryDebugTag()
  3. 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 95

Class

DevelQueryDebugTest
Tests query debug.

Namespace

Drupal\Tests\devel\Kernel

Code

public function testEntityQueryDebugTag() {

  // Clear the messages stack.
  $this
    ->getDrupalMessages();

  // Ensures that no debug message is shown to user without the adequate
  // permissions.
  $query = \Drupal::entityQuery('user');
  $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\nFROM\n{users} base_table";
  $query = \Drupal::entityQuery('user');
  $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);
}