You are here

function Braintree_TransactionAdvancedSearchTest::test_rangeNode_createdAt_lessThanOrEqualTo in Commerce Braintree 7

File

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

Class

Braintree_TransactionAdvancedSearchTest

Code

function test_rangeNode_createdAt_lessThanOrEqualTo() {
  $transaction = Braintree_Transaction::saleNoValidate(array(
    'amount' => '1000.00',
    'creditCard' => array(
      'cardholderName' => 'Ted Everywoman' . rand(),
      'number' => '5105105105105100',
      'expirationDate' => '05/12',
    ),
  ));
  $past = clone $transaction->createdAt;
  $past
    ->modify("-1 hour");
  $now = $transaction->createdAt;
  $future = clone $transaction->createdAt;
  $future
    ->modify("+1 hour");
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::creditCardCardholderName()
      ->is($transaction->creditCardDetails->cardholderName),
    Braintree_TransactionSearch::createdAt()
      ->lessThanOrEqualTo($future),
  ));
  $this
    ->assertEquals(1, $collection
    ->maximumCount());
  $this
    ->assertEquals($transaction->id, $collection
    ->firstItem()->id);
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::creditCardCardholderName()
      ->is($transaction->creditCardDetails->cardholderName),
    Braintree_TransactionSearch::createdAt()
      ->lessThanOrEqualTo($now),
  ));
  $this
    ->assertEquals(1, $collection
    ->maximumCount());
  $this
    ->assertEquals($transaction->id, $collection
    ->firstItem()->id);
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::creditCardCardholderName()
      ->is($transaction->creditCardDetails->cardholderName),
    Braintree_TransactionSearch::createdAt()
      ->lessThanOrEqualTo($past),
  ));
  $this
    ->assertEquals(0, $collection
    ->maximumCount());
}