Commit 60c06921 authored by Dries's avatar Dries

- Patch #291026 by Dave Reid et al: further (usability) improvements to the E_NOTICE handling.

parent 18e62bf8
......@@ -48,6 +48,7 @@ function dblog_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('dblog_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
);
$items['admin/reports/dblog'] = array(
'title' => 'Recent log entries',
......
......@@ -492,33 +492,95 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
* Test the error handler.
*/
function testErrorHandler() {
$error_notice = array(
'%type' => 'Notice',
'%message' => 'Undefined variable: bananas',
'%function' => 'system_test_generate_warnings()',
'%line' => 184,
'%file' => realpath('modules/simpletest/tests/system_test.module'),
);
$error_warning = array(
'%type' => 'Warning',
'%message' => 'Division by zero',
'%function' => 'system_test_generate_warnings()',
'%line' => 186,
'%file' => realpath('modules/simpletest/tests/system_test.module'),
);
$error_user_notice = array(
'%type' => 'User notice',
'%message' => 'Drupal is awesome',
'%function' => 'system_test_generate_warnings()',
'%line' => 188,
'%file' => realpath('modules/simpletest/tests/system_test.module'),
);
// Set error reporting to collect notices.
variable_set('error_level', 2);
$this->drupalGet('system-test/generate-warnings');
$this->assertErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
$this->assertErrorMessage('Notice', 'system_test.module', 'system_test_generate_warnings() ', 'Undefined variable');
$this->assertErrorMessage('Warning', 'system_test.module', 'system_test_generate_warnings() ', 'Division by zero');
$this->assertErrorMessage('User notice', 'system_test.module', 'system_test_generate_warnings() ', 'Drupal is awesome');
// Set error reporting to not collect notices.
variable_set('error_level', 1);
$this->drupalGet('system-test/generate-warnings');
$this->assertNoErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
// Set error reporting to not show any errors.
variable_set('error_level', 0);
$this->drupalGet('system-test/generate-warnings');
$this->assertNoErrorMessage($error_notice);
$this->assertNoErrorMessage($error_warning);
$this->assertNoErrorMessage($error_user_notice);
}
/**
* Test the exception handler.
*/
function testExceptionHandler() {
$error_exception = array(
'%type' => 'Exception',
'%message' => 'Drupal is awesome',
'%function' => 'system_test_trigger_exception()',
'%line' => 197,
'%file' => realpath('modules/simpletest/tests/system_test.module'),
);
$error_pdo_exception = array(
'%type' => 'PDOException',
'%message' => 'SQLSTATE',
'%function' => 'system_test_trigger_pdo_exception()',
'%line' => 205,
'%file' => realpath('modules/simpletest/tests/system_test.module'),
);
$this->drupalGet('system-test/trigger-exception');
$this->assertErrorMessage('Exception', 'system_test.module', 'system_test_trigger_exception()', 'Drupal is awesome');
$this->assertErrorMessage($error_exception);
$this->drupalGet('system-test/trigger-pdo-exception');
// We only check for SQLSTATE because the exact error reported varies from database to database.
$this->assertErrorMessage('PDOException', 'system_test.module', 'system_test_trigger_pdo_exception()', 'SQLSTATE');
// We cannot use assertErrorMessage() since the extact error reported
// varies from database to database. Check for the error keyword 'SQLSTATE'.
$this->assertText($error_pdo_exception['%type'], t('Found %type in error page.', $error_pdo_exception));
$this->assertText($error_pdo_exception['%message'], t('Found %message in error page.', $error_pdo_exception));
$error_details = t('in %function (line %line of %file)', $error_pdo_exception);
$this->assertRaw($error_details, t("Found '!message' in error page.", array('!message' => $error_details)));
}
/**
* Helper function: assert that the logged message is correct.
* Helper function: assert that the error message is found.
*/
function assertErrorMessage($type, $file, $function, $message) {
$this->assertText($type, t("Found '%type' in error page.", array('%type' => $type)));
$this->assertText($file, t("Found '%file' in error page.", array('%file' => $file)));
$this->assertText($function, t("Found '%function' in error page.", array('%function' => $function)));
$this->assertText($message, t("Found '%message' in error page.", array('%message' => $message)));
function assertErrorMessage(array $error) {
$message = t('%type: %message in %function (line %line of %file).', $error);
$this->assertRaw($message, t('Error !message found.', array('!message' => $message)));
}
/**
* Helper function: assert that the error message is not found.
*/
function assertNoErrorMessage(array $error) {
$message = t('%type: %message in %function (line %line of %file).', $error);
$this->assertNoRaw($message, t('Error !message not found.', array('!message' => $message)));
}
}
......@@ -700,4 +762,4 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase {
$this->assertEqual($error['message'], $message, t("Message was %message", array('%message' => $message)));
}
}
}
\ No newline at end of file
}
......@@ -28,11 +28,12 @@ function syslog_help($path, $arg) {
function syslog_menu() {
$items['admin/settings/logging/syslog'] = array(
'title' => 'Syslog',
'description' => 'Settings for syslog logging. Syslog is an operating system administrative logging tool used in systems management and security auditing. Most suited to medium and large sites, syslog provides filtering tools that allow messages to be routed by type and severity.',
'page callback' => 'drupal_get_form',
'title' => 'Syslog logging',
'description' => 'Settings for syslog logging. Syslog is an operating system administrative logging tool used in systems management and security auditing. Most suited to medium and large sites, syslog provides filtering tools that allow messages to be routed by type and severity.',
'page callback' => 'drupal_get_form',
'page arguments' => array('syslog_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
......
......@@ -1225,9 +1225,25 @@ function system_site_information_settings() {
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
'#required' => TRUE,
);
$form['site_403'] = array(
'#type' => 'textfield',
'#title' => t('Default 403 (access denied) page'),
'#default_value' => '',
'#size' => 40,
'#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'),
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
);
$form['site_404'] = array(
'#type' => 'textfield',
'#title' => t('Default 404 (not found) page'),
'#default_value' => '',
'#size' => 40,
'#description' => t('This page is displayed when no other content matches the requested document. If unsure, specify nothing.'),
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
);
$form['#validate'][] = 'system_site_information_settings_validate';
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......@@ -1256,23 +1272,7 @@ function system_site_information_settings_validate($form, &$form_state) {
* @ingroup forms
* @see system_settings_form()
*/
function system_error_reporting_settings() {
$form['site_403'] = array(
'#type' => 'textfield',
'#title' => t('Default 403 (access denied) page'),
'#default_value' => '',
'#size' => 40,
'#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'),
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
);
$form['site_404'] = array(
'#type' => 'textfield',
'#title' => t('Default 404 (not found) page'),
'#default_value' => '',
'#size' => 40,
'#description' => t('This page is displayed when no other content matches the requested document. If unsure, specify nothing.'),
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
);
function system_logging_settings() {
$form['error_level'] = array(
'#type' => 'radios',
'#title' => t('Error reporting'),
......@@ -1288,18 +1288,6 @@ function system_error_reporting_settings() {
return system_settings_form($form);
}
/**
* Menu callback; Menu page for the various logging options.
*/
function system_logging_overview() {
$item = menu_get_item('admin/settings/logging');
$content = system_admin_menu_block($item);
$output = theme('admin_block_content', $content);
return $output;
}
/**
* Form builder; Configure site performance settings.
*
......
......@@ -586,18 +586,18 @@ function system_menu() {
'page arguments' => array('system_site_information_settings'),
'access arguments' => array('administer site configuration'),
);
$items['admin/settings/error-reporting'] = array(
'title' => 'Error reporting',
'description' => 'Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.',
$items['admin/settings/logging'] = array(
'title' => 'Logging, errors and alerts',
'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destination, such as syslog, database, email, ...etc.",
'page callback' => 'drupal_get_form',
'page arguments' => array('system_error_reporting_settings'),
'page arguments' => array('system_logging_settings'),
'access arguments' => array('administer site configuration'),
);
$items['admin/settings/logging'] = array(
'title' => 'Logging and alerts',
'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destination, such as syslog, database, email, ...etc.",
'page callback' => 'system_logging_overview',
$items['admin/settings/logging/settings'] = array(
'title' => 'Settings',
'access arguments' => array('administer site configuration'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/settings/performance'] = array(
'title' => 'Performance',
......@@ -1298,7 +1298,7 @@ function _system_settings_form_automatic_defaults($form) {
$form[$key] = _system_settings_form_automatic_defaults($form[$key]);
}
}
return $form;
}
......@@ -1319,7 +1319,7 @@ function system_settings_form($form, $automatic_defaults = TRUE) {
if ($automatic_defaults) {
$form = _system_settings_form_automatic_defaults($form);
}
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
}
......
......@@ -450,7 +450,7 @@ class AccessDeniedTestCase extends DrupalWebTestCase {
$node = $this->drupalCreateNode($edit);
// Use a custom 403 page.
$this->drupalPost('admin/settings/error-reporting', array('site_403' => 'node/' . $node->nid), t('Save configuration'));
$this->drupalPost('admin/settings/site-information', array('site_403' => 'node/' . $node->nid), t('Save configuration'));
$this->drupalGet('admin');
$this->assertText($node->title, t('Found the custom 403 page'));
......@@ -464,7 +464,7 @@ class AccessDeniedTestCase extends DrupalWebTestCase {
// Log back in and remove the custom 403 page.
$this->drupalLogin($this->admin_user);
$this->drupalPost('admin/settings/error-reporting', array(), t('Reset to defaults'));
$this->drupalPost('admin/settings/site-information', array(), t('Reset to defaults'));
// Logout and check that the user login block is shown on default 403 pages.
$this->drupalLogout();
......@@ -511,7 +511,7 @@ class PageNotFoundTestCase extends DrupalWebTestCase {
$node = $this->drupalCreateNode($edit);
// Use a custom 404 page.
$this->drupalPost('admin/settings/error-reporting', array('site_404' => 'node/' . $node->nid), t('Save configuration'));
$this->drupalPost('admin/settings/site-information', array('site_404' => 'node/' . $node->nid), t('Save configuration'));
$this->drupalGet($this->randomName(10));
$this->assertText($node->title, t('Found the custom 404 page'));
......@@ -525,7 +525,7 @@ class PageNotFoundTestCase extends DrupalWebTestCase {
// Log back in and remove the custom 404 page.
$this->drupalLogin($this->admin_user);
$this->drupalPost('admin/settings/error-reporting', array(), t('Reset to defaults'));
$this->drupalPost('admin/settings/site-information', array(), t('Reset to defaults'));
// Logout and check that the user login block is not shown on default 404 pages.
$this->drupalLogout();
......@@ -778,16 +778,16 @@ class SystemSettingsForm extends DrupalWebTestCase {
function tearDown() {
variable_del('system_settings_form_test');
variable_del('system_settings_form_test_4');
parent::tearDown();
}
/**
* Tests the handling of automatic defaults in systems_settings_form().
*/
function testAutomaticDefaults() {
$form = array();
$form['system_settings_form_test'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
......@@ -819,7 +819,6 @@ class SystemSettingsForm extends DrupalWebTestCase {
$this->assertTrue($automatic['system_settings_form_test_3']['#default_value']);
$this->assertFalse($automatic['has_children']['system_settings_form_test_4']['#default_value']);
$this->assertTrue($automatic['has_children']['system_settings_form_test_5']['#default_value']);
$no_automatic = system_settings_form($form);
$this->assertTrue($no_automatic['system_settings_form_test']['#default_value']);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment