Here is a test for the dblog module.

I found the following issues:

1) The drupalCreateUser function does not trigger an Add User event logging. Should it?
2) Likewise, the drupalCreateNode function does not trigger an Add Content-Type event logging. Should it?
3) When a user is deleted, any content they created remains but the uid = 0. One side effect is their blog entry shows as "'s blog" on the home page. Is this intended or should the content be deleted or 'reassigned' in some fashion?
4) The following query leaves an extra row in the watchdog table. In other words, if dblog_row_limit = 100, the watchdog table will have 101 rows after this function runs. A where clause of 'wid <= %d' (replace '<' with '<=') would leave 100 rows.

function dblog_cron() {
  // Cleanup the watchdog table
  $max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}'));
  db_query('DELETE FROM {watchdog} WHERE wid < %d', $max - variable_get('dblog_row_limit', 1000));
}
5) In checking the cron functionality, there appears to be something funny with the global $conf array. I noticed this when setting the dblog_row_limit variable by a post from the related administrative form. Based on my tests, there would appear to be multiple copies of the array in memory.

I base this on dumping values from the variable_set and variable_get routines before and after setting the dblog_row_limit variable by a post from the administrative form. The $conf[$name] variable has the new value in the set routine, but has the 'system' value in the get routine (called immediately after). By 'system' value, I mean the value when the SimpleTest is not running.

Later, I manually called the variable_set routine and this value took.

Comments

solotandem’s picture

FileSize
14.19 KB

Due to the recent core changes to the user api, my test did not pass as expected. This version fixes the tests with the exception of the three failures outlined above.

I created a patch for the dblog_cron query at http://drupal.org/node/241629.

boombatower’s picture

Status: Needs review » Fixed

Committed.

Only two intended fails since core patch was committed!

solotandem’s picture

Status: Fixed » Needs review
FileSize
1.83 KB

Simplified some code for consistency with other tests.

boombatower’s picture

Status: Needs review » Fixed

Committed.

Thanks again.

solotandem’s picture

Status: Fixed » Needs review
FileSize
2.06 KB

Changed some code missed with last patch; removed code no longer needed due to core fix of dblog_cron; and corrected a comment.

boombatower’s picture

Status: Needs review » Fixed

Committed.

solotandem’s picture

Status: Fixed » Needs review
FileSize
3.12 KB

This patch resolves item #5 in the original post about the global $conf array. I removed some now unneeded assertions and utilized the internal browser to invoke the cron job instead of calling the api function dblog_cron.

boombatower’s picture

Status: Needs review » Fixed

Committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.