You are here

function UserpointsAPITestCase::testUserpermissions in User Points 7

Same name and namespace in other branches
  1. 7.2 userpoints.test \UserpointsAPITestCase::testUserpermissions()

Test user permissions

File

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

Class

UserpointsAPITestCase
API Tests.

Code

function testUserpermissions() {
  $this->non_admin_username = 'test';
  $points = 10;

  // check permission with admin user.
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer userpoints',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // check access page.
  $this
    ->drupalGet('admin/config/people/userpoints');
  $content = $this
    ->drupalGetContent();
  $content = strstr($content, 'Access denied');
  $this
    ->assertTrue($content == FALSE, t("Successful navigated to the page modify points"));

  // check modify points.
  $edit = array(
    'txn_user' => $this->admin_user->name,
    'points' => $points,
  );
  $this
    ->drupalPost('admin/config/people/userpoints/add', $edit, 'Save');

  // Check database.
  $this
    ->assertEqual($this
    ->getTxnPoints($this->admin_user->uid, $points), $points, t("Successful verified that points were added into database."));

  // logout and change user.
  $this
    ->drupalLogout();

  // check permission with view user.
  $view_user = $this
    ->drupalCreateUser(array(
    'view userpoints',
  ));
  $this
    ->drupalLogin($view_user);

  // check access page.
  $this
    ->drupalGet('admin/config/people/userpoints');
  $this
    ->assertResponse(403, t("Successful verified that a user without admin userpoints permissions can not access the admin interface."));
}