You are here

function UserpointsAdminTestCase::testAddEditPoints in User Points 7

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

File

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

Class

UserpointsAdminTestCase
Administration UI tests

Code

function testAddEditPoints() {
  $user = $this
    ->drupalCreateUser();
  $categories = userpoints_get_categories();
  $tid = userpoints_get_default_tid();
  $category = $categories[$tid];

  // Grant some points with admin user.
  $txn_id = $this
    ->addPoints(10, $user, 10);

  // Go to the listing page, verify that the user is shown.
  $row = $this
    ->xpath('//table/tbody/tr');

  //$this->assertEqual(strip_tags((string)$row[0]->td[0]), t('@name (details)', array('@name' => $user->name)), t('User name with details link displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[1], 10, t('Points correctly displayed.'));

  // Go to the transaction listing page, verify that the transaction is shown.
  $this
    ->clickLink(t('Transactions'));
  $row = $this
    ->xpath('//table/tbody/tr');
  $transaction = userpoints_transaction_load($txn_id);

  //$this->assertEqual(strip_tags((string)$row[0]->td[0]), $user->name, t('User correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[1], 10, t('Points correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[2], format_date($transaction->time_stamp, 'small'), t('Date correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[3], 'admin', t('Reason correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[4], t('Approved'), t('Status correctly displayed.'));
  $this
    ->clickLink(t('edit'));

  // Verify default values.
  $this
    ->assertFieldByName('points', 10);
  $value = $this
    ->xpath("//input[@name=:name and @disabled=:disabled]/@value", array(
    ':name' => 'txn_user',
    ':disabled' => 'disabled',
  ));
  $this
    ->assertEqual($value[0]['value'], $user->name, t('User field has the correct value and is disabled.'));
  $this
    ->assertFieldByName('approver', $this->admin_user->name);
  $edit = array(
    'points' => 7,
    'operation' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    'reference' => $this
      ->randomName(),
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Verify that the transaction has been updated.
  $this
    ->assertEqual(7, userpoints_get_current_points($user->uid));
  $row = $this
    ->xpath('//table/tbody/tr');
  $transaction = userpoints_transaction_load($transaction->txn_id);

  //$this->assertEqual(strip_tags((string)$row[0]->td[0]), $user->name, t('User correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[1], 7, t('Points correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[2], format_date($transaction->time_stamp, 'small'), t('Date correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[3], $edit['description'], t('Reason correctly displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[4], t('Approved'), t('Status correctly displayed.'));

  // Go to the listing page, verify that the total points have been updated.
  $this
    ->clickLink(t('Totals'));
  $row = $this
    ->xpath('//table/tbody/tr');

  //$this->assertEqual(strip_tags((string)$row[0]->td[0]), t('@name (details)', array('@name' => $user->name)), t('User name with details link displayed.'));
  $this
    ->assertEqual((string) $row[0]->td[1], 7, t('Points correctly displayed.'));

  // View transaction details.
  $this
    ->clickLink(t('Transactions'));
  $this
    ->clickLink('view');
}