You are here

function Braintree_UtilTest::testVerifyKeys in Commerce Braintree 7

File

braintree_php/tests/unit/UtilTest.php, line 150

Class

Braintree_UtilTest

Code

function testVerifyKeys() {
  $signature = array(
    'amount',
    'customerId',
    'orderId',
    'paymentMethodToken',
    'type',
    array(
      'creditCard' => array(
        'token',
        'cvv',
        'expirationDate',
        'number',
      ),
    ),
    array(
      'customer' => array(
        'id',
        'company',
        'email',
        'fax',
        'firstName',
        'lastName',
        'phone',
        'website',
      ),
    ),
    array(
      'billing' => array(
        'firstName',
        'lastName',
        'company',
        'countryName',
        'extendedAddress',
        'locality',
        'postalCode',
        'region',
        'streetAddress',
      ),
    ),
    array(
      'shipping' => array(
        'firstName',
        'lastName',
        'company',
        'countryName',
        'extendedAddress',
        'locality',
        'postalCode',
        'region',
        'streetAddress',
      ),
    ),
    array(
      'options' => array(
        'storeInVault',
        'submitForSettlement',
        'addBillingAddressToPaymentMethod',
      ),
    ),
    array(
      'customFields' => array(
        '_anyKey_',
      ),
    ),
  );

  // test valid
  $userKeys = array(
    'amount' => '100.00',
    'customFields' => array(
      'HEY' => 'HO',
      'WAY' => 'NO',
    ),
    'creditCard' => array(
      'number' => '5105105105105100',
      'expirationDate' => '05/12',
    ),
  );
  $n = Braintree_Util::verifyKeys($signature, $userKeys);
  $this
    ->assertNull($n);
  $userKeys = array(
    'amount' => '100.00',
    'customFields' => array(
      'HEY' => 'HO',
      'WAY' => 'NO',
    ),
    'bogus' => 'FAKE',
    'totallyFake' => 'boom',
    'creditCard' => array(
      'number' => '5105105105105100',
      'expirationDate' => '05/12',
    ),
  );

  // test invalid
  $this
    ->setExpectedException('InvalidArgumentException');
  Braintree_Util::verifyKeys($signature, $userKeys);
}