function UserpointsTestCase::testParamsArrayCall in User Points 6
File
- tests/userpoints_api.test, line 114
Class
- UserpointsTestCase
Code
function testParamsArrayCall() {
global $user;
global $admin_user;
$points = rand();
$params = array(
'points' => $points,
);
$this
->assertTrue(userpoints_userpointsapi($params) == TRUE, t('API call using a params array responded with successful grant of points'));
$sql = "SELECT points from {userpoints_txn} WHERE uid = %d AND points = %d";
$db_points = db_result(db_query($sql, $user->uid, $points));
$this
->assertTrue($db_points == $points, t('Successfully verified points in the txn table'));
$params = array(
'points' => '',
);
$return = userpoints_userpointsapi($params);
$this
->assertTrue($return['status'] == FALSE, t('API successfully prevented null points from being added'));
$params = array(
'points' => 'abcd',
);
$return = userpoints_userpointsapi($params);
$this
->assertTrue($return['status'] == FALSE, t('API successfully prevented non-numeric points from being added'));
$params = array(
'points' => $points,
'uid' => $admin_user->uid,
);
$this
->assertTrue(userpoints_userpointsapi($params) == TRUE, t('Successfully granted points to admin user'));
$sql = "SELECT points from {userpoints_txn} WHERE uid = %d AND points = %d";
$db_points = db_result(db_query($sql, $admin_user->uid, $points));
$this
->assertTrue($db_points == $points, t('Successfully verified points in the txn table'));
$sql = "SELECT uid FROM {users} ORDER BY uid DESC";
$nonuid = db_result(db_query_range($sql, 0, 1)) + 1;
$params = array(
'points' => $points,
'uid' => $nonuid,
);
$ret = userpoints_userpointsapi($params);
$this
->assertTrue($ret['status'] == FALSE, t('Successfully blocked points given to a non-existent user'));
$maxtid = "SELECT tid from {term_data} ORDER BY tid DESC";
$nontid = db_result(db_query_range($sql, 0, 1)) + 1;
$params = array(
'points' => $points,
'uid' => $nontid,
);
$ret = userpoints_userpointsapi($params);
$this
->assertTrue($ret['status'] == FALSE, t('Successfully blocked points given to a non-existent tid'));
$points = rand(1, 500);
$description = $this
->randomName();
$operation = $this
->randomName();
$params = array(
'points' => $points,
'description' => $description,
'operation' => $operation,
);
$ret = userpoints_userpointsapi($params);
$sql = "SELECT description, operation, reference FROM {userpoints_txn} WHERE description = '%s' AND operation = '%s'";
$db_point_rec = db_fetch_array(db_query($sql, $description, $operation));
$this
->assertTrue($db_point_rec['description'] == $description, t('Point description successfully verified in DB'));
$this
->assertTrue($db_point_rec['operation'] == $operation, t('Point event successfully verified in DB'));
}