You are here

public function DbLogTest::testTemporaryUser in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testTemporaryUser()
  2. 10 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testTemporaryUser()

Tests that the details page displays correctly for a temporary user.

File

core/modules/dblog/tests/src/Functional/DbLogTest.php, line 814

Class

DbLogTest
Generate events and verify dblog entries; verify user access to log reports based on permissions.

Namespace

Drupal\Tests\dblog\Functional

Code

public function testTemporaryUser() {

  // Create a temporary user.
  $tempuser = $this
    ->drupalCreateUser();
  $tempuser_uid = $tempuser
    ->id();

  // Log in as the admin user.
  $this
    ->drupalLogin($this->adminUser);

  // Generate a single watchdog entry.
  $this
    ->generateLogEntries(1, [
    'user' => $tempuser,
    'uid' => $tempuser_uid,
  ]);
  $query = Database::getConnection()
    ->select('watchdog');
  $query
    ->addExpression('MAX([wid])');
  $wid = $query
    ->execute()
    ->fetchField();

  // Check if the full message displays on the details page.
  $this
    ->drupalGet('admin/reports/dblog/event/' . $wid);
  $this
    ->assertSession()
    ->pageTextContains('Dblog test log message');

  // Delete the user.
  $tempuser
    ->delete();
  $this
    ->drupalGet('user/' . $tempuser_uid);
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Check if the full message displays on the details page.
  $this
    ->drupalGet('admin/reports/dblog/event/' . $wid);
  $this
    ->assertSession()
    ->pageTextContains('Dblog test log message');
}