ApplePayTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Test\Integration;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test;
  5. use Test\Setup;
  6. use Braintree;
  7. class ApplePayTest extends Setup
  8. {
  9. private static $gateway;
  10. public static function setUpBeforeClass()
  11. {
  12. self::$gateway = self::_buildMerchantGateway();
  13. }
  14. public static function tearDownAfterClass()
  15. {
  16. self::$gateway = null;
  17. }
  18. private static function _buildMerchantGateway()
  19. {
  20. $gateway = new Braintree\Gateway([
  21. 'clientId' => 'client_id$development$integration_client_id',
  22. 'clientSecret' => 'client_secret$development$integration_client_secret',
  23. ]);
  24. $result = $gateway->merchant()->create([
  25. 'email' => 'name@email.com',
  26. 'countryCodeAlpha3' => 'USA',
  27. 'paymentMethods' => ['credit_card', 'paypal'],
  28. ]);
  29. return new Braintree\Gateway([
  30. 'accessToken' => $result->credentials->accessToken,
  31. ]);
  32. }
  33. public function testRegisterDomainWithExpectedStubbedResult()
  34. {
  35. $result = self::$gateway->applePay()->registerDomain('domain');
  36. $this->assertEquals(true, $result->success);
  37. }
  38. public function testValidationErrorWhenRegisteringNoDomain()
  39. {
  40. $result = self::$gateway->applePay()->registerDomain('');
  41. $this->assertEquals(false, $result->success);
  42. $this->assertEquals(1, preg_match('/Domain name is required\./', $result->message));
  43. }
  44. public function testUnregisterDomainWithExpectedStubbedResult()
  45. {
  46. $domain = 'example.com';
  47. $result = self::$gateway->applePay()->unregisterDomain($domain);
  48. $this->assertEquals(true, $result->success);
  49. }
  50. public function testUnregisterDomainWithSpecialCharactersWithExpectedStubbedResult()
  51. {
  52. $domain = 'ex&mple.com';
  53. $result = self::$gateway->applePay()->unregisterDomain($domain);
  54. $this->assertEquals(true, $result->success);
  55. }
  56. public function testUnregisterDomainWithSchemeWithExpectedStubbedResult()
  57. {
  58. $domain = 'http://example.com';
  59. $result = self::$gateway->applePay()->unregisterDomain($domain);
  60. $this->assertEquals(true, $result->success);
  61. }
  62. public function testRegisteredDomainsWithExpectedStubbedResult()
  63. {
  64. $result = self::$gateway->applePay()->registeredDomains();
  65. $this->assertEquals(true, $result->success);
  66. $registeredDomains = $result->applePayOptions->domains;
  67. $this->assertEmpty(array_diff(['www.example.com'], $registeredDomains));
  68. }
  69. }