You are here

function UserpointsTestCase::testModeration in User Points 6

File

tests/userpoints_api.test, line 454

Class

UserpointsTestCase

Code

function testModeration() {
  global $user;
  $points = rand(1, 100);

  /** condition1 moderate=TRUE **/
  $params = array(
    'uid' => $user->uid,
    'points' => $points,
    'moderate' => TRUE,
  );

  /* add points to user */
  $return = userpoints_userpointsapi($params);
  $this
    ->assertTrue($return['status'] == TRUE, t("1. (moderate=TRUE) API responded with successful grant of points"));

  /* Check the database to ensure the point were properly saved */
  $sql = "SELECT points FROM {userpoints_txn} WHERE uid = %d AND points = %d AND status = 1";
  $db_points = (int) db_result(db_query($sql, $user->uid, $points));
  $this
    ->assertTrue($db_points == $points, t("1. (moderate=TRUE) Successfully verified points in the txn table and waiting moderation."));

  /* Check do not update point to 'userpoints' table */
  $sql1 = "SELECT points FROM {userpoints} WHERE uid=%d";
  $db_points = (int) db_result(db_query($sql1, $user->uid));
  $this
    ->assertTrue($db_points == 0, t("1. (moderate=TRUE) Successfully verified that points were added and the summary table was not updated."));

  /*
      //DISABLED because it should be checking if it adhered to the sites default moderation status
      $params = array(
        'uid' => $user->uid,
        'points' => $points,
        'moderate' => NULL,
      );
      $return = userpoints_userpointsapi($params);
      $this->assertTrue($return['status'] == TRUE , t("6. (moderate=NULL) API responded with successful grant of points"));
      $sql = "SELECT points FROM {userpoints_txn} WHERE uid = %d AND points = %d AND status = 1";
      $db_points = (int) db_result(db_query($sql, $user->uid, $points));
      $this->assertTrue($db_points == $points,t("6. (moderate=NULL) Successfully verified points in the txn table and waiting moder.") );
      $sql1 = "SELECT points FROM {userpoints} WHERE uid=%d";
      $db_points = (int) db_result(db_query($sql1, $user->uid));
      $this->assertTrue($db_points == 0,t("6. (moderate=NULL) Successfully, Points added and does not modify summary table.") );
  */

  /** condition7 moderate=FALSE **/
  $params = array(
    'uid' => $user->uid,
    'points' => $points,
    'moderate' => FALSE,
  );

  /* add points to user */
  $return = userpoints_userpointsapi($params);
  $this
    ->assertTrue($return['status'] == TRUE, t("7. (moderate=FALSE) API responded with successful grant of points"));

  /* Check the database to ensure the point were properly saved */
  $sql = "SELECT points FROM {userpoints_txn} WHERE uid = %d AND points = %d AND status = 0";
  $db_points = (int) db_result(db_query($sql, $user->uid, $points));
  $this
    ->assertTrue($db_points == $points, t("7. (moderate=FALSE) Successfully verified points in the txn table and NOT waiting moderation."));
}