summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-05-12 18:08:43 +0000
committerDries Buytaert <dries@buytaert.net>2009-05-12 18:08:43 +0000
commita07e17a92c8dd67da010ce6ff7ede1cb575f577b (patch)
tree93806eeca614d1cb31c5ce1a5a2fc261b9e83539 /modules
parent83ea3cd0424e8b7b3972e5e5c1edbae7af52fd37 (diff)
downloadbrdo-a07e17a92c8dd67da010ce6ff7ede1cb575f577b.tar.gz
brdo-a07e17a92c8dd67da010ce6ff7ede1cb575f577b.tar.bz2
- Patch #210876 by deekayen: log enabling and disabling of modules, and wrote a handy assertLogMessage() function to assert watchdog messages.
Diffstat (limited to 'modules')
-rw-r--r--modules/system/system.test37
1 files changed, 37 insertions, 0 deletions
diff --git a/modules/system/system.test b/modules/system/system.test
index 60c872df0..101390148 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -52,6 +52,40 @@ class ModuleTestCase extends DrupalWebTestCase {
$this->assertEqual(module_exists($module), $enabled, t($message, array('@module' => $module)));
}
}
+
+ /**
+ * Verify a log entry was entered for a module's status change.
+ * Called in the same way of the expected original watchdog() execution.
+ *
+ * @param $type
+ * The category to which this message belongs.
+ * @param $message
+ * The message to store in the log. Keep $message translatable
+ * by not concatenating dynamic values into it! Variables in the
+ * message should be added by using placeholder strings alongside
+ * the variables argument to declare the value of the placeholders.
+ * See t() for documentation on how $message and $variables interact.
+ * @param $variables
+ * Array of variables to replace in the message on display or
+ * NULL if message is already translated or not possible to
+ * translate.
+ * @param $severity
+ * The severity of the message, as per RFC 3164.
+ * @param $link
+ * A link to associate with the message.
+ */
+ function assertLogMessage($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = '') {
+ $count = db_select('watchdog', 'w')
+ ->condition('type', $type)
+ ->condition('message', $message)
+ ->condition('variables', serialize($variables))
+ ->condition('severity', $severity)
+ ->condition('link', $link)
+ ->countQuery()
+ ->execute()
+ ->fetchField();
+ $this->assertTrue($count > 0, t('watchdog table contains @count rows for @message', array('@count' => $count, '@message' => $message)));
+ }
}
/**
@@ -87,6 +121,7 @@ class EnableDisableTestCase extends ModuleTestCase {
$this->assertText(t('hook_modules_enabled fired for aggregator'), t('hook_modules_enabled fired.'));
$this->assertModules(array('aggregator'), TRUE);
$this->assertTableCount('aggregator', TRUE);
+ $this->assertLogMessage('system', "%module module enabled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
// Disable aggregator, check tables, uninstall aggregator, check tables.
$edit = array();
@@ -98,6 +133,7 @@ class EnableDisableTestCase extends ModuleTestCase {
$this->assertText(t('hook_modules_disabled fired for aggregator'), t('hook_modules_disabled fired.'));
$this->assertModules(array('aggregator'), FALSE);
$this->assertTableCount('aggregator', TRUE);
+ $this->assertLogMessage('system', "%module module disabled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
// Uninstall the module.
$edit = array();
@@ -111,6 +147,7 @@ class EnableDisableTestCase extends ModuleTestCase {
$this->assertText(t('hook_modules_uninstalled fired for aggregator'), t('hook_modules_uninstalled fired.'));
$this->assertModules(array('aggregator'), FALSE);
$this->assertTableCount('aggregator', FALSE);
+ $this->assertLogMessage('system', "%module module uninstalled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
}
}