? fix_tests.patch
Index: userpoints.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/userpoints/userpoints.module,v
retrieving revision 1.67.2.61
diff -u -p -r1.67.2.61 userpoints.module
--- userpoints.module	15 Jul 2010 21:52:34 -0000	1.67.2.61
+++ userpoints.module	10 Aug 2010 08:39:52 -0000
@@ -629,13 +629,16 @@ function userpoints_userpointsapi($param
       );
     }
   }
-  if ($params['points'] < 0) {
+  if (isset($params['points']) && $params['points'] < 0) {
     $msg = t('lost');
   }
-  elseif ($params['status'] == 2) {
+  elseif (isset($params['status']) && $params['status'] == 2) {
     //points have been declined
     $msg = t('was declined');
   }
+  elseif (!empty($params['expired'])) {
+    $msg = t('expired');
+  }
   else {
     $msg = t('earned');
   }
@@ -668,7 +671,7 @@ function userpoints_userpointsapi($param
         ))));
   } //if $params['status']
 
-  if ($mesg && ($params['display'] || ($params['display'] === NULL && variable_get(USERPOINTS_DISPLAY_MESSAGE, 1) == 1))) {
+  if ($mesg && (!empty($params['display']) || (!array_key_exists('display', $params) && variable_get(USERPOINTS_DISPLAY_MESSAGE, 1) == 1))) {
     drupal_set_message($mesg);
   }
   // Call the _userpoints hook to allow modules to act after points are awarded
@@ -1095,7 +1098,7 @@ function userpoints_admin_txn($form_stat
     '#title'         => t('User Name'),
     '#size'          => 30,
     '#maxlength'     => 60,
-    '#default_value' => $txn_user->name,
+    '#default_value' => !empty($txn_user->name) ? $txn_user->name : '',
     '#autocomplete_path' => 'user/autocomplete',
     '#description'   => t('User Name for the user you want the !points to affect', userpoints_translation()),
   );
@@ -1105,7 +1108,7 @@ function userpoints_admin_txn($form_stat
     '#title'         => t('Points'),
     '#size'          => 10,
     '#maxlength'     => 10,
-    '#default_value' => $txn->points,
+    '#default_value' => isset($txn->points) ? $txn->points : 0,
     '#description'   => t('Number of !points to add/subtract from the user. For example, 25 (to add !points) or -25 (to subtract !points).', userpoints_translation()),
   );
 
@@ -1118,8 +1121,8 @@ function userpoints_admin_txn($form_stat
     '#description'   => t('Date and time of this transaction, in the form YYYY-MM-DD HH:MM +ZZZZ'),
   );
 
-  if ($txn->txn_id) {
-    if ($txn->expirydate > 0) {
+  if (!empty($txn->txn_id)) {
+    if (!empty($txn->expirydate)) {
       $expirydate = format_date($txn->expirydate, 'custom', 'Y-m-d H:i O');
     }
   }
@@ -1152,7 +1155,7 @@ function userpoints_admin_txn($form_stat
   $form['reference'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Reference'),
-    '#default_value' => $txn->reference,
+    '#default_value' => !empty($txn->reference) ? $txn->reference : '',
     '#size'          => 30,
     '#maxlength'     => 128,
     '#description'   => t('Enter optional reference for this transaction. This field will be indexed and searchable.'),
@@ -1161,7 +1164,7 @@ function userpoints_admin_txn($form_stat
   $form['description'] = array(
     '#type'          => 'textarea',
     '#title'         => t('Description'),
-    '#default_value' => $txn->description,
+    '#default_value' => !empty($txn->description) ? $txn->description : '',
     '#width'         => 70,
     '#lines'         => 5,
     '#description'   => t('Enter an optional description for this transaction, such as the reason it is created.'),
@@ -1337,6 +1340,7 @@ function userpoints_admin_points() {
   $sql .= tablesort_sql($header);
   $pager_limit = variable_get(USERPOINTS_REPORT_USERCOUNT, 30);
   $result = pager_query($sql, $pager_limit, 0, $sql_cnt, $tid);
+  $rows = array();
   while ($data = db_fetch_object($result)) {
     if (!$data->cat) {
       $data->cat = t('!Uncategorized', userpoints_translation());
Index: tests/userpoints_api.test
===================================================================
RCS file: /cvs/drupal/contributions/modules/userpoints/tests/Attic/userpoints_api.test,v
retrieving revision 1.1.2.11
diff -u -p -r1.1.2.11 userpoints_api.test
--- tests/userpoints_api.test	15 Jul 2010 21:52:34 -0000	1.1.2.11
+++ tests/userpoints_api.test	10 Aug 2010 08:39:52 -0000
@@ -303,45 +303,40 @@ class UserpointsTestCase extends DrupalW
     $this->assertTrue($db_points == $keep_points, t("Successfully removed expired points from the summary table.") );
   }
 
-  /*
+   /**
    * Changes the default expiration date in the administrative settings
    * and then checks to ensure that it is saved/returned correctly.
-  */
-  function test_get_default_expiry_date() {
+   */
+  function testDefaultExpireDate() {
      //login as an admin
     global $admin_user;
     $this->drupalLogin($admin_user);
 
-    $date = mktime(0, 0, 0, 1, 1, 2010);
+    // Use a date in the future.
+    $date = time() + 100000;
+    $date_array = array(
+      'month' => date('n', $date),
+      'day'   => date('d', $date),
+      'year'  => date('Y', $date),
+    );
 
-    /* save settings */
+    // save settings.
     $edit = array(
-      'userpoints_points_moderation' => '1',
-      'userpoints_trans_ucpoints' => 'Points',
-      'userpoints_trans_lcpoints' => 'points',
-      'userpoints_trans_lcpoint' => 'point',
-      'userpoints_trans_uncat' => 'Uncategorized',
-      'userpoints_expireafter_date' => '2419200',
-      'userpoints_expireon_date[month]' => '1',
-      'userpoints_expireon_date[day]' => '1',
-      'userpoints_expireon_date[year]' => '2010',
-      'userpoints_expiry_description' => '',
-      'userpoints_display_message' => '1',
-      'userpoints_report_limit' => '10',
-      'userpoints_report_displayzero' => '1',
-      'userpoints_report_usercount' => '30',
-      'userpoints_category_default_tid' => '0',
+      'userpoints_expireon_date[month]' => $date_array['month'],
+      'userpoints_expireon_date[day]' => $date_array['day'],
+      'userpoints_expireon_date[year]' => $date_array['year'],
     );
     $this->drupalPost('admin/settings/userpoints', $edit, 'Save configuration');
 
-    /* check database */
-    $sql = "SELECT value FROM {variable} WHERE name='%s'";
-    $expireon_date = db_result(db_query($sql, 'userpoints_expireon_date'));
-    $this->assertTrue($expireon_date != FALSE, t("Successfully verified the expiriation date in the database."));
+    // Check database.
+    $database_date = variable_get('userpoints_expireon_date', FALSE);
+    $this->assertEqual($database_date['day'], $date_array['day']);
+    $this->assertEqual($database_date['month'], $date_array['month']);
+    $this->assertEqual($database_date['year'], $date_array['year']);
 
-    /* check API */
+    // Check API.
     $expiry_date = userpoints_get_default_expiry_date();
-    $this->assertTrue($expiry_date == $date, t("Successfully verified that userpoints_get_expiry_date returns correct date is %s.", array('%s' => date("M-d-Y", $expiry_date))));
+    $this->assertEqual($expiry_date, userpoints_date_to_timestamp($date_array));
   }
 
 
@@ -351,15 +346,12 @@ class UserpointsTestCase extends DrupalW
     $desc = $this->randomName(10);
 
     /* create a new term*/
-    $new_term = array(
+    $term = array(
       'name' => $term_name,
       'description' => $desc,
-      'vid' => $vid
+      'vid' => $vid,
     );
-    taxonomy_save_term($new_term);
-
-    /* get this term */
-    $term = taxonomy_get_term_by_name($term_name);
+    taxonomy_save_term($term);
 
     /* login as admin userpoints */
     $admin_user = $this->drupalCreateUser(array('administer userpoints'));
@@ -367,41 +359,17 @@ class UserpointsTestCase extends DrupalW
 
     /* save settings */
     $edit = array(
-      'userpoints_points_moderation' => '1',
-      'userpoints_trans_ucpoints' => 'Points',
-      'userpoints_trans_lcpoints' => 'points',
-      'userpoints_trans_lcpoint' => 'point',
-      'userpoints_trans_uncat' => 'Uncategorized',
-      'userpoints_expireafter_date' => '2419200',
-      'userpoints_expireon_date[month]' => '1',
-      'userpoints_expireon_date[day]' => '1',
-      'userpoints_expireon_date[year]' => '2010',
-      'userpoints_expiry_description' => '',
-      'userpoints_display_message' => '1',
-      'userpoints_report_limit' => '10',
-      'userpoints_report_displayzero' => '1',
-      'userpoints_report_usercount' => '30',
-      'userpoints_category_default_tid' => $term[0]->tid,
+      'userpoints_category_default_tid' => $term['tid'],
     );
     $this->drupalPost('admin/settings/userpoints', $edit, 'Save configuration');
 
-    /* check database */
-    $sql = "SELECT value FROM {variable} WHERE name='%s'";
-    $expireon_date = db_result(db_query($sql, 'userpoints_category_default_tid'));
-    $this->assertTrue($expireon_date != FALSE, t("Successfully verified the term ID in the database."));
-
     /* check API*/
     $tid = userpoints_get_default_tid();
-    $this->assertTrue($tid == 0, t("Successfully retrieved default tid = %d.", array('%d' => $tid)));
-
-    /* check database */
-    $sql = "SELECT value FROM {variable} WHERE name='%s'";
-    $expireon_date = db_result(db_query($sql, 'userpoints_category_default_vid'));
-    $this->assertTrue($expireon_date != FALSE, t("Successfully verified the vocab ID in the database."));
+    $this->assertTrue($tid == $term['tid'], t("Successfully retrieved default tid = %d.", array('%d' => $tid)));
 
     /* check API*/
-    $vid = userpoints_get_vid();
-    $this->assertTrue(is_numeric($vid), t("Successfully retrieved default vid %d.", array('%d' => $vid)));
+    $api_vid = userpoints_get_vid();
+    $this->assertEqual($api_vid, $vid, t("Successfully retrieved default vid %d.", array('%d' => $vid)));
   }
   /**
    * Test user permissions
