You are here

function CommercePaymentRulesTest::testPaymentConditions in Commerce Core 7

Test conditions on payment.

File

modules/payment/tests/commerce_payment.rules.test, line 32
Unit tests for payment rules.

Class

CommercePaymentRulesTest
Test payment user interface.

Code

function testPaymentConditions() {

  // Create a $100 product.
  $product = $this
    ->createDummyProduct('', '', 100, 'USD');

  // Create an order with this product.
  $order = $this
    ->createDummyOrder(1, array(
    $product->product_id => 1,
  ));

  // Order balance.
  $condition = rules_condition('commerce_payment_order_balance_comparison');
  $tests = array(
    array(
      'operator' => '=',
      'value' => '100',
      'result' => TRUE,
    ),
    array(
      'operator' => '=',
      'value' => '99.99',
      'result' => FALSE,
    ),
    array(
      'operator' => '=',
      'value' => '100.01',
      'result' => FALSE,
    ),
    array(
      'operator' => '>=',
      'value' => '100',
      'result' => TRUE,
    ),
    array(
      'operator' => '>=',
      'value' => '100.01',
      'result' => FALSE,
    ),
    array(
      'operator' => '>',
      'value' => '100',
      'result' => FALSE,
    ),
    array(
      'operator' => '>',
      'value' => '99.99',
      'result' => TRUE,
    ),
    array(
      'operator' => '<=',
      'value' => '100',
      'result' => TRUE,
    ),
    array(
      'operator' => '<=',
      'value' => '99.99',
      'result' => FALSE,
    ),
    array(
      'operator' => '<',
      'value' => '100',
      'result' => FALSE,
    ),
    array(
      'operator' => '<',
      'value' => '100.01',
      'result' => TRUE,
    ),
  );
  foreach ($tests as $test) {
    $this
      ->assert($test['result'] == $condition
      ->executeByArgs(array(
      'commerce_order' => $order,
      'operator' => $test['operator'],
      'value' => $test['value'],
    )), t('Order balance is @operator $@value.', array(
      '@operator' => $test['operator'],
      '@value' => $test['value'],
    )));
  }
}