You are here

public function UserpointsRulesTestCase::testActions in User Points 7.2

Test the rules actions exposed by this module.

File

userpoints_rules/userpoints_rules.test, line 30
Tests for Userpoints Services integration.

Class

UserpointsRulesTestCase
@file Tests for Userpoints Services integration.

Code

public function testActions() {
  $user = $this
    ->drupalCreateUser(array(
    'view userpoints',
    'view userpoints transactions',
  ));
  $this
    ->createActionRules();
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('myuserpoints');
  $this
    ->clickLink(t('view'));

  // Get the transaction id and load the transaction.
  preg_match('|myuserpoints\\/transaction\\/([0-9]+)\\/view|', $this
    ->getURL(), $matches);
  $txn_id = $matches[1];
  $transaction = userpoints_transaction_load($txn_id);

  // Assert a few properties.
  $this
    ->assertEqual(10, $transaction
    ->getPoints());
  $this
    ->assertTrue($transaction
    ->isApproved());
  $this
    ->assertTrue($transaction
    ->getExpiryDate() > REQUEST_TIME);
  $this
    ->assertEqual('userpoints_rules_login_test', $transaction
    ->getOperation());

  // Verify that the reason can be clicked and points to the user profile.
  $this
    ->clickLink(t('Granted points for logging in.'));
  $this
    ->assertEqual(url('user/' . $user->uid, array(
    'absolute' => TRUE,
  )), $this
    ->getUrl());
  $this
    ->drupalLogout();
}