You are here

function Braintree_TransactionAdvancedSearchTest::test_rangeNode_gatewayRejectedAt in Commerce Braintree 7

File

braintree_php/tests/integration/TransactionAdvancedSearchTest.php, line 953

Class

Braintree_TransactionAdvancedSearchTest

Code

function test_rangeNode_gatewayRejectedAt() {
  $old_merchant_id = Braintree_Configuration::merchantId();
  $old_public_key = Braintree_Configuration::publicKey();
  $old_private_key = Braintree_Configuration::privateKey();
  Braintree_Configuration::merchantId('processing_rules_merchant_id');
  Braintree_Configuration::publicKey('processing_rules_public_key');
  Braintree_Configuration::privateKey('processing_rules_private_key');
  $transaction = Braintree_Transaction::sale(array(
    'amount' => '1000.00',
    'creditCard' => array(
      'number' => '4111111111111111',
      'expirationDate' => '05/12',
      'cvv' => '200',
    ),
  ))->transaction;
  $twenty_min_ago = date_create("now -20 minutes", new DateTimeZone("UTC"));
  $ten_min_ago = date_create("now -10 minutes", new DateTimeZone("UTC"));
  $ten_min_from_now = date_create("now +10 minutes", new DateTimeZone("UTC"));
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::id()
      ->is($transaction->id),
    Braintree_TransactionSearch::gatewayRejectedAt()
      ->between($twenty_min_ago, $ten_min_ago),
  ));
  $firstCount = $collection
    ->maximumCount();
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::id()
      ->is($transaction->id),
    Braintree_TransactionSearch::gatewayRejectedAt()
      ->between($ten_min_ago, $ten_min_from_now),
  ));
  $secondCount = $collection
    ->maximumCount();
  $firstId = $collection
    ->firstItem()->id;
  Braintree_Configuration::merchantId($old_merchant_id);
  Braintree_Configuration::publicKey($old_public_key);
  Braintree_Configuration::privateKey($old_private_key);
  $this
    ->assertEquals(0, $firstCount);
  $this
    ->assertEquals(1, $secondCount);
  $this
    ->assertEquals($transaction->id, $firstId);
}