function ModuleTestBase::assertLogMessage

Same name in this branch
  1. 8.9.x core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertLogMessage()
Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertLogMessage()
  2. 10 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertLogMessage()
  3. 11.x core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertLogMessage()

Verify a log entry was entered for a module's status change.

Parameters

$type: The category to which this message belongs.

$message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.

$variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.

$severity: The severity of the message, as per RFC 3164.

$link: A link to associate with the message.

2 calls to ModuleTestBase::assertLogMessage()
InstallUninstallTest::assertSuccessfulUninstall in core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
Uninstalls a module and asserts that it was done correctly.
InstallUninstallTest::testInstallUninstall in core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
Tests that a fixed set of modules can be installed and uninstalled.

File

core/modules/system/tests/src/Functional/Module/ModuleTestBase.php, line 192

Class

ModuleTestBase
Helper class for module test cases.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function assertLogMessage($type, $message, $variables = [], $severity = RfcLogLevel::NOTICE, $link = '') {
    $count = Database::getConnection()->select('watchdog', 'w')
        ->condition('type', $type)
        ->condition('message', $message)
        ->condition('variables', serialize($variables))
        ->condition('severity', $severity)
        ->condition('link', $link)
        ->countQuery()
        ->execute()
        ->fetchField();
    $this->assertTrue($count > 0, new FormattableMarkup('watchdog table contains @count rows for @message', [
        '@count' => $count,
        '@message' => new FormattableMarkup($message, $variables),
    ]));
}

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