error_log.test 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Error Log module.
  5. */
  6. /**
  7. * Tests Error Log module functionality.
  8. */
  9. class ErrorLogTestCase extends DrupalWebTestCase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected $profile = 'testing';
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public static function getInfo() {
  18. return array(
  19. 'name' => 'Error Log functionality',
  20. 'description' => 'Test Error Log module.',
  21. 'group' => 'error_log',
  22. );
  23. }
  24. /**
  25. * Tests Error Log module.
  26. */
  27. public function testErrorLog() {
  28. $original_error_log = ini_get('error_log');
  29. $error_log = $this->public_files_directory . '/error_log.log';
  30. ini_set('error_log', $error_log);
  31. module_enable(array('error_log'));
  32. try {
  33. db_query('SELECT * FROM {nonexistent_table}', array(':uid' => 0));
  34. }
  35. catch (PDOException $exception) {
  36. watchdog_exception('test', $exception);
  37. }
  38. $log = file($error_log);
  39. $this->assertIdentical(count($log), 3, 'Log has three messages.');
  40. $this->assertIdentical(preg_match('/^\[.*\] \[info\] \[system\] .* error_log module installed\.$/', $log[0]), 1, 'First log message checks out.');
  41. $this->assertIdentical(preg_match('/^\[.*\] \[info\] \[system\] .* error_log module enabled\.$/', $log[1]), 1, 'Second log message checks out.');
  42. $pattern = preg_quote("nonexistent_table' doesn't exist: SELECT * FROM {nonexistent_table}; Array([:uid] => 0) in ErrorLogTestCase");
  43. $this->assertIdentical(preg_match("/^\[.*\] \[error\] \[test\] .*$pattern/", $log[2]), 1, 'Third log message checks out.');
  44. ini_set('error_log', $original_error_log);
  45. }
  46. }