You are here

function UserpointsAPITestCase::testModeration in User Points 7

File

tests/userpoints_api.test, line 521
Contains test classes for userpoints module.

Class

UserpointsAPITestCase
API Tests.

Code

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

  // condition1 moderate=TRUE.
  $params = array(
    'uid' => $this->non_admin_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.
  $this
    ->assertTrue($this
    ->getTxnPoints($this->non_admin_user->uid, $points) == $points, t("1. (moderate=TRUE) Successfully verified points in the txn table and waiting moderation."));

  // Check do not update point to 'userpoints' table.
  $this
    ->assertTrue($this
    ->getPoints($this->non_admin_user->uid) == 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' => $this->non_admin_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, $this->non_admin_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, $this->non_admin_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' => $this->non_admin_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 = :uid AND points = :points AND status = 0";
  $db_points = (int) db_query($sql, array(
    ':uid' => $this->non_admin_user->uid,
    ':points' => $points,
  ))
    ->fetchField();
  $this
    ->assertTrue($db_points == $points, t("7. (moderate=FALSE) Successfully verified points in the txn table and NOT waiting moderation."));
}