1 system.test ShutdownFunctionsTest::testShutdownFunctions()

Test shutdown functions.

File

core/modules/system/tests/system.test, line 2388
Tests for system.module.

Class

ShutdownFunctionsTest
Functional tests shutdown functions.

Code

function testShutdownFunctions() {
  $arg1 = $this->randomName();
  $arg2 = $this->randomName();
  $this->backdropGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);

  // Now wait a few seconds to ensure that the watchdog entries are written
  // before we check for them.
  sleep(2);

  $shutdown1 = format_string('First shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2));
  $shutdown2 = format_string('Second shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2));

  // Text doesn't show up because the page returns before shutdown functions.
  $this->assertNoText($shutdown1);
  $this->assertNoText($shutdown2);

  // However, the messages should show up in watchdog.
  $shutdown1_log = db_query("SELECT COUNT(*) FROM {watchdog} WHERE message = :string", array(':string' => $shutdown1))->fetchField();
  $shutdown2_log = db_query("SELECT COUNT(*) FROM {watchdog} WHERE message = :string", array(':string' => $shutdown2))->fetchField();
  $this->assertEqual($shutdown1_log, 1, 'Shutdown message 1 logged.');
  $this->assertEqual($shutdown2_log, 1, 'Shutdown message 2 logged.');

  // Make sure exceptions displayed through _backdrop_render_exception_safe()
  // are correctly escaped.
  $message = 'Exception: Backdrop is <blink>awesome</blink>';
  $exception_log = db_query("SELECT COUNT(*) FROM {watchdog} WHERE message LIKE :string", array(':string' => db_like($message) . '%'))->fetchField();
  $this->assertRaw($exception_log, 1, 'Uncaught exception logged.');
}