Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -0,0 +1,8 @@
dblog.view_logs:
title: 'View'
route_name: dblog.overview
base_route: dblog.overview
dblog.clear_logs:
title: 'Delete'
route_name: dblog.confirm
base_route: dblog.overview

View file

@ -128,7 +128,6 @@ class DbLogController extends ControllerBase {
$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(
// Icon column.
@ -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 {

View file

@ -65,7 +65,7 @@ class DblogClearLogConfirmForm extends ConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$_SESSION['dblog_overview_filter'] = array();
$this->connection->delete('watchdog')->execute();
$this->connection->truncate('watchdog')->execute();
drupal_set_message($this->t('Database log cleared.'));
$form_state->setRedirectUrl($this->getCancelUrl());
}

View file

@ -1,71 +0,0 @@
<?php
namespace Drupal\dblog\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the form that clears out the log.
*/
class DblogClearLogForm extends FormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new DblogClearLogForm.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dblog_clear_log_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['dblog_clear'] = array(
'#type' => 'details',
'#title' => $this->t('Clear log messages'),
'#description' => $this->t('This will permanently remove the log messages from the database.'),
);
$form['dblog_clear']['clear'] = array(
'#type' => 'submit',
'#value' => $this->t('Clear log messages'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('dblog.confirm');
}
}

View file

@ -26,7 +26,7 @@ class DblogFilterForm extends FormBase {
$form['filters'] = array(
'#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(

View file

@ -147,12 +147,23 @@ class DbLogTest extends WebTestBase {
$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)));
// 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();
// Get the number of enabled modules. Cron adds a log entry for each module.
$list = \Drupal::moduleHandler()->getImplementations('cron');
$module_count = count($list);
$count = $current_id - $last_id;
$this->assertTrue(($current_id - $last_id) == $module_count + 2, format_string('Cron added @count of @expected new log entries', array('@count' => $count, '@expected' => $module_count + 2)));
}
/**
@ -209,6 +220,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 = array();
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.
*
@ -536,7 +573,7 @@ class DbLogTest extends WebTestBase {
// 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');
// Count the rows in watchdog that previously related to the deleted user.
@ -584,10 +621,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,11 +638,7 @@ 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');
@ -619,7 +649,7 @@ class DbLogTest extends WebTestBase {
$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->assertText(t('Database log cleared.'), 'Confirmation message found');
@ -637,7 +667,7 @@ class DbLogTest extends WebTestBase {
*/
protected function getLogEntries() {
$entries = array();
if ($table = $this->xpath('.//table[@id="admin-dblog"]')) {
if ($table = $this->getLogsEntriesTable()) {
$table = array_shift($table);
foreach ($table->tbody->tr as $row) {
$entries[] = array(
@ -651,6 +681,16 @@ class DbLogTest extends WebTestBase {
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.
*

View file

@ -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.');
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\dblog\Kernel;
use Drupal\dblog\Controller\DbLogController;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests for the DbLogController class.
*
* @group dblog
*/
class DbLogControllerTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['dblog', 'user'];
/**
* Tests corrupted log entries can still display available data.
*/
public function testDbLogCorrupted() {
$this->installEntitySchema('user');
$dblog_controller = DbLogController::create($this->container);
// Check message with properly serialized data.
$message = (object) [
'message' => 'Sample message with placeholder: @placeholder',
'variables' => serialize(['@placeholder' => 'test placeholder']),
];
$this->assertEquals('Sample message with placeholder: test placeholder', $dblog_controller->formatMessage($message));
// Check that controller work with corrupted data.
$message->variables = 'BAD SERIALIZED DATA';
$formatted = $dblog_controller->formatMessage($message);
$this->assertEquals('Log data is corrupted and cannot be unserialized: Sample message with placeholder: @placeholder', $formatted);
}
}