global $base_root;
$connection = Database::
getConnection();
// Get a count of how many watchdog entries already exist.
$count =
$connection->
select('watchdog'
)->
countQuery()->
execute()->
fetchField();
$log =
[ 'channel' => 'system',
'message' => 'Log entry added to test the doClearTest clear down.',
'variables' =>
[],
'severity' => RfcLogLevel::NOTICE,
'link' => NULL,
'uid' =>
$this->adminUser->
id(),
'request_uri' =>
$base_root . \Drupal::
request()->
getRequestUri(),
'referer' => \Drupal::
request()->server->
get('HTTP_REFERER'
),
'ip' => '127.0.0.1',
'timestamp' => REQUEST_TIME,
];
// Add a watchdog entry.
$this->container->
get('logger.dblog'
)->
log($log['severity'
],
$log['message'
],
$log);
// Make sure the table count has actually been incremented.
$this->
assertEquals($count + 1,
(int) $connection->
select('watchdog'
)->
countQuery()->
execute()->
fetchField(),
new FormattableMarkup('\Drupal\dblog\Logger\DbLog->log() added an entry to the dblog :count',
[':count' =>
$count]));
// Log in the admin user.
$this->
drupalLogin($this->adminUser
);
// Post in order to clear the database table.