OAuthTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Test\Unit;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test\Setup;
  5. use Braintree;
  6. class OAuthTest extends Setup
  7. {
  8. protected $gateway;
  9. public function setUp()
  10. {
  11. $this->gateway = new Braintree\Gateway([
  12. 'clientId' => 'client_id$development$integration_client_id',
  13. 'clientSecret' => 'client_secret$development$integration_client_secret'
  14. ]);
  15. }
  16. public function testMapInvalidGrantCodeToOldError()
  17. {
  18. $result = $this->_buildResult([
  19. 'code' => '93801',
  20. 'message' => 'Invalid grant: code not found'
  21. ]);
  22. $this->gateway->oauth()->_mapError($result);
  23. $this->assertEquals($result->error, 'invalid_grant');
  24. $this->assertEquals($result->errorDescription, 'code not found');
  25. }
  26. public function testMapInvalidCredentialsCodeToOldError()
  27. {
  28. $result = $this->_buildResult([
  29. 'code' => '93802',
  30. 'message' => 'Invalid credentials: wrong client id or secret'
  31. ]);
  32. $this->gateway->oauth()->_mapError($result);
  33. $this->assertEquals($result->error, 'invalid_credentials');
  34. $this->assertEquals($result->errorDescription, 'wrong client id or secret');
  35. }
  36. public function testMapInvalidScopeCodeToOldError()
  37. {
  38. $result = $this->_buildResult([
  39. 'code' => '93803',
  40. 'message' => 'Invalid scope: scope is invalid'
  41. ]);
  42. $this->gateway->oauth()->_mapError($result);
  43. $this->assertEquals($result->error, 'invalid_scope');
  44. $this->assertEquals($result->errorDescription, 'scope is invalid');
  45. }
  46. protected function _buildResult($error)
  47. {
  48. return new Braintree\Result\Error([
  49. 'errors' => [
  50. 'errors' => [],
  51. 'credentials' => [
  52. 'errors' => [$error]
  53. ]
  54. ]
  55. ]);
  56. }
  57. }