Index: modules/dblog/dblog.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/dblog/dblog.test,v
retrieving revision 1.39
diff -u -p -r1.39 dblog.test
--- modules/dblog/dblog.test	1 Sep 2010 03:03:05 -0000	1.39
+++ modules/dblog/dblog.test	2 Oct 2010 13:04:34 -0000
@@ -67,17 +67,72 @@ class DBLogTestCase extends DrupalWebTes
    * @param integer $count Log row limit.
    */
   private function verifyCron($row_limit) {
-    // Generate additional log entries.
+    // Run Cron when dblog row count exceeds row limit.
     $this->generateLogEntries($row_limit + 10);
     // Verify dblog row count exceeds row limit.
     $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
-    $this->assertTrue($count > $row_limit, t('Dblog row count of @count exceeds row limit of @limit', array('@count' => $count, '@limit' => $row_limit)));
+    $this->assertTrue($count > $row_limit, t('Dblog row count of :count exceeds row limit of :limit', array(':count' => $count, ':limit' => $row_limit)));
+    // Run cron job.
+    $this->cronRun();
+    // Verify dblog row count equals row limit plus one because cron adds a record after it runs.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == $row_limit + 1, t('Dblog row count of :count equals row limit of :limit plus one', array(':count' => $count, ':limit' => $row_limit)));
 
+    // Run Cron when dblog row count is equal to the row limit.
+    db_query('DELETE FROM {watchdog}');
+    $this->generateLogEntries($row_limit);
+    // Verify dblog row count is equal to row limit.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == $row_limit, t('Dblog row count of :count is equal to row limit of :limit', array(':count' => $count, ':limit' => $row_limit)));
+    // Run cron job.
+    $this->cronRun();
+    // Verify dblog row count equals row limit plus one because cron adds a record after it runs.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == $row_limit + 1, t('Dblog row count of :count equals row limit of :limit plus one', array(':count' => $count, ':limit' => $row_limit)));
+
+    // Run Cron when dblog row count is less than the row limit.
+    $decrease = 10;
+    db_query('DELETE FROM {watchdog}');
+    $this->generateLogEntries($row_limit - $decrease);
+    // Verify dblog row count is less than row limit.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == $row_limit - $decrease, t('Dblog row count of :count is :decrease less than row limit of :limit', array(':count' => $count, ':limit' => $row_limit, ':decrease' => $decrease)));
+    // Run cron job.
+    $this->cronRun();
+    // Verify dblog row count is the same plus one because cron adds a record after it runs.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == ($row_limit - $decrease) + 1, t('Dblog row count of :count is :decrease less than row limit of :limit plus one', array(':count' => $count, ':limit' => $row_limit, ':decrease' => $decrease)));
+
+    // Run Cron when dblog row count is zero, e.g. like when table is truncated.
+    db_query('DELETE FROM {watchdog}');
+    // Verify dblog row count is zero.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == 0, t('Dblog row count of :count equals an empty table', array(':count' => $count)));
+    // Run cron job.
+    $this->cronRun();
+    // Verify dblog row count equals 0 plus one because cron adds a record after it runs.
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == 1, t('Dblog row count of :count equals an empty table plus one', array(':count' => $count)));
+
+    // Run Cron when some dblog rows have been deleted out wid order.
+    // Generate 3 sets of log entries, each set equal to row limit.
+    // Create delimiting markers between the sets using the wid field.
+    db_query('DELETE FROM {watchdog}');
+    $this->generateLogEntries($row_limit);
+    $marker1 = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
+    $this->generateLogEntries($row_limit);
+    $marker2 = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
+    $this->generateLogEntries($row_limit);
+    // Delete the middle set.
+    db_query('DELETE FROM {watchdog} WHERE wid > :marker1 AND wid <= :marker2', array(':marker1' => $marker1, ':marker2' => $marker2));
+    // Verify dblog row count equals twice the row limit (2 remaining sets).
+    $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
+    $this->assertTrue($count == $row_limit * 2, t('Dblog row count of :count is twice the row limit of :limit', array(':count' => $count, ':limit' => $row_limit)));
     // Run cron job.
     $this->cronRun();
     // Verify dblog row count equals row limit plus one because cron adds a record after it runs.
     $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
-    $this->assertTrue($count == $row_limit + 1, t('Dblog row count of @count equals row limit of @limit plus one', array('@count' => $count, '@limit' => $row_limit)));
+    $this->assertTrue($count == $row_limit + 1, t('Dblog row count of :count equals row limit of :limit plus one', array(':count' => $count, ':limit' => $row_limit)));
   }
 
   /**
