You are here

function Braintree_TransactionAdvancedSearchTest::testSearchOnTextFields in Commerce Braintree 7

File

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

Class

Braintree_TransactionAdvancedSearchTest

Code

function testSearchOnTextFields() {
  $firstName = 'Tim' . rand();
  $token = 'creditcard' . rand();
  $customerId = 'customer' . rand();
  $transaction = Braintree_Transaction::saleNoValidate(array(
    'amount' => Braintree_Test_TransactionAmounts::$authorize,
    'creditCard' => array(
      'number' => Braintree_Test_CreditCardNumbers::$visa,
      'expirationDate' => '05/2012',
      'cardholderName' => 'Tom Smith',
      'token' => $token,
    ),
    'billing' => array(
      'company' => 'Braintree',
      'countryName' => 'United States of America',
      'extendedAddress' => 'Suite 123',
      'firstName' => $firstName,
      'lastName' => 'Smith',
      'locality' => 'Chicago',
      'postalCode' => '12345',
      'region' => 'IL',
      'streetAddress' => '123 Main St',
    ),
    'customer' => array(
      'company' => 'Braintree',
      'email' => 'smith@example.com',
      'fax' => '5551231234',
      'firstName' => 'Tom',
      'id' => $customerId,
      'lastName' => 'Smith',
      'phone' => '5551231234',
      'website' => 'http://example.com',
    ),
    'options' => array(
      'storeInVault' => true,
    ),
    'orderId' => 'myorder',
    'shipping' => array(
      'company' => 'Braintree P.S.',
      'countryName' => 'Mexico',
      'extendedAddress' => 'Apt 456',
      'firstName' => 'Thomas',
      'lastName' => 'Smithy',
      'locality' => 'Braintree',
      'postalCode' => '54321',
      'region' => 'MA',
      'streetAddress' => '456 Road',
    ),
  ));
  $search_criteria = array(
    'billingCompany' => "Braintree",
    'billingCountryName' => "United States of America",
    'billingExtendedAddress' => "Suite 123",
    'billingFirstName' => $firstName,
    'billingLastName' => "Smith",
    'billingLocality' => "Chicago",
    'billingPostalCode' => "12345",
    'billingRegion' => "IL",
    'billingStreetAddress' => "123 Main St",
    'creditCardCardholderName' => "Tom Smith",
    'creditCardExpirationDate' => "05/2012",
    'creditCardNumber' => Braintree_Test_CreditCardNumbers::$visa,
    'customerCompany' => "Braintree",
    'customerEmail' => "smith@example.com",
    'customerFax' => "5551231234",
    'customerFirstName' => "Tom",
    'customerId' => $customerId,
    'customerLastName' => "Smith",
    'customerPhone' => "5551231234",
    'customerWebsite' => "http://example.com",
    'orderId' => "myorder",
    'paymentMethodToken' => $token,
    'processorAuthorizationCode' => $transaction->processorAuthorizationCode,
    'shippingCompany' => "Braintree P.S.",
    'shippingCountryName' => "Mexico",
    'shippingExtendedAddress' => "Apt 456",
    'shippingFirstName' => "Thomas",
    'shippingLastName' => "Smithy",
    'shippingLocality' => "Braintree",
    'shippingPostalCode' => "54321",
    'shippingRegion' => "MA",
    'shippingStreetAddress' => "456 Road",
  );
  $query = array(
    Braintree_TransactionSearch::id()
      ->is($transaction->id),
  );
  foreach ($search_criteria as $criterion => $value) {
    $query[] = Braintree_TransactionSearch::$criterion()
      ->is($value);
  }
  $collection = Braintree_Transaction::search($query);
  $this
    ->assertEquals(1, $collection
    ->maximumCount());
  $this
    ->assertEquals($transaction->id, $collection
    ->firstItem()->id);
  foreach ($search_criteria as $criterion => $value) {
    $collection = Braintree_Transaction::search(array(
      Braintree_TransactionSearch::$criterion()
        ->is($value),
      Braintree_TransactionSearch::id()
        ->is($transaction->id),
    ));
    $this
      ->assertEquals(1, $collection
      ->maximumCount());
    $this
      ->assertEquals($transaction->id, $collection
      ->firstItem()->id);
    $collection = Braintree_Transaction::search(array(
      Braintree_TransactionSearch::$criterion()
        ->is('invalid_attribute'),
      Braintree_TransactionSearch::id()
        ->is($transaction->id),
    ));
    $this
      ->assertEquals(0, $collection
      ->maximumCount());
  }
}