You are here

class Braintree_WebhookNotificationTest in Commerce Braintree 7

Hierarchy

Expanded class hierarchy of Braintree_WebhookNotificationTest

File

braintree_php/tests/unit/WebhookNotificationTest.php, line 4

View source
class Braintree_WebhookNotificationTest extends PHPUnit_Framework_TestCase {
  function testVerify() {
    $verificationString = Braintree_WebhookNotification::verify('verification_token');
    $this
      ->assertEquals('integration_public_key|c9f15b74b0d98635cd182c51e2703cffa83388c3', $verificationString);
  }
  function testSampleNotificationReturnsAParsableNotification() {
    $sampleNotification = Braintree_WebhookTesting::sampleNotification(Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE, 'my_id');
    $webhookNotification = Braintree_WebhookNotification::parse($sampleNotification['signature'], $sampleNotification['payload']);
    $this
      ->assertEquals(Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE, $webhookNotification->kind);
    $this
      ->assertNotNull($webhookNotification->timestamp);
    $this
      ->assertEquals("my_id", $webhookNotification->subscription->id);
  }
  function testParsingModifiedSignatureRaisesError() {
    $sampleNotification = Braintree_WebhookTesting::sampleNotification(Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE, 'my_id');
    $this
      ->setExpectedException('Braintree_Exception_InvalidSignature');
    $webhookNotification = Braintree_WebhookNotification::parse($sampleNotification['signature'] . "bad", $sampleNotification['payload']);
  }
  function testParsingUnknownPublicKeyRaisesError() {
    $sampleNotification = Braintree_WebhookTesting::sampleNotification(Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE, 'my_id');
    $this
      ->setExpectedException('Braintree_Exception_InvalidSignature');
    $webhookNotification = Braintree_WebhookNotification::parse("bad" . $sampleNotification['signature'], $sampleNotification['payload']);
  }
  function testParsingInvalidSignatureRaisesError() {
    $sampleNotification = Braintree_WebhookTesting::sampleNotification(Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE, 'my_id');
    $this
      ->setExpectedException('Braintree_Exception_InvalidSignature');
    $webhookNotification = Braintree_WebhookNotification::parse("bad_signature", $sampleNotification['payload']);
  }

}

Members