Index: modules/statistics/statistics.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.admin.inc,v
retrieving revision 1.36
diff -u -p -r1.36 statistics.admin.inc
--- modules/statistics/statistics.admin.inc	2 Dec 2009 14:56:32 -0000	1.36
+++ modules/statistics/statistics.admin.inc	4 Dec 2009 19:57:07 -0000
@@ -269,5 +269,28 @@ function statistics_settings_form() {
     '#description' => t('Increment a counter each time content is viewed.'),
   );
 
+  $form['reset_statistics'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Reset site statistics'),
+    '#description' => t('Reset the statistical information of the site.'),
+  );
+  $form['reset_statistics']['reset'] = array(
+    '#type' => 'submit',
+    '#value' => t('Reset site statistics'),
+    '#submit' => array('statistics_reset_submit'),
+  );
+
   return system_settings_form($form);
 }
+
+/**
+ * Submit callback; clear statistical information.
+ *
+ * @ingroup forms
+ */
+function statistics_reset_submit(&$form_state, $form) {
+  db_truncate('accesslog')->execute();
+  db_truncate('node_counter')->execute();
+
+  drupal_set_message(t('Cleared statistical information.'));
+}
Index: modules/statistics/statistics.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.test,v
retrieving revision 1.12
diff -u -p -r1.12 statistics.test
--- modules/statistics/statistics.test	24 Aug 2009 12:32:10 -0000	1.12
+++ modules/statistics/statistics.test	4 Dec 2009 19:57:07 -0000
@@ -70,3 +70,51 @@ class StatisticsBlockVisitorsTestCase ex
     $this->assertRaw(t('The IP address %ip was deleted.', array('%ip' => $test_ip_address)), t('IP address deleted.'));
   }
 }
+
+class StatisticsTestCase extends DrupalWebTestCase {
+  protected $big_user;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Statistics functionality',
+      'description' => 'Clear the statistics table.',
+      'group' => 'Statistics',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('statistics');
+    // Create user.
+    $this->big_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'access statistics', 'administer statistics'));
+  }
+
+  /**
+   * Login an admin user and clear the statistics tables.
+   */
+  protected function testStatisticsClear() {
+    global $base_root;
+
+    // Enable access logging (redundant since we insert the data manually).
+    variable_set('statistics_enable_access_log', 1);
+    
+    // Login the admin user.
+    $this->drupalLogin($this->big_user);
+
+    // Check the current accesslog status, make a page request and verify.
+    $count_before = db_query("SELECT COUNT(*) FROM {accesslog}")->fetchField();
+    $this->drupalGet('admin/reports/hits');
+    $count_after = db_query("SELECT COUNT(*) FROM {accesslog}")->fetchField();
+    $this->assertEqual($count_before + 1, $count_after, t('Page request added an entry to the accesslog :count_before - :count_after', array(':count_before' => $count_before, ':count_after' => $count_after)));
+
+    // Make post to clear the table.
+    $this->drupalPost('admin/config/system/statistics', array(), t('Reset site statistics'));
+
+    // Test node_counter table.
+    $count = db_query("SELECT COUNT(*) FROM {node_counter}")->fetchField();
+    $this->assertEqual($count, 0, t('The node_counter table contains :count records after a clear.', array(':count' => $count)));
+
+    // Test accesslog table, note that we should already have 2 items in the table!
+    $count = db_query("SELECT COUNT(*) FROM {accesslog}")->fetchField();
+    $this->assertEqual($count, 2, t('The accesslog table contains :count records after a clear.', array(':count' => $count)));
+  }
+}
