function UserpointsBaseTestCase::addPoints in User Points 7
Same name and namespace in other branches
- 7.2 userpoints.test \UserpointsBaseTestCase::addPoints()
Add points through the admin form.
Parameters
$points: Amount of points to add.
$user: User object for which to grant points for.
$total: Amount of points the user should have after the points have been added. If not NULL, the confirmation string is checked and so is userpoints_get_current_points().
Return value
The most recent transaction id, assuming that this belongs to this transaction.
1 call to UserpointsBaseTestCase::addPoints()
File
- tests/
userpoints_api.test, line 32 - Contains test classes for userpoints module.
Class
- UserpointsBaseTestCase
- Userpoints base test class with various helper functions.
Code
function addPoints($points, $user, $total = NULL) {
$edit = array(
'txn_user' => $user->name,
'points' => $points,
);
$this
->drupalPost('admin/config/people/userpoints/add', $edit, t('Save'));
if ($total !== NULL) {
$categories = userpoints_get_categories();
$tid = userpoints_get_default_tid();
$category = $categories[$tid];
$this
->assertText(t('@name just earned @points points and now has @total points in the @category category.', array(
'@name' => $user->name,
'@points' => $points,
'@total' => $total,
'@category' => $category,
)), t('Correct confirmation message displayed.'));
$this
->assertEqual($total, userpoints_get_current_points($user->uid, $tid), t('User has the correct total amount of points.'));
}
return db_query('SELECT MAX(txn_id) FROM {userpoints_txn} WHERE uid = :uid', array(
':uid' => $user->uid,
))
->fetchField();
}