You are here

function UserpointsAPITestCase::testUserpermissions in User Points 7.2

Same name and namespace in other branches
  1. 7 tests/userpoints_api.test \UserpointsAPITestCase::testUserpermissions()

Test user permissions

File

./userpoints.test, line 335
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.
  $this
    ->addPoints($points, $this->admin_user);

  // 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."));
}