function UserpointsGrantPointsTestCase::testGrantPoints in User Points 7.2
Test basic usage of the API to create and update transactions.
File
- ./
userpoints.test, line 598 - Contains test classes for userpoints module.
Class
- UserpointsGrantPointsTestCase
- API Tests.
Code
function testGrantPoints() {
// Most basic usage, with automated saving.
userpoints_grant_points('test', 10, 'userpoints', $this->non_admin_user->uid)
->save();
$this
->verifyPoints($this->non_admin_user->uid, 10, 10);
// Negative points, use of save().
userpoints_grant_points('test', -5, 'userpoints', $this->non_admin_user->uid)
->save();
$this
->verifyPoints($this->non_admin_user->uid, 5, 10);
// Verify that pending points are not added to the total.
$transaction = userpoints_grant_points('test', 7, 'userpoints', $this->non_admin_user->uid)
->pending();
$transaction
->save();
$this
->verifyPoints($this->non_admin_user->uid, 5, 10);
// Make sure that loaded transactions can be updated, and after marked as
// approved, the points are correct.
$transaction = userpoints_transaction_load($transaction
->getTxnId());
$transaction
->approve()
->save();
$this
->verifyPoints($this->non_admin_user->uid, 12, 12);
try {
// Approved transaction must not be changed.
$transaction
->setPoints(123)
->save();
$this
->fail(t('Changing a approved transaction was not denied.'));
} catch (UserpointsChangeException $e) {
$this
->pass(t('Changing a approved transaction was denied.'));
}
$transaction = userpoints_grant_points('test', 19, 'userpoints', $this->non_admin_user->uid)
->pending();
$transaction
->save();
$this
->verifyPoints($this->non_admin_user->uid, 12, 12);
// Transactions can be declined.
$transaction
->decline()
->save();
$this
->verifyPoints($this->non_admin_user->uid, 12, 12);
try {
// Declined transaction must not be changed.
$transaction
->setPoints(123)
->save();
$this
->fail(t('Changing a declined transaction was not denied.'));
} catch (UserpointsChangeException $e) {
$this
->pass(t('Changing a declined transaction was denied.'));
}
}