You are here

function UserpointsAPITestCase::testEditingTransactions in User Points 7

Test that editing points correctly updates the current and max points.

File

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

Class

UserpointsAPITestCase
API Tests.

Code

function testEditingTransactions() {

  // First, add some points to two different categories.
  $uid = $this->non_admin_user->uid;
  $params = array(
    'points' => 100,
    'tid' => 0,
    'uid' => $uid,
  );
  userpoints_userpointsapi($params);
  $params = array(
    'points' => 50,
    'tid' => 1,
    'uid' => $uid,
  );
  userpoints_userpointsapi($params);

  // Add a third transaction that can be edited.
  $params = array(
    'points' => 5,
    'tid' => 0,
    'uid' => $uid,
  );
  $return = userpoints_userpointsapi($params);
  $txn_id = $return['transaction']['txn_id'];

  // Verify points up to this point.
  $this
    ->verifyPoints($uid, 105, 105, 0);
  $this
    ->verifyPoints($uid, 50, 50, 1);

  // Now, edit the transaction. Mix any combination of point, category and
  // status changes. After the change, verify current and max points.
  // Points change.
  $params = array(
    'txn_id' => $txn_id,
    'points' => -5,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 95, 105, 0);

  // Change status to pending.
  $params = array(
    'txn_id' => $txn_id,
    'status' => USERPOINTS_TXN_STATUS_PENDING,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 100, 105, 0);

  // Change status back to approved.
  $params = array(
    'txn_id' => $txn_id,
    'status' => USERPOINTS_TXN_STATUS_APPROVED,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 95, 105, 0);

  // Change category.
  $params = array(
    'txn_id' => $txn_id,
    'tid' => 1,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 100, 105, 0);
  $this
    ->verifyPoints($uid, 45, 50, 1);

  // Change points and status.
  $params = array(
    'txn_id' => $txn_id,
    'points' => 3,
    'status' => USERPOINTS_TXN_STATUS_PENDING,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 100, 105, 0);
  $this
    ->verifyPoints($uid, 50, 50, 1);

  // Change status back to approved.
  $params = array(
    'txn_id' => $txn_id,
    'status' => USERPOINTS_TXN_STATUS_APPROVED,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 53, 53, 1);

  // Change points and category.
  $params = array(
    'txn_id' => $txn_id,
    'points' => 9,
    'tid' => 0,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 109, 109, 0);
  $this
    ->verifyPoints($uid, 50, 53, 1);

  // Change points and status and category.
  $params = array(
    'txn_id' => $txn_id,
    'points' => 10,
    'tid' => 1,
    'status' => USERPOINTS_TXN_STATUS_DECLINED,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 100, 109, 0);
  $this
    ->verifyPoints($uid, 50, 53, 1);

  // Change points and status back to approved.
  $params = array(
    'txn_id' => $txn_id,
    'points' => 4,
    'status' => USERPOINTS_TXN_STATUS_APPROVED,
  );
  userpoints_userpointsapi($params);
  $this
    ->verifyPoints($uid, 100, 109, 0);
  $this
    ->verifyPoints($uid, 54, 54, 1);
  $this
    ->verifyPoints($uid, 154, 159, 'all');
}