function DbLogTest::testTemporaryUser

Same name in other branches
  1. 8.9.x 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()
  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 838

Class

DbLogTest
Verifies log entries and user access 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');
}

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