updated core and modules
This commit is contained in:
@@ -94,7 +94,7 @@ class DbLogController extends ControllerBase {
|
||||
* An array of log level classes.
|
||||
*/
|
||||
public static function getLogLevelClassMap() {
|
||||
return array(
|
||||
return [
|
||||
RfcLogLevel::DEBUG => 'dblog-debug',
|
||||
RfcLogLevel::INFO => 'dblog-info',
|
||||
RfcLogLevel::NOTICE => 'dblog-notice',
|
||||
@@ -103,7 +103,7 @@ class DbLogController extends ControllerBase {
|
||||
RfcLogLevel::CRITICAL => 'dblog-critical',
|
||||
RfcLogLevel::ALERT => 'dblog-alert',
|
||||
RfcLogLevel::EMERGENCY => 'dblog-emergency',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,47 +115,46 @@ class DbLogController extends ControllerBase {
|
||||
* @return array
|
||||
* A render array as expected by drupal_render().
|
||||
*
|
||||
* @see dblog_clear_log_form()
|
||||
* @see dblog_event()
|
||||
* @see Drupal\dblog\Form\DblogClearLogConfirmForm
|
||||
* @see Drupal\dblog\Controller\DbLogController::eventDetails()
|
||||
*/
|
||||
public function overview() {
|
||||
|
||||
$filter = $this->buildFilterQuery();
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
|
||||
$classes = static::getLogLevelClassMap();
|
||||
|
||||
$this->moduleHandler->loadInclude('dblog', 'admin.inc');
|
||||
|
||||
$build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogFilterForm');
|
||||
$build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogClearLogForm');
|
||||
|
||||
$header = array(
|
||||
$header = [
|
||||
// Icon column.
|
||||
'',
|
||||
array(
|
||||
[
|
||||
'data' => $this->t('Type'),
|
||||
'field' => 'w.type',
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
|
||||
array(
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM]],
|
||||
[
|
||||
'data' => $this->t('Date'),
|
||||
'field' => 'w.wid',
|
||||
'sort' => 'desc',
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW]],
|
||||
$this->t('Message'),
|
||||
array(
|
||||
[
|
||||
'data' => $this->t('User'),
|
||||
'field' => 'ufd.name',
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
|
||||
array(
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM]],
|
||||
[
|
||||
'data' => $this->t('Operations'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW]],
|
||||
];
|
||||
|
||||
$query = $this->database->select('watchdog', 'w')
|
||||
->extend('\Drupal\Core\Database\Query\PagerSelectExtender')
|
||||
->extend('\Drupal\Core\Database\Query\TableSortExtender');
|
||||
$query->fields('w', array(
|
||||
$query->fields('w', [
|
||||
'wid',
|
||||
'uid',
|
||||
'severity',
|
||||
@@ -164,7 +163,7 @@ class DbLogController extends ControllerBase {
|
||||
'message',
|
||||
'variables',
|
||||
'link',
|
||||
));
|
||||
]);
|
||||
$query->leftJoin('users_field_data', 'ufd', 'w.uid = ufd.uid');
|
||||
|
||||
if (!empty($filter['where'])) {
|
||||
@@ -182,45 +181,45 @@ class DbLogController extends ControllerBase {
|
||||
$log_text = Unicode::truncate($title, 56, TRUE, TRUE);
|
||||
// The link generator will escape any unsafe HTML entities in the final
|
||||
// text.
|
||||
$message = $this->l($log_text, new Url('dblog.event', array('event_id' => $dblog->wid), array(
|
||||
'attributes' => array(
|
||||
$message = $this->l($log_text, new Url('dblog.event', ['event_id' => $dblog->wid], [
|
||||
'attributes' => [
|
||||
// Provide a title for the link for useful hover hints. The
|
||||
// Attribute object will escape any unsafe HTML entities in the
|
||||
// final text.
|
||||
'title' => $title,
|
||||
),
|
||||
)));
|
||||
],
|
||||
]));
|
||||
}
|
||||
$username = array(
|
||||
$username = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $this->userStorage->load($dblog->uid),
|
||||
);
|
||||
$rows[] = array(
|
||||
'data' => array(
|
||||
];
|
||||
$rows[] = [
|
||||
'data' => [
|
||||
// Cells.
|
||||
array('class' => array('icon')),
|
||||
['class' => ['icon']],
|
||||
$this->t($dblog->type),
|
||||
$this->dateFormatter->format($dblog->timestamp, 'short'),
|
||||
$message,
|
||||
array('data' => $username),
|
||||
array('data' => array('#markup' => $dblog->link)),
|
||||
),
|
||||
['data' => $username],
|
||||
['data' => ['#markup' => $dblog->link]],
|
||||
],
|
||||
// Attributes for table row.
|
||||
'class' => array(Html::getClass('dblog-' . $dblog->type), $classes[$dblog->severity]),
|
||||
);
|
||||
'class' => [Html::getClass('dblog-' . $dblog->type), $classes[$dblog->severity]],
|
||||
];
|
||||
}
|
||||
|
||||
$build['dblog_table'] = array(
|
||||
$build['dblog_table'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')),
|
||||
'#attributes' => ['id' => 'admin-dblog', 'class' => ['admin-dblog']],
|
||||
'#empty' => $this->t('No log messages available.'),
|
||||
'#attached' => array(
|
||||
'library' => array('dblog/drupal.dblog'),
|
||||
),
|
||||
);
|
||||
$build['dblog_pager'] = array('#type' => 'pager');
|
||||
'#attached' => [
|
||||
'library' => ['dblog/drupal.dblog'],
|
||||
],
|
||||
];
|
||||
$build['dblog_pager'] = ['#type' => 'pager'];
|
||||
|
||||
return $build;
|
||||
|
||||
@@ -237,60 +236,60 @@ class DbLogController extends ControllerBase {
|
||||
* format expected by drupal_render();
|
||||
*/
|
||||
public function eventDetails($event_id) {
|
||||
$build = array();
|
||||
if ($dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', array(':id' => $event_id))->fetchObject()) {
|
||||
$build = [];
|
||||
if ($dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', [':id' => $event_id])->fetchObject()) {
|
||||
$severity = RfcLogLevel::getLevels();
|
||||
$message = $this->formatMessage($dblog);
|
||||
$username = array(
|
||||
$username = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser(),
|
||||
);
|
||||
$rows = array(
|
||||
array(
|
||||
array('data' => $this->t('Type'), 'header' => TRUE),
|
||||
];
|
||||
$rows = [
|
||||
[
|
||||
['data' => $this->t('Type'), 'header' => TRUE],
|
||||
$this->t($dblog->type),
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Date'), 'header' => TRUE),
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Date'), 'header' => TRUE],
|
||||
$this->dateFormatter->format($dblog->timestamp, 'long'),
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('User'), 'header' => TRUE),
|
||||
array('data' => $username),
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Location'), 'header' => TRUE),
|
||||
],
|
||||
[
|
||||
['data' => $this->t('User'), 'header' => TRUE],
|
||||
['data' => $username],
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Location'), 'header' => TRUE],
|
||||
$this->l($dblog->location, $dblog->location ? Url::fromUri($dblog->location) : Url::fromRoute('<none>')),
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Referrer'), 'header' => TRUE),
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Referrer'), 'header' => TRUE],
|
||||
$this->l($dblog->referer, $dblog->referer ? Url::fromUri($dblog->referer) : Url::fromRoute('<none>')),
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Message'), 'header' => TRUE),
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Message'), 'header' => TRUE],
|
||||
$message,
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Severity'), 'header' => TRUE),
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Severity'), 'header' => TRUE],
|
||||
$severity[$dblog->severity],
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Hostname'), 'header' => TRUE),
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Hostname'), 'header' => TRUE],
|
||||
$dblog->hostname,
|
||||
),
|
||||
array(
|
||||
array('data' => $this->t('Operations'), 'header' => TRUE),
|
||||
array('data' => array('#markup' => $dblog->link)),
|
||||
),
|
||||
);
|
||||
$build['dblog_table'] = array(
|
||||
],
|
||||
[
|
||||
['data' => $this->t('Operations'), 'header' => TRUE],
|
||||
['data' => ['#markup' => $dblog->link]],
|
||||
],
|
||||
];
|
||||
$build['dblog_table'] = [
|
||||
'#type' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#attributes' => array('class' => array('dblog-event')),
|
||||
'#attached' => array(
|
||||
'library' => array('dblog/drupal.dblog'),
|
||||
),
|
||||
);
|
||||
'#attributes' => ['class' => ['dblog-event']],
|
||||
'#attached' => [
|
||||
'library' => ['dblog/drupal.dblog'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $build;
|
||||
@@ -312,9 +311,9 @@ class DbLogController extends ControllerBase {
|
||||
$filters = dblog_filters();
|
||||
|
||||
// Build query.
|
||||
$where = $args = array();
|
||||
$where = $args = [];
|
||||
foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) {
|
||||
$filter_where = array();
|
||||
$filter_where = [];
|
||||
foreach ($filter as $value) {
|
||||
$filter_where[] = $filters[$key]['where'];
|
||||
$args[] = $value;
|
||||
@@ -325,10 +324,10 @@ class DbLogController extends ControllerBase {
|
||||
}
|
||||
$where = !empty($where) ? implode(' AND ', $where) : '';
|
||||
|
||||
return array(
|
||||
return [
|
||||
'where' => $where,
|
||||
'args' => $args,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,14 +343,18 @@ class DbLogController extends ControllerBase {
|
||||
*/
|
||||
public function formatMessage($row) {
|
||||
// Check for required properties.
|
||||
if (isset($row->message) && isset($row->variables)) {
|
||||
if (isset($row->message, $row->variables)) {
|
||||
$variables = @unserialize($row->variables);
|
||||
// Messages without variables or user specified text.
|
||||
if ($row->variables === 'N;') {
|
||||
if ($variables === NULL) {
|
||||
$message = Xss::filterAdmin($row->message);
|
||||
}
|
||||
elseif (!is_array($variables)) {
|
||||
$message = $this->t('Log data is corrupted and cannot be unserialized: @message', ['@message' => Xss::filterAdmin($row->message)]);
|
||||
}
|
||||
// Message to translate with injected variables.
|
||||
else {
|
||||
$message = $this->t(Xss::filterAdmin($row->message), unserialize($row->variables));
|
||||
$message = $this->t(Xss::filterAdmin($row->message), $variables);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -366,8 +369,6 @@ class DbLogController extends ControllerBase {
|
||||
* Messages are not truncated on this page because events detailed herein do
|
||||
* not have links to a detailed view.
|
||||
*
|
||||
* Use one of the above *Report() methods.
|
||||
*
|
||||
* @param string $type
|
||||
* Type of database log events to display (e.g., 'search').
|
||||
*
|
||||
@@ -375,10 +376,10 @@ class DbLogController extends ControllerBase {
|
||||
* A build array in the format expected by drupal_render().
|
||||
*/
|
||||
public function topLogMessages($type) {
|
||||
$header = array(
|
||||
array('data' => $this->t('Count'), 'field' => 'count', 'sort' => 'desc'),
|
||||
array('data' => $this->t('Message'), 'field' => 'message'),
|
||||
);
|
||||
$header = [
|
||||
['data' => $this->t('Count'), 'field' => 'count', 'sort' => 'desc'],
|
||||
['data' => $this->t('Message'), 'field' => 'message'],
|
||||
];
|
||||
|
||||
$count_query = $this->database->select('watchdog');
|
||||
$count_query->addExpression('COUNT(DISTINCT(message))');
|
||||
@@ -389,7 +390,7 @@ class DbLogController extends ControllerBase {
|
||||
->extend('\Drupal\Core\Database\Query\TableSortExtender');
|
||||
$query->addExpression('COUNT(wid)', 'count');
|
||||
$query = $query
|
||||
->fields('w', array('message', 'variables'))
|
||||
->fields('w', ['message', 'variables'])
|
||||
->condition('w.type', $type)
|
||||
->groupBy('message')
|
||||
->groupBy('variables')
|
||||
@@ -398,23 +399,23 @@ class DbLogController extends ControllerBase {
|
||||
$query->setCountQuery($count_query);
|
||||
$result = $query->execute();
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
foreach ($result as $dblog) {
|
||||
if ($message = $this->formatMessage($dblog)) {
|
||||
$rows[] = array($dblog->count, $message);
|
||||
$rows[] = [$dblog->count, $message];
|
||||
}
|
||||
}
|
||||
|
||||
$build['dblog_top_table'] = array(
|
||||
$build['dblog_top_table'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => $this->t('No log messages available.'),
|
||||
'#attached' => array(
|
||||
'library' => array('dblog/drupal.dblog'),
|
||||
),
|
||||
);
|
||||
$build['dblog_top_pager'] = array('#type' => 'pager');
|
||||
'#attached' => [
|
||||
'library' => ['dblog/drupal.dblog'],
|
||||
],
|
||||
];
|
||||
$build['dblog_top_pager'] = ['#type' => 'pager'];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ class DblogClearLogConfirmForm extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$_SESSION['dblog_overview_filter'] = array();
|
||||
$this->connection->delete('watchdog')->execute();
|
||||
$_SESSION['dblog_overview_filter'] = [];
|
||||
$this->connection->truncate('watchdog')->execute();
|
||||
drupal_set_message($this->t('Database log cleared.'));
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
@@ -23,39 +23,39 @@ class DblogFilterForm extends FormBase {
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$filters = dblog_filters();
|
||||
|
||||
$form['filters'] = array(
|
||||
$form['filters'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Filter log messages'),
|
||||
'#open' => !empty($_SESSION['dblog_overview_filter']),
|
||||
);
|
||||
'#open' => TRUE,
|
||||
];
|
||||
foreach ($filters as $key => $filter) {
|
||||
$form['filters']['status'][$key] = array(
|
||||
$form['filters']['status'][$key] = [
|
||||
'#title' => $filter['title'],
|
||||
'#type' => 'select',
|
||||
'#multiple' => TRUE,
|
||||
'#size' => 8,
|
||||
'#options' => $filter['options'],
|
||||
);
|
||||
];
|
||||
if (!empty($_SESSION['dblog_overview_filter'][$key])) {
|
||||
$form['filters']['status'][$key]['#default_value'] = $_SESSION['dblog_overview_filter'][$key];
|
||||
}
|
||||
}
|
||||
|
||||
$form['filters']['actions'] = array(
|
||||
$form['filters']['actions'] = [
|
||||
'#type' => 'actions',
|
||||
'#attributes' => array('class' => array('container-inline')),
|
||||
);
|
||||
$form['filters']['actions']['submit'] = array(
|
||||
'#attributes' => ['class' => ['container-inline']],
|
||||
];
|
||||
$form['filters']['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Filter'),
|
||||
);
|
||||
];
|
||||
if (!empty($_SESSION['dblog_overview_filter'])) {
|
||||
$form['filters']['actions']['reset'] = array(
|
||||
$form['filters']['actions']['reset'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Reset'),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::resetForm'),
|
||||
);
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::resetForm'],
|
||||
];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class DblogFilterForm extends FormBase {
|
||||
* The current state of the form.
|
||||
*/
|
||||
public function resetForm(array &$form, FormStateInterface $form_state) {
|
||||
$_SESSION['dblog_overview_filter'] = array();
|
||||
$_SESSION['dblog_overview_filter'] = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DbLog implements LoggerInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function log($level, $message, array $context = array()) {
|
||||
public function log($level, $message, array $context = []) {
|
||||
// Remove any backtraces since they may contain an unserializable variable.
|
||||
unset($context['backtrace']);
|
||||
|
||||
@@ -64,7 +64,7 @@ class DbLog implements LoggerInterface {
|
||||
try {
|
||||
$this->connection
|
||||
->insert('watchdog')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'uid' => $context['uid'],
|
||||
'type' => Unicode::substr($context['channel'], 0, 64),
|
||||
'message' => $message,
|
||||
@@ -75,7 +75,7 @@ class DbLog implements LoggerInterface {
|
||||
'referer' => $context['referer'],
|
||||
'hostname' => Unicode::substr($context['ip'], 0, 128),
|
||||
'timestamp' => $context['timestamp'],
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
||||
@@ -38,13 +38,13 @@ class DBLogResource extends ResourceBase {
|
||||
*/
|
||||
public function get($id = NULL) {
|
||||
if ($id) {
|
||||
$record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", array(':wid' => $id))
|
||||
$record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", [':wid' => $id])
|
||||
->fetchAssoc();
|
||||
if (!empty($record)) {
|
||||
return new ResourceResponse($record);
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException(t('Log entry with ID @id was not found', array('@id' => $id)));
|
||||
throw new NotFoundHttpException(t('Log entry with ID @id was not found', ['@id' => $id]));
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException(t('No log entry ID was provided'));
|
||||
|
||||
@@ -34,7 +34,7 @@ class DblogMessage extends FieldPluginBase {
|
||||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['replace_variables'] = array('default' => TRUE);
|
||||
$options['replace_variables'] = ['default' => TRUE];
|
||||
|
||||
return $options;
|
||||
}
|
||||
@@ -45,11 +45,11 @@ class DblogMessage extends FieldPluginBase {
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
|
||||
$form['replace_variables'] = array(
|
||||
$form['replace_variables'] = [
|
||||
'#title' => $this->t('Replace variables'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['replace_variables'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@ class DbLogTest extends WebTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('dblog', 'node', 'forum', 'help', 'block');
|
||||
public static $modules = ['dblog', 'node', 'forum', 'help', 'block'];
|
||||
|
||||
/**
|
||||
* A user with some relevant administrative permissions.
|
||||
@@ -47,8 +47,8 @@ class DbLogTest extends WebTestBase {
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
// Create users with specific permissions.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'access site reports', 'administer users'));
|
||||
$this->webUser = $this->drupalCreateUser(array());
|
||||
$this->adminUser = $this->drupalCreateUser(['administer site configuration', 'access administration pages', 'access site reports', 'administer users']);
|
||||
$this->webUser = $this->drupalCreateUser([]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ class DbLogTest extends WebTestBase {
|
||||
* Database Logging module functionality through both the admin and user
|
||||
* interfaces.
|
||||
*/
|
||||
function testDbLog() {
|
||||
public function testDbLog() {
|
||||
// Log in the admin user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
@@ -70,8 +70,8 @@ class DbLogTest extends WebTestBase {
|
||||
$this->verifyBreadcrumbs();
|
||||
$this->verifyLinkEscaping();
|
||||
// Verify the overview table sorting.
|
||||
$orders = array('Date', 'Type', 'User');
|
||||
$sorts = array('asc', 'desc');
|
||||
$orders = ['Date', 'Type', 'User'];
|
||||
$sorts = ['asc', 'desc'];
|
||||
foreach ($orders as $order) {
|
||||
foreach ($sorts as $sort) {
|
||||
$this->verifySort($sort, $order);
|
||||
@@ -124,14 +124,14 @@ class DbLogTest extends WebTestBase {
|
||||
*/
|
||||
private function verifyRowLimit($row_limit) {
|
||||
// Change the database log row limit.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['dblog_row_limit'] = $row_limit;
|
||||
$this->drupalPostForm('admin/config/development/logging', $edit, t('Save configuration'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Check row limit variable.
|
||||
$current_limit = $this->config('dblog.settings')->get('row_limit');
|
||||
$this->assertTrue($current_limit == $row_limit, format_string('[Cache] Row limit variable of @count equals row limit of @limit', array('@count' => $current_limit, '@limit' => $row_limit)));
|
||||
$this->assertTrue($current_limit == $row_limit, format_string('[Cache] Row limit variable of @count equals row limit of @limit', ['@count' => $current_limit, '@limit' => $row_limit]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,14 +145,39 @@ class DbLogTest extends WebTestBase {
|
||||
$this->generateLogEntries($row_limit + 10);
|
||||
// Verify that the database log row count exceeds the row limit.
|
||||
$count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
|
||||
$this->assertTrue($count > $row_limit, format_string('Dblog row count of @count exceeds row limit of @limit', array('@count' => $count, '@limit' => $row_limit)));
|
||||
$this->assertTrue($count > $row_limit, format_string('Dblog row count of @count exceeds row limit of @limit', ['@count' => $count, '@limit' => $row_limit]));
|
||||
|
||||
// Get the number of enabled modules. Cron adds a log entry for each module.
|
||||
$list = \Drupal::moduleHandler()->getImplementations('cron');
|
||||
$module_count = count($list);
|
||||
$cron_detailed_count = $this->runCron();
|
||||
$this->assertTrue($cron_detailed_count == $module_count + 2, format_string('Cron added @count of @expected new log entries', ['@count' => $cron_detailed_count, '@expected' => $module_count + 2]));
|
||||
|
||||
// Test disabling of detailed cron logging.
|
||||
$this->config('system.cron')->set('logging', 0)->save();
|
||||
$cron_count = $this->runCron();
|
||||
$this->assertTrue($cron_count = 1, format_string('Cron added @count of @expected new log entries', ['@count' => $cron_count, '@expected' => 1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs cron and returns number of new log entries.
|
||||
*
|
||||
* @return int
|
||||
* Number of new watchdog entries.
|
||||
*/
|
||||
private function runCron() {
|
||||
// Get last ID to compare against; log entries get deleted, so we can't
|
||||
// reliably add the number of newly created log entries to the current count
|
||||
// to measure number of log entries created by cron.
|
||||
$last_id = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
|
||||
|
||||
// Run a cron job.
|
||||
$this->cronRun();
|
||||
// Verify that the database log row count equals the row limit plus one
|
||||
// because cron adds a record after it runs.
|
||||
$count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
|
||||
$this->assertTrue($count == $row_limit + 1, format_string('Dblog row count of @count equals row limit of @limit plus one', array('@count' => $count, '@limit' => $row_limit)));
|
||||
|
||||
// Get last ID after cron was run.
|
||||
$current_id = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
|
||||
|
||||
return $current_id - $last_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +203,7 @@ class DbLogTest extends WebTestBase {
|
||||
* entry.
|
||||
* - 'timestamp': Int unix timestamp.
|
||||
*/
|
||||
private function generateLogEntries($count, $options = array()) {
|
||||
private function generateLogEntries($count, $options = []) {
|
||||
global $base_root;
|
||||
|
||||
// This long URL makes it just a little bit harder to pass the link part of
|
||||
@@ -187,10 +212,10 @@ class DbLogTest extends WebTestBase {
|
||||
$link = urldecode('/content/xo%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A%E9%85%B1%E5%87%89%E6%8B%8C%E7%B4%A0%E9%B8%A1%E7%85%A7%E7%83%A7%E9%B8%A1%E9%BB%84%E7%8E%AB%E7%91%B0-%E7%A7%91%E5%B7%9E%E7%9A%84%E5%B0%8F%E4%B9%9D%E5%AF%A8%E6%B2%9F%E7%BB%9D%E7%BE%8E%E9%AB%98%E5%B1%B1%E6%B9%96%E6%B3%8A-lake-isabelle');
|
||||
|
||||
// Prepare the fields to be logged
|
||||
$log = $options + array(
|
||||
$log = $options + [
|
||||
'channel' => 'custom',
|
||||
'message' => 'Dblog test log message',
|
||||
'variables' => array(),
|
||||
'variables' => [],
|
||||
'severity' => RfcLogLevel::NOTICE,
|
||||
'link' => $link,
|
||||
'user' => $this->adminUser,
|
||||
@@ -199,7 +224,7 @@ class DbLogTest extends WebTestBase {
|
||||
'referer' => \Drupal::request()->server->get('HTTP_REFERER'),
|
||||
'ip' => '127.0.0.1',
|
||||
'timestamp' => REQUEST_TIME,
|
||||
);
|
||||
];
|
||||
|
||||
$logger = $this->container->get('logger.dblog');
|
||||
$message = $log['message'] . ' Entry #';
|
||||
@@ -209,6 +234,32 @@ class DbLogTest extends WebTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the entry logs by clicking on 'Clear log messages' button.
|
||||
*/
|
||||
protected function clearLogsEntries() {
|
||||
$this->drupalGet(Url::fromRoute('dblog.confirm'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the logs according to the specific severity and log entry type.
|
||||
*
|
||||
* @param string $type
|
||||
* (optional) The log entry type.
|
||||
* @param string $severity
|
||||
* (optional) The log entry severity.
|
||||
*/
|
||||
protected function filterLogsEntries($type = NULL, $severity = NULL) {
|
||||
$edit = [];
|
||||
if (!is_null($type)) {
|
||||
$edit['type[]'] = $type;
|
||||
}
|
||||
if (!is_null($severity)) {
|
||||
$edit['severity[]'] = $severity;
|
||||
}
|
||||
$this->drupalPostForm(NULL, $edit, t('Filter'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms that database log reports are displayed at the correct paths.
|
||||
*
|
||||
@@ -270,8 +321,8 @@ class DbLogTest extends WebTestBase {
|
||||
private function verifyEvents() {
|
||||
// Invoke events.
|
||||
$this->doUser();
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => t('Article')));
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => t('Article')]);
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
|
||||
$this->doNode('article');
|
||||
$this->doNode('page');
|
||||
$this->doNode('forum');
|
||||
@@ -290,7 +341,7 @@ class DbLogTest extends WebTestBase {
|
||||
* The order by which the table should be sorted.
|
||||
*/
|
||||
public function verifySort($sort = 'asc', $order = 'Date') {
|
||||
$this->drupalGet('admin/reports/dblog', array('query' => array('sort' => $sort, 'order' => $order)));
|
||||
$this->drupalGet('admin/reports/dblog', ['query' => ['sort' => $sort, 'order' => $order]]);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('Recent log messages'), 'DBLog report was displayed correctly and sorting went fine.');
|
||||
}
|
||||
@@ -300,12 +351,12 @@ class DbLogTest extends WebTestBase {
|
||||
* page.
|
||||
*/
|
||||
private function verifyLinkEscaping() {
|
||||
$link = \Drupal::l('View', Url::fromRoute('entity.node.canonical', array('node' => 1)));
|
||||
$link = \Drupal::l('View', Url::fromRoute('entity.node.canonical', ['node' => 1]));
|
||||
$message = 'Log entry added to do the verifyLinkEscaping test.';
|
||||
$this->generateLogEntries(1, array(
|
||||
$this->generateLogEntries(1, [
|
||||
'message' => $message,
|
||||
'link' => $link,
|
||||
));
|
||||
]);
|
||||
|
||||
$result = db_query_range('SELECT wid FROM {watchdog} ORDER BY wid DESC', 0, 1);
|
||||
$this->drupalGet('admin/reports/dblog/event/' . $result->fetchField());
|
||||
@@ -323,7 +374,7 @@ class DbLogTest extends WebTestBase {
|
||||
$pass = user_password();
|
||||
// Add a user using the form to generate an add user event (which is not
|
||||
// triggered by drupalCreateUser).
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name;
|
||||
$edit['mail'] = $name . '@example.com';
|
||||
$edit['pass[pass1]'] = $pass;
|
||||
@@ -333,7 +384,7 @@ class DbLogTest extends WebTestBase {
|
||||
$this->assertResponse(200);
|
||||
// Retrieve the user object.
|
||||
$user = user_load_by_name($name);
|
||||
$this->assertTrue($user != NULL, format_string('User @name was loaded', array('@name' => $name)));
|
||||
$this->assertTrue($user != NULL, format_string('User @name was loaded', ['@name' => $name]));
|
||||
// pass_raw property is needed by drupalLogin.
|
||||
$user->pass_raw = $pass;
|
||||
// Log in user.
|
||||
@@ -341,18 +392,18 @@ class DbLogTest extends WebTestBase {
|
||||
// Log out user.
|
||||
$this->drupalLogout();
|
||||
// Fetch the row IDs in watchdog that relate to the user.
|
||||
$result = db_query('SELECT wid FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->id()));
|
||||
$result = db_query('SELECT wid FROM {watchdog} WHERE uid = :uid', [':uid' => $user->id()]);
|
||||
foreach ($result as $row) {
|
||||
$ids[] = $row->wid;
|
||||
}
|
||||
$count_before = (isset($ids)) ? count($ids) : 0;
|
||||
$this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', array('@count' => $count_before, '@name' => $user->getUsername())));
|
||||
$this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getUsername()]));
|
||||
|
||||
// Log in the admin user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Delete the user created at the start of this test.
|
||||
// We need to POST here to invoke batch_process() in the internal browser.
|
||||
$this->drupalPostForm('user/' . $user->id() . '/cancel', array('user_cancel_method' => 'user_cancel_reassign'), t('Cancel account'));
|
||||
$this->drupalPostForm('user/' . $user->id() . '/cancel', ['user_cancel_method' => 'user_cancel_reassign'], t('Cancel account'));
|
||||
|
||||
// View the database log report.
|
||||
$this->drupalGet('admin/reports/dblog');
|
||||
@@ -362,13 +413,13 @@ class DbLogTest extends WebTestBase {
|
||||
// Add user.
|
||||
// Default display includes name and email address; if too long, the email
|
||||
// address is replaced by three periods.
|
||||
$this->assertLogMessage(t('New user: %name %email.', array('%name' => $name, '%email' => '<' . $user->getEmail() . '>')), 'DBLog event was recorded: [add user]');
|
||||
$this->assertLogMessage(t('New user: %name %email.', ['%name' => $name, '%email' => '<' . $user->getEmail() . '>']), 'DBLog event was recorded: [add user]');
|
||||
// Log in user.
|
||||
$this->assertLogMessage(t('Session opened for %name.', array('%name' => $name)), 'DBLog event was recorded: [login user]');
|
||||
$this->assertLogMessage(t('Session opened for %name.', ['%name' => $name]), 'DBLog event was recorded: [login user]');
|
||||
// Log out user.
|
||||
$this->assertLogMessage(t('Session closed for %name.', array('%name' => $name)), 'DBLog event was recorded: [logout user]');
|
||||
$this->assertLogMessage(t('Session closed for %name.', ['%name' => $name]), 'DBLog event was recorded: [logout user]');
|
||||
// Delete user.
|
||||
$message = t('Deleted user: %name %email.', array('%name' => $name, '%email' => '<' . $user->getEmail() . '>'));
|
||||
$message = t('Deleted user: %name %email.', ['%name' => $name, '%email' => '<' . $user->getEmail() . '>']);
|
||||
$message_text = Unicode::truncate(Html::decodeEntities(strip_tags($message)), 56, TRUE, TRUE);
|
||||
// Verify that the full message displays on the details page.
|
||||
$link = FALSE;
|
||||
@@ -406,7 +457,7 @@ class DbLogTest extends WebTestBase {
|
||||
*/
|
||||
private function doNode($type) {
|
||||
// Create user.
|
||||
$perm = array('create ' . $type . ' content', 'edit own ' . $type . ' content', 'delete own ' . $type . ' content');
|
||||
$perm = ['create ' . $type . ' content', 'edit own ' . $type . ' content', 'delete own ' . $type . ' content'];
|
||||
$user = $this->drupalCreateUser($perm);
|
||||
// Log in user.
|
||||
$this->drupalLogin($user);
|
||||
@@ -419,13 +470,13 @@ class DbLogTest extends WebTestBase {
|
||||
$this->assertResponse(200);
|
||||
// Retrieve the node object.
|
||||
$node = $this->drupalGetNodeByTitle($title);
|
||||
$this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title)));
|
||||
$this->assertTrue($node != NULL, format_string('Node @title was loaded', ['@title' => $title]));
|
||||
// Edit the node.
|
||||
$edit = $this->getContentUpdate($type);
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
// Delete the node.
|
||||
$this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('node/' . $node->id() . '/delete', [], t('Delete'));
|
||||
$this->assertResponse(200);
|
||||
// View the node (to generate page not found event).
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
@@ -442,11 +493,11 @@ class DbLogTest extends WebTestBase {
|
||||
|
||||
// Verify that node events were recorded.
|
||||
// Was node content added?
|
||||
$this->assertLogMessage(t('@type: added %title.', array('@type' => $type, '%title' => $title)), 'DBLog event was recorded: [content added]');
|
||||
$this->assertLogMessage(t('@type: added %title.', ['@type' => $type, '%title' => $title]), 'DBLog event was recorded: [content added]');
|
||||
// Was node content updated?
|
||||
$this->assertLogMessage(t('@type: updated %title.', array('@type' => $type, '%title' => $title)), 'DBLog event was recorded: [content updated]');
|
||||
$this->assertLogMessage(t('@type: updated %title.', ['@type' => $type, '%title' => $title]), 'DBLog event was recorded: [content updated]');
|
||||
// Was node content deleted?
|
||||
$this->assertLogMessage(t('@type: deleted %title.', array('@type' => $type, '%title' => $title)), 'DBLog event was recorded: [content deleted]');
|
||||
$this->assertLogMessage(t('@type: deleted %title.', ['@type' => $type, '%title' => $title]), 'DBLog event was recorded: [content deleted]');
|
||||
|
||||
// View the database log access-denied report page.
|
||||
$this->drupalGet('admin/reports/access-denied');
|
||||
@@ -473,18 +524,18 @@ class DbLogTest extends WebTestBase {
|
||||
private function getContent($type) {
|
||||
switch ($type) {
|
||||
case 'forum':
|
||||
$content = array(
|
||||
$content = [
|
||||
'title[0][value]' => $this->randomMachineName(8),
|
||||
'taxonomy_forums' => array(1),
|
||||
'taxonomy_forums' => [1],
|
||||
'body[0][value]' => $this->randomMachineName(32),
|
||||
);
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$content = array(
|
||||
$content = [
|
||||
'title[0][value]' => $this->randomMachineName(8),
|
||||
'body[0][value]' => $this->randomMachineName(32),
|
||||
);
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $content;
|
||||
@@ -500,9 +551,9 @@ class DbLogTest extends WebTestBase {
|
||||
* Random content needed by various node types.
|
||||
*/
|
||||
private function getContentUpdate($type) {
|
||||
$content = array(
|
||||
$content = [
|
||||
'body[0][value]' => $this->randomMachineName(32),
|
||||
);
|
||||
];
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -516,10 +567,10 @@ class DbLogTest extends WebTestBase {
|
||||
global $base_root;
|
||||
// Get a count of how many watchdog entries already exist.
|
||||
$count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
|
||||
$log = array(
|
||||
$log = [
|
||||
'channel' => 'system',
|
||||
'message' => 'Log entry added to test the doClearTest clear down.',
|
||||
'variables' => array(),
|
||||
'variables' => [],
|
||||
'severity' => RfcLogLevel::NOTICE,
|
||||
'link' => NULL,
|
||||
'user' => $this->adminUser,
|
||||
@@ -528,20 +579,20 @@ class DbLogTest extends WebTestBase {
|
||||
'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->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), format_string('\Drupal\dblog\Logger\DbLog->log() added an entry to the dblog :count', array(':count' => $count)));
|
||||
$this->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), format_string('\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.
|
||||
$this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages'));
|
||||
$this->clearLogsEntries();
|
||||
// Confirm that the logs should be cleared.
|
||||
$this->drupalPostForm(NULL, array(), 'Confirm');
|
||||
$this->drupalPostForm(NULL, [], 'Confirm');
|
||||
// Count the rows in watchdog that previously related to the deleted user.
|
||||
$count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
|
||||
$this->assertEqual($count, 0, format_string('DBLog contains :count records after a clear.', array(':count' => $count)));
|
||||
$this->assertEqual($count, 0, format_string('DBLog contains :count records after a clear.', [':count' => $count]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -554,21 +605,21 @@ class DbLogTest extends WebTestBase {
|
||||
db_delete('watchdog')->execute();
|
||||
|
||||
// Generate 9 random watchdog entries.
|
||||
$type_names = array();
|
||||
$types = array();
|
||||
$type_names = [];
|
||||
$types = [];
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$type_names[] = $type_name = $this->randomMachineName();
|
||||
$severity = RfcLogLevel::EMERGENCY;
|
||||
for ($j = 0; $j < 3; $j++) {
|
||||
$types[] = $type = array(
|
||||
$types[] = $type = [
|
||||
'count' => $j + 1,
|
||||
'type' => $type_name,
|
||||
'severity' => $severity++,
|
||||
);
|
||||
$this->generateLogEntries($type['count'], array(
|
||||
];
|
||||
$this->generateLogEntries($type['count'], [
|
||||
'channel' => $type['type'],
|
||||
'severity' => $type['severity'],
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,10 +635,7 @@ class DbLogTest extends WebTestBase {
|
||||
// Filter by each type and confirm that entries with various severities are
|
||||
// displayed.
|
||||
foreach ($type_names as $type_name) {
|
||||
$edit = array(
|
||||
'type[]' => array($type_name),
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Filter'));
|
||||
$this->filterLogsEntries($type_name);
|
||||
|
||||
// Count the number of entries of this type.
|
||||
$type_count = 0;
|
||||
@@ -604,24 +652,20 @@ class DbLogTest extends WebTestBase {
|
||||
// Set the filter to match each of the two filter-type attributes and
|
||||
// confirm the correct number of entries are displayed.
|
||||
foreach ($types as $type) {
|
||||
$edit = array(
|
||||
'type[]' => array($type['type']),
|
||||
'severity[]' => array($type['severity']),
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Filter'));
|
||||
$this->filterLogsEntries($type['type'], $type['severity']);
|
||||
|
||||
$count = $this->getTypeCount($types);
|
||||
$this->assertEqual(array_sum($count), $type['count'], 'Count matched');
|
||||
}
|
||||
|
||||
$this->drupalGet('admin/reports/dblog', array('query' => array('order' => 'Type')));
|
||||
$this->drupalGet('admin/reports/dblog', ['query' => ['order' => 'Type']]);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('Operations'), 'Operations text found');
|
||||
|
||||
// Clear all logs and make sure the confirmation message is found.
|
||||
$this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages'));
|
||||
$this->clearLogsEntries();
|
||||
// Confirm that the logs should be cleared.
|
||||
$this->drupalPostForm(NULL, array(), 'Confirm');
|
||||
$this->drupalPostForm(NULL, [], 'Confirm');
|
||||
$this->assertText(t('Database log cleared.'), 'Confirmation message found');
|
||||
}
|
||||
|
||||
@@ -636,21 +680,31 @@ class DbLogTest extends WebTestBase {
|
||||
* - user: (string) The user associated with this database log event.
|
||||
*/
|
||||
protected function getLogEntries() {
|
||||
$entries = array();
|
||||
if ($table = $this->xpath('.//table[@id="admin-dblog"]')) {
|
||||
$entries = [];
|
||||
if ($table = $this->getLogsEntriesTable()) {
|
||||
$table = array_shift($table);
|
||||
foreach ($table->tbody->tr as $row) {
|
||||
$entries[] = array(
|
||||
$entries[] = [
|
||||
'severity' => $this->getSeverityConstant($row['class']),
|
||||
'type' => $this->asText($row->td[1]),
|
||||
'message' => $this->asText($row->td[3]),
|
||||
'user' => $this->asText($row->td[4]),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the Logs table in the DOM.
|
||||
*
|
||||
* @return \SimpleXMLElement[]
|
||||
* The return value of a xpath search.
|
||||
*/
|
||||
protected function getLogsEntriesTable() {
|
||||
return $this->xpath('.//table[@id="admin-dblog"]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the count of database log entries by database log event type.
|
||||
*
|
||||
@@ -741,7 +795,7 @@ class DbLogTest extends WebTestBase {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Generate a single watchdog entry.
|
||||
$this->generateLogEntries(1, array('user' => $tempuser, 'uid' => $tempuser_uid));
|
||||
$this->generateLogEntries(1, ['user' => $tempuser, 'uid' => $tempuser_uid]);
|
||||
$wid = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
|
||||
|
||||
// Check if the full message displays on the details page.
|
||||
|
||||
@@ -18,7 +18,7 @@ class DbLogResourceTest extends RESTTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('hal', 'dblog');
|
||||
public static $modules = ['hal', 'dblog'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
@@ -33,12 +33,12 @@ class DbLogResourceTest extends RESTTestBase {
|
||||
// Write a log message to the DB.
|
||||
$this->container->get('logger.channel.rest')->notice('Test message');
|
||||
// Get the ID of the written message.
|
||||
$id = db_query_range("SELECT wid FROM {watchdog} WHERE type = :type ORDER BY wid DESC", 0, 1, array(':type' => 'rest'))
|
||||
$id = db_query_range("SELECT wid FROM {watchdog} WHERE type = :type ORDER BY wid DESC", 0, 1, [':type' => 'rest'])
|
||||
->fetchField();
|
||||
|
||||
// Create a user account that has the required permissions to read
|
||||
// the watchdog resource via the REST API.
|
||||
$account = $this->drupalCreateUser(array('restful get dblog'));
|
||||
$account = $this->drupalCreateUser(['restful get dblog']);
|
||||
$this->drupalLogin($account);
|
||||
|
||||
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => $id, '_format' => $this->defaultFormat]), 'GET');
|
||||
@@ -53,13 +53,13 @@ class DbLogResourceTest extends RESTTestBase {
|
||||
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => 9999, '_format' => $this->defaultFormat]), 'GET');
|
||||
$this->assertResponse(404);
|
||||
$decoded = Json::decode($response);
|
||||
$this->assertEqual($decoded['error'], 'Log entry with ID 9999 was not found', 'Response message is correct.');
|
||||
$this->assertEqual($decoded['message'], 'Log entry with ID 9999 was not found', 'Response message is correct.');
|
||||
|
||||
// Make a bad request (a true malformed request would never be a route match).
|
||||
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => 0, '_format' => $this->defaultFormat]), 'GET');
|
||||
$this->assertResponse(400);
|
||||
$decoded = Json::decode($response);
|
||||
$this->assertEqual($decoded['error'], 'No log entry ID was provided', 'Response message is correct.');
|
||||
$this->assertEqual($decoded['message'], 'No log entry ID was provided', 'Response message is correct.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user