diff --git a/core/modules/dblog/dblog.admin.inc b/core/modules/dblog/dblog.admin.inc index b2da7ed..61a355e 100644 --- a/core/modules/dblog/dblog.admin.inc +++ b/core/modules/dblog/dblog.admin.inc @@ -6,10 +6,12 @@ */ /** - * Menu callback; displays a listing of log messages. + * Page callback: Displays a listing of dblog messages. * - * Messages are truncated at 56 chars. Full-length message could be viewed at - * the message details page. + * Messages are truncated at 56 chars. Full-length message can be viewed in + * their entirity on the message details page (admin/reports/event/%). + * + * @see dblog_menu() */ function dblog_overview() { $filter = dblog_build_filter_query(); @@ -79,12 +81,15 @@ function dblog_overview() { } /** - * Menu callback; generic function to display a page of the most frequent events. + * Page callback: Shows the most frequent log messages of a given event type. + * + * Messages are not truncated on this page because events detailed herein do not + * have links to a detailed view. * - * Messages are not truncated because events from this page have no detail view. + * @param string $type + * Type of database log events to display (e.g. 'search'). * - * @param $type - * type of dblog events to display. + * @see dblog_menu() */ function dblog_top($type) { @@ -125,7 +130,12 @@ function dblog_top($type) { } /** - * Menu callback; displays details about a log message. + * Page callback: Displays details about a specific database log message. + * + * @param int $id + * Unique watchdog event ID. + * + * @see dblog_menu() */ function dblog_event($id) { $severity = watchdog_severity_levels(); @@ -182,7 +192,10 @@ function dblog_event($id) { } /** - * Build query for dblog administration filters based on session. + * Builds a query for database log administration filters based on session. + * + * @return array + * An associative array with keys 'where' and 'args'. */ function dblog_build_filter_query() { if (empty($_SESSION['dblog_overview_filter'])) { @@ -211,9 +224,16 @@ function dblog_build_filter_query() { ); } - /** - * List dblog administration filters that can be applied. + * Creates a list of database log administration filters that can be applied. + * + * @return array + * Two-dimensional array with 'type' and 'severity' top-level keys, each of + * which is an array with the following keys: + * - title: Title of the filter. + * - where: The filter condition. + * - options: Types of watchdog messages or severity levels. + * If no records exist in the table, the 'type' element will not be returned. */ function dblog_filters() { $filters = array(); @@ -240,9 +260,9 @@ function dblog_filters() { } /** - * Returns HTML for a log message. + * Returns an HTML string for a database log event. * - * @param $variables + * @param array $variables * An associative array containing: * - event: An object with at least the message and variables properties. * - link: (optional) Format message as link, event->wid is required. @@ -272,11 +292,11 @@ function theme_dblog_message($variables) { } /** - * Return form for dblog administration filters. + * Form constructor for the dblog filter form. * - * @ingroup forms - * @see dblog_filter_form_submit() * @see dblog_filter_form_validate() + * @see dblog_filter_form_submit() + * @ingroup forms */ function dblog_filter_form($form) { $filters = dblog_filters(); @@ -314,12 +334,13 @@ function dblog_filter_form($form) { '#value' => t('Reset') ); } - return $form; } /** - * Validate result from dblog administration filter form. + * Form validation handler for dblog_filter_form(). + * + * @see dblog_filter_form_submit() */ function dblog_filter_form_validate($form, &$form_state) { if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['type']) && empty($form_state['values']['severity'])) { @@ -328,7 +349,9 @@ function dblog_filter_form_validate($form, &$form_state) { } /** - * Process result from dblog administration filter form. + * Form submission handler for dblog_filter_form(). + * + * @see dblog_filter_form_validate() */ function dblog_filter_form_submit($form, &$form_state) { $op = $form_state['values']['op']; @@ -349,10 +372,12 @@ function dblog_filter_form_submit($form, &$form_state) { } /** - * Return form for dblog clear button. + * Form constructor for the dblog clear log form. + * + * This form allows the user to clear the dblog table of event messages. * - * @ingroup forms * @see dblog_clear_log_submit() + * @ingroup forms */ function dblog_clear_log_form($form) { $form['dblog_clear'] = array( @@ -367,12 +392,13 @@ function dblog_clear_log_form($form) { '#value' => t('Clear log messages'), '#submit' => array('dblog_clear_log_submit'), ); - return $form; } /** - * Submit callback: clear database with log messages. + * Submission handler for dblog_clear_log_form(). + * + * @see dblog_clear_log_form() */ function dblog_clear_log_submit() { $_SESSION['dblog_overview_filter'] = array(); diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index e92fcbd..c9c8235 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -6,9 +6,9 @@ use Drupal\Core\Database\Database; * @file * System monitoring and logging for administrators. * - * The dblog module monitors your site and keeps a list of - * recorded events containing usage and performance data, errors, - * warnings, and similar operational information. + * The Database Logging module monitors your site and keeps a list of recorded + * events containing usage and performance data, errors, warnings, and similar + * operational information. * * @see watchdog() */ @@ -98,10 +98,10 @@ function dblog_init() { /** * Implements hook_cron(). * - * Remove expired log messages and flood control events. + * Controls the size of the log table, paring it to 'dblog_row_limit' messages. */ function dblog_cron() { - // Cleanup the watchdog table. + // Cleanup the database log table. $row_limit = variable_get('dblog_row_limit', 1000); // For row limit n, get the wid of the nth row in descending wid order. @@ -123,6 +123,12 @@ function dblog_cron() { } } +/** + * Gathers a list of uniquely defined database log message types. + * + * @return array + * List of uniquely defined database log message types. + */ function _dblog_get_message_types() { $types = array(); @@ -137,7 +143,7 @@ function _dblog_get_message_types() { /** * Implements hook_watchdog(). * - * Note some values may be truncated for database column size restrictions. + * Note: Some values may be truncated to meet database column size restrictions. */ function dblog_watchdog(array $log_entry) { // The user object may not exist in all conditions, so 0 is substituted if needed. @@ -160,7 +166,7 @@ function dblog_watchdog(array $log_entry) { } /** - * Implements hook_form_FORM_ID_alter(). + * Implements hook_form_FORM_ID_alter() for system_logging_settings(). */ function dblog_form_system_logging_settings_alter(&$form, $form_state) { $form['dblog_row_limit'] = array( diff --git a/core/modules/dblog/dblog.test b/core/modules/dblog/dblog.test index e3a997e..678772d 100644 --- a/core/modules/dblog/dblog.test +++ b/core/modules/dblog/dblog.test @@ -2,9 +2,12 @@ /** * @file - * Tests for dblog.module. + * Tests for Database Logging module. */ +/** + * Tests the Database Logging module functionality. + */ class DBLogTestCase extends DrupalWebTestCase { protected $profile = 'standard'; @@ -20,7 +23,7 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Enable modules and create users with specific permissions. + * Enables modules and creates users with specific permissions. */ function setUp() { parent::setUp('dblog', 'poll'); @@ -30,7 +33,11 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Login users, create dblog events, and test dblog functionality through the admin and user interfaces. + * Tests Database Logging module functionality through interfaces. + * + * First logs in users, then creates database log events, and finally tests + * Database Logging module functionality through both the admin and user + * interfaces. */ function testDBLog() { // Login the admin user. @@ -48,9 +55,10 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Verify setting of the dblog row limit. + * Verifies setting of the database log row limit. * - * @param integer $count Log row limit. + * @param int $row_limit + * The row limit. */ private function verifyRowLimit($row_limit) { // Change the dblog row limit. @@ -68,9 +76,10 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Verify cron applies the dblog row limit. + * Verifies that cron correctly applies the database log row limit. * - * @param integer $count Log row limit. + * @param int $row_limit + * The row limit. */ private function verifyCron($row_limit) { // Generate additional log entries. @@ -81,19 +90,20 @@ class DBLogTestCase extends DrupalWebTestCase { // Run cron job. $this->cronRun(); - // Verify dblog row count equals row limit plus one because cron adds a record after it runs. + // Verify dblog row count equals 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, t('Dblog row count of @count equals row limit of @limit plus one', array('@count' => $count, '@limit' => $row_limit))); } /** - * Generate dblog entries. + * Generates a number of random database log events. * - * @param integer $count - * Number of log entries to generate. - * @param $type + * @param int $count + * Number of watchdog entries to generate. + * @param string $type * The type of watchdog entry. - * @param $severity + * @param int $severity * The severity of the watchdog entry. */ private function generateLogEntries($count, $type = 'custom', $severity = WATCHDOG_NOTICE) { @@ -120,9 +130,10 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Verify the logged in user has the desired access to the various dblog nodes. + * Verifies logged in user has desired access to various database log nodes. * - * @param integer $response HTTP response code. + * @param int $response + * HTTP response code. */ private function verifyReports($response = 200) { $quote = '''; @@ -164,7 +175,7 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Verify events. + * Generates and then verifies various types of events. */ private function verifyEvents() { // Invoke events. @@ -179,14 +190,14 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Generate and verify user events. - * + * Generates and then verifies some user events. */ private function doUser() { // Set user variables. $name = $this->randomName(); $pass = user_password(); - // Add user using form to generate add user event (which is not triggered by drupalCreateUser). + // Add user using form to generate add user event (which is not triggered by + // drupalCreateUser). $edit = array(); $edit['name'] = $name; $edit['mail'] = $name . '@example.com'; @@ -198,7 +209,8 @@ class DBLogTestCase extends DrupalWebTestCase { // Retrieve user object. $user = user_load_by_name($name); $this->assertTrue($user != NULL, t('User @name was loaded', array('@name' => $name))); - $user->pass_raw = $pass; // Needed by drupalLogin. + // pass_raw property is needed by drupalLogin. + $user->pass_raw = $pass; // Login user. $this->drupalLogin($user); // Logout user. @@ -213,7 +225,7 @@ class DBLogTestCase extends DrupalWebTestCase { // Login the admin user. $this->drupalLogin($this->big_user); - // Delete user. + // Delete user created at start of this test. // We need to POST here to invoke batch_process() in the internal browser. $this->drupalPost('user/' . $user->uid . '/cancel', array('user_cancel_method' => 'user_cancel_reassign'), t('Cancel account')); @@ -221,9 +233,10 @@ class DBLogTestCase extends DrupalWebTestCase { $this->drupalGet('admin/reports/dblog'); $this->assertResponse(200); - // Verify events were recorded. + // Verify that the expected events were recorded. // Add user. - // Default display includes name and email address; if too long then email is replaced by three periods. + // 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->mail)), t('DBLog event was recorded: [add user]')); // Login user. $this->assertLogMessage(t('Session opened for %name.', array('%name' => $name)), t('DBLog event was recorded: [login user]')); @@ -261,9 +274,10 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Generate and verify node events. + * Generates and then verifies some node events. * - * @param string $type Content type. + * @param string $type + * A node type (e.g. 'article', 'page' or 'poll'). */ private function doNode($type) { // Create user. @@ -272,7 +286,8 @@ class DBLogTestCase extends DrupalWebTestCase { // Login user. $this->drupalLogin($user); - // Create node using form to generate add content event (which is not triggered by drupalCreateNode). + // Create node using form to generate add content event (which is not + // triggered by drupalCreateNode). $edit = $this->getContent($type); $langcode = LANGUAGE_NOT_SPECIFIED; $title = $edit["title"]; @@ -301,32 +316,35 @@ class DBLogTestCase extends DrupalWebTestCase { $this->drupalGet('admin/reports/dblog'); $this->assertResponse(200); - // Verify events were recorded. - // Content added. + // Verify node events were recorded. + // Was node content added? $this->assertLogMessage(t('@type: added %title.', array('@type' => $type, '%title' => $title)), t('DBLog event was recorded: [content added]')); - // Content updated. + // Was node content updated? $this->assertLogMessage(t('@type: updated %title.', array('@type' => $type, '%title' => $title)), t('DBLog event was recorded: [content updated]')); - // Content deleted. + // Was node content deleted? $this->assertLogMessage(t('@type: deleted %title.', array('@type' => $type, '%title' => $title)), t('DBLog event was recorded: [content deleted]')); // View dblog access-denied report node. $this->drupalGet('admin/reports/access-denied'); $this->assertResponse(200); - // Access denied. + // Verify 'access denied' event was recorded. $this->assertText(t('admin/reports/dblog'), t('DBLog event was recorded: [access denied]')); // View dblog page-not-found report node. $this->drupalGet('admin/reports/page-not-found'); $this->assertResponse(200); - // Page not found. + // Verify 'page not found' event was recorded. $this->assertText(t('node/@nid', array('@nid' => $node->nid)), t('DBLog event was recorded: [page not found]')); } /** - * Create content based on content type. + * Creates random content based on node content type. + * + * @param string $type + * Node content type (e.g. 'article'). * - * @param string $type Content type. - * @return array Content. + * @return array + * Random content needed by various node types. */ private function getContent($type) { $langcode = LANGUAGE_NOT_SPECIFIED; @@ -350,10 +368,13 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Create content update based on content type. + * Creates random content as an update based on node content type. + * + * @param string $type + * Node content type (e.g. 'article'). * - * @param string $type Content type. - * @return array Content. + * @return array + * Random content needed by various node types. */ private function getContentUpdate($type) { switch ($type) { @@ -375,15 +396,18 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Login an admin user, create dblog event, and test clearing dblog functionality through the admin interface. + * Tests the addition and clearing of log events through the admin interface. + * + * First logs in an admin user, then creates database log event, and finally + * tests the clearing dblog functionality through the admin interface. */ protected function testDBLogAddAndClear() { global $base_root; - // Get a count of how many watchdog entries there are. + // Get a count of how many watchdog entries already exist. $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(); $log = array( 'type' => 'custom', - 'message' => 'Log entry added to test the doClearTest clear down.', + 'message' => 'Log entry added to test the testDBLogAddAndClear clearing logic.', 'variables' => array(), 'severity' => WATCHDOG_NOTICE, 'link' => NULL, @@ -395,11 +419,11 @@ class DBLogTestCase extends DrupalWebTestCase { ); // Add a watchdog entry. dblog_watchdog($log); - // Make sure the table count has actually incremented. + // Make sure the table count has actually been incremented. $this->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), t('dblog_watchdog() added an entry to the dblog :count', array(':count' => $count))); // Login the admin user. $this->drupalLogin($this->big_user); - // Now post to clear the db table. + // Now post to clear the database table. $this->drupalPost('admin/reports/dblog', array(), t('Clear log messages')); // Count rows in watchdog that previously related to the deleted user. $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(); @@ -407,15 +431,17 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Test the dblog filter on admin/reports/dblog. + * Tests the database log filter functionality. + * + * Path: admin/reports/dblog */ protected function testFilter() { $this->drupalLogin($this->big_user); - // Clear log to ensure that only generated entries are found. + // Clear log to ensure that only generated entries will be found. db_delete('watchdog')->execute(); - // Generate watchdog entries. + // Generate 9 random watchdog entries. $type_names = array(); $types = array(); for ($i = 0; $i < 3; $i++) { @@ -431,10 +457,10 @@ class DBLogTestCase extends DrupalWebTestCase { } } - // View the dblog. + // View the dblog page. $this->drupalGet('admin/reports/dblog'); - // Confirm all the entries are displayed. + // Confirm that all the entries are displayed. $count = $this->getTypeCount($types); foreach ($types as $key => $type) { $this->assertEqual($count[$key], $type['count'], 'Count matched'); @@ -460,8 +486,8 @@ class DBLogTestCase extends DrupalWebTestCase { $this->assertEqual(array_sum($count), $type_count, 'Count matched'); } - // Set filter to match each of the three type attributes and confirm the - // number of entries displayed. + // Set filter to match each of the two filter-type attributes and confirm + // correct number of entries are displayed. foreach ($types as $key => $type) { $edit = array( 'type[]' => array($type['type']), @@ -472,17 +498,21 @@ class DBLogTestCase extends DrupalWebTestCase { $count = $this->getTypeCount($types); $this->assertEqual(array_sum($count), $type['count'], 'Count matched'); } - + // Clear all logs and make sure the confirmation message is found. $this->drupalPost('admin/reports/dblog', array(), t('Clear log messages')); $this->assertText(t('Database log cleared.'), t('Confirmation message found')); } /** - * Get the log entry information form the page. + * Gets the database log event information from the browser page. * - * @return - * List of entries and their information. + * @return array + * List of dblog events where each event is an array with following keys: + * - severity: (int) A dblog severity constant. + * - type: (string) The type of dblog event. + * - message: (string) The message for this dblog event. + * - user: (string) The user associated with this dblog event. */ protected function getLogEntries() { $entries = array(); @@ -501,11 +531,12 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Get the count of entries per type. + * Gets the count of database log entries by database log event type. * - * @param $types + * @param array $types * The type information to compare against. - * @return + * + * @return array * The count of each type keyed by the key of the $types array. */ protected function getTypeCount(array $types) { @@ -523,11 +554,12 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Get the watchdog severity constant corresponding to the CSS class. + * Gets the watchdog severity constant corresponding to the CSS class. * - * @param $class + * @param string $class * CSS class attribute. - * @return + * + * @return int|null * The watchdog severity constant or NULL if not found. */ protected function getSeverityConstant($class) { @@ -554,11 +586,12 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Extract the text contained by the element. + * Extracts the text contained by the XHTML element. * - * @param $element + * @param SimpleXMLElement $element * Element to extract text from. - * @return + * + * @return string * Extracted text. */ protected function asText(SimpleXMLElement $element) { @@ -569,21 +602,24 @@ class DBLogTestCase extends DrupalWebTestCase { } /** - * Assert messages appear on the log overview screen. + * Confirms that a log message appears on the database log overview screen. + * + * Path: /admin/reports/dblog * * This function should be used only for admin/reports/dblog page, because it - * check for the message link text truncated to 56 characters. Other dblog - * pages have no detail links so contains a full message text. + * checks for the message link text truncated to 56 characters. Other log + * pages have no detail links so they contain the full message text. * - * @param $log_message - * The message to check. - * @param $message + * @param string $log_message + * The database log message to check. + * @param string $message * The message to pass to simpletest. */ protected function assertLogMessage($log_message, $message) { $message_text = truncate_utf8(filter_xss($log_message, array()), 56, TRUE, TRUE); - // After filter_xss() HTML entities should be converted to their characters - // because assertLink() uses this string in xpath() to query DOM. + // After filter_xss(), HTML entities should be converted to their character + // equivalents because assertLink() uses this string in xpath() to query the + // Document Object Model (DOM). $this->assertLink(html_entity_decode($message_text), 0, $message); } }