Commit 9fb534bb authored by webchick's avatar webchick

Issue #1987700 by disasm: Convert error_test() module to a new style controller.

parent 0893c0e6
......@@ -48,9 +48,9 @@ function testErrorCollect() {
$this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected');
if (count($this->collectedErrors) == 3) {
$this->assertError($this->collectedErrors[0], 'Notice', 'error_test_generate_warnings()', 'error_test.module', 'Undefined variable: bananas');
$this->assertError($this->collectedErrors[1], 'Warning', 'error_test_generate_warnings()', 'error_test.module', 'Division by zero');
$this->assertError($this->collectedErrors[2], 'User warning', 'error_test_generate_warnings()', 'error_test.module', 'Drupal is awesome');
$this->assertError($this->collectedErrors[0], 'Notice', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Undefined variable: bananas');
$this->assertError($this->collectedErrors[1], 'Warning', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Division by zero');
$this->assertError($this->collectedErrors[2], 'User warning', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Drupal is awesome');
}
else {
// Give back the errors to the log report.
......
......@@ -37,19 +37,19 @@ function testErrorHandler() {
$error_notice = array(
'%type' => 'Notice',
'!message' => 'Undefined variable: bananas',
'%function' => 'error_test_generate_warnings()',
'%function' => 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()',
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
$error_warning = array(
'%type' => 'Warning',
'!message' => 'Division by zero',
'%function' => 'error_test_generate_warnings()',
'%function' => 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()',
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
$error_user_notice = array(
'%type' => 'User warning',
'!message' => 'Drupal is awesome',
'%function' => 'error_test_generate_warnings()',
'%function' => 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()',
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
......@@ -97,14 +97,14 @@ function testExceptionHandler() {
$error_exception = array(
'%type' => 'Exception',
'!message' => 'Drupal is awesome',
'%function' => 'error_test_trigger_exception()',
'%function' => 'Drupal\error_test\Controller\ErrorTestController->triggerException()',
'%line' => 56,
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
$error_pdo_exception = array(
'%type' => 'DatabaseExceptionWrapper',
'!message' => 'SELECT * FROM bananas_are_awesome',
'%function' => 'error_test_trigger_pdo_exception()',
'%function' => 'Drupal\error_test\Controller\ErrorTestController->triggerPDOException()',
'%line' => 64,
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
......
<?php
/**
* Implements hook_menu().
*/
function error_test_menu() {
$items['error-test/generate-warnings'] = array(
'title' => 'Generate warnings',
'page callback' => 'error_test_generate_warnings',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['error-test/generate-warnings-with-report'] = array(
'title' => 'Generate warnings with Simpletest reporting',
'page callback' => 'error_test_generate_warnings',
'page arguments' => array(TRUE),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['error-test/trigger-exception'] = array(
'title' => 'Trigger an exception',
'page callback' => 'error_test_trigger_exception',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['error-test/trigger-pdo-exception'] = array(
'title' => 'Trigger a PDO exception',
'page callback' => 'error_test_trigger_pdo_exception',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Menu callback; generate warnings to test the error handler.
*/
function error_test_generate_warnings($collect_errors = FALSE) {
// Tell Drupal error reporter to send errors to Simpletest or not.
define('SIMPLETEST_COLLECT_ERRORS', $collect_errors);
// This will generate a notice.
$monkey_love = $bananas;
// This will generate a warning.
$awesomely_big = 1/0;
// This will generate a user error.
trigger_error("Drupal is awesome", E_USER_WARNING);
return "";
}
/**
* Menu callback; trigger an exception to test the exception handler.
*/
function error_test_trigger_exception() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
throw new Exception("Drupal is awesome");
}
/**
* Menu callback; trigger an exception to test the exception handler.
*/
function error_test_trigger_pdo_exception() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
db_query('SELECT * FROM bananas_are_awesome');
}
error_test_generate_warnings:
pattern: '/error-test/generate-warnings'
defaults:
_content: '\Drupal\error_test\Controller\ErrorTestController::generateWarnings'
requirements:
_access: 'TRUE'
error_test_generate_warnings_with_report:
pattern: '/error-test/generate-warnings-with-report'
defaults:
_content: '\Drupal\error_test\Controller\ErrorTestController::generateWarnings'
collect_errors: TRUE
requirements:
_access: 'TRUE'
error_test_trigger_exception:
pattern: '/error-test/trigger-exception'
defaults:
_content: '\Drupal\error_test\Controller\ErrorTestController::triggerException'
requirements:
_access: 'TRUE'
error_test_trigger_pdo_exception:
pattern: '/error-test/trigger-pdo-exception'
defaults:
_content: '\Drupal\error_test\Controller\ErrorTestController::triggerPDOException'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\error_test\Controller\ErrorTestController.
*/
namespace Drupal\error_test\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller routines for error_test routes.
*/
class ErrorTestController extends ControllerBase {
/**
* Generate warnings to test the error handler.
*/
public function generateWarnings($collect_errors = FALSE) {
// Tell Drupal error reporter to send errors to Simpletest or not.
define('SIMPLETEST_COLLECT_ERRORS', $collect_errors);
// This will generate a notice.
$monkey_love = $bananas;
// This will generate a warning.
$awesomely_big = 1/0;
// This will generate a user error.
trigger_error("Drupal is awesome", E_USER_WARNING);
return "";
}
/**
* Trigger an exception to test the exception handler.
*/
public function triggerException() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
throw new \Exception("Drupal is awesome");
}
/**
* Trigger an exception to test the PDO exception handler.
*/
public function triggerPDOException() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
$this->container->get('database')->query('SELECT * FROM bananas_are_awesome');
}
}
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