public function UserpointsServiceTestCase::testAddRetrievePoints in User Points 7
Same name and namespace in other branches
- 7.2 userpoints_service/userpoints_service.test \UserpointsServiceTestCase::testAddRetrievePoints()
Basic tests for granting and retreiving points through a service.
File
- ./
userpoints_service.test, line 71 - Tests for Userpoints Services integration.
Class
Code
public function testAddRetrievePoints() {
// Create and log in our privileged user.
$this->privilegedUser = $this
->drupalCreateUser(array(
'view userpoints',
'administer userpoints',
));
$this
->drupalLogin($this->privilegedUser);
$normal_user = $this
->drupalCreateUser(array());
$total = 0;
for ($i = 0; $i < 3; $i++) {
$points = rand(-50, 50);
$params = array(
'uid' => $normal_user->uid,
'points' => $points,
);
$this
->servicesPost($this->endpoint->path . '/userpoints/add', $params);
$total += $points;
}
$result = $this
->servicesGet($this->endpoint->path . '/userpoints/' . $normal_user->uid);
$this
->assertEqual($total, $result['body']);
// Give the admin user some points too.
$points = rand(-50, 50);
$params = array(
'uid' => $this->privilegedUser->uid,
'points' => $points,
);
$this
->servicesPost($this->endpoint->path . '/userpoints/add', $params);
$result = $this
->servicesGet($this->endpoint->path . '/userpoints');
$index = $result['body'];
$this
->assertEqual($index[0]->points, userpoints_get_current_points($index[0]->uid));
$this
->assertEqual($index[1]->points, userpoints_get_current_points($index[1]->uid));
$this
->assertEqual($index[0]->max_points, userpoints_get_max_points($index[0]->uid));
$this
->assertEqual($index[1]->max_points, userpoints_get_max_points($index[1]->uid));
}