You are here

public function UserpointsRulesTestCase::testEvents in User Points 7.2

Test the before and after events and the setter and getter callbacks.

File

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

Class

UserpointsRulesTestCase
@file Tests for Userpoints Services integration.

Code

public function testEvents() {
  $user = $this
    ->drupalCreateUser(array(
    'view userpoints',
  ));
  $this
    ->createEventRules();
  $transaction = userpoints_grant_points('userpoints_rules_trigger_before_rule', 10, 'userpoints', $user->uid);
  $transaction
    ->save();

  // Verify that the changes defined in the rules have been done.
  $this
    ->assertTrue($transaction
    ->isDeclined(), t('Transaction has been marked as declined.'));
  $this
    ->assertEqual('Transaction was declined through rules.', $transaction
    ->getDescription(), t('Transaction description has been set.'));

  // Verify that the changes have been persisted in the database.
  $transaction = userpoints_transaction_load($transaction
    ->getTxnId());
  $this
    ->assertTrue($transaction
    ->isDeclined(), t('Transaction has been marked as declined.'));
  $this
    ->assertEqual('Transaction was declined through rules.', $transaction
    ->getDescription(), t('Transaction description has been set.'));
  $transaction = userpoints_grant_points('userpoints_rules_trigger_after_rule', 15, 'userpoints', $user->uid)
    ->pending();
  $transaction
    ->save();

  // Verify that the changes defined in the rules have been done.
  $transaction = userpoints_transaction_load($transaction
    ->getTxnId());
  $this
    ->assertTrue($transaction
    ->isApproved(), t('Transaction has been marked as approved.'));
  $this
    ->assertEqual('Transaction was set to pending through rules.', $transaction
    ->getReference(), t('Transaction reference has been set.'));
}