function DbLogTest::testTemporaryUser

Same name in other branches
  1. 9 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testTemporaryUser()
  2. 8.9.x core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testTemporaryUser()
  3. 11.x 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 834

Class

DbLogTest
Verifies log entries and user access based on permissions.

Namespace

Drupal\Tests\dblog\Functional

Code

public function testTemporaryUser() : void {
    // Create a temporary user.
    $temporary_user = $this->drupalCreateUser();
    $temporary_user_uid = $temporary_user->id();
    // Log in as the admin user.
    $this->drupalLogin($this->adminUser);
    // Generate a single watchdog entry.
    $this->generateLogEntries(1, [
        'user' => $temporary_user,
        'uid' => $temporary_user_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.
    $temporary_user->delete();
    $this->drupalGet('user/' . $temporary_user_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');
}

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