You are here

function UserpointsAPITestCase::testGetDefaultTid in User Points 7

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

Test the default term id.

File

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

Class

UserpointsAPITestCase
API Tests.

Code

function testGetDefaultTid() {
  $vid = userpoints_get_vid();
  $term_name = $this
    ->randomName(10);
  $desc = $this
    ->randomName(10);

  // create a new term.
  $term = (object) array(
    'name' => $term_name,
    'description' => $desc,
    'vid' => $vid,
  );
  taxonomy_term_save($term);

  // login as admin userpoints
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer userpoints',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // save settings.
  $edit = array(
    'userpoints_category_default_tid' => $term->tid,
  );
  $this
    ->drupalPost('admin/config/people/userpoints/settings', $edit, 'Save configuration');

  // Check database.
  $this
    ->assertEqual(variable_get('userpoints_category_default_tid', FALSE), $term->tid);

  // check API.
  $tid = userpoints_get_default_tid();
  $this
    ->assertEqual($tid, $term->tid);

  // Check database.
  $this
    ->assertTrue(variable_get('userpoints_category_default_vid', FALSE) != FALSE, t("Successfully verified the vocab ID in the database."));

  // Check API.
  $vid = userpoints_get_vid();
  $this
    ->assertTrue(is_numeric($vid), t("Successfully retrieved default vid %d.", array(
    '%d' => $vid,
  )));
}