| 1 |
<?php |
| 2 |
namespace Payplug; |
| 3 |
use Payplug; |
| 4 |
use Payplug\Core\HttpClient; |
| 5 |
|
| 6 |
/** |
| 7 |
* @group unit |
| 8 |
* @group ci |
| 9 |
* @group recommended |
| 10 |
*/ |
| 11 |
class AuthenticationTest extends \PHPUnit_Framework_TestCase |
| 12 |
{ |
| 13 |
private $_requestMock; |
| 14 |
|
| 15 |
protected function setUp() |
| 16 |
{ |
| 17 |
$this->_configuration = new \Payplug\Payplug('abc'); |
| 18 |
Payplug\Payplug::setDefaultConfiguration($this->_configuration); |
| 19 |
|
| 20 |
$this->_requestMock = $this->getMock('\Payplug\Core\IHttpRequest'); |
| 21 |
Core\HttpClient::$REQUEST_HANDLER = $this->_requestMock; |
| 22 |
} |
| 23 |
|
| 24 |
protected function setUpTwice() |
| 25 |
{ |
| 26 |
$this->_configuration = new \Payplug\Payplug('abc','1970-01-01'); |
| 27 |
Payplug\Payplug::setDefaultConfiguration($this->_configuration); |
| 28 |
|
| 29 |
$this->_requestMock = $this->getMock('\Payplug\Core\IHttpRequest'); |
| 30 |
Core\HttpClient::$REQUEST_HANDLER = $this->_requestMock; |
| 31 |
} |
| 32 |
|
| 33 |
public function testGetKeysByLogin() |
| 34 |
{ |
| 35 |
$email = '[email protected]'; |
| 36 |
$password = 'passwordIsOverrated'; |
| 37 |
$response = array( |
| 38 |
'secret_keys' => array( |
| 39 |
'test' => 'sk_test_everythingIsUnderControl', |
| 40 |
'live' => 'sk_live_allYourBasesAreBelongToUs', |
| 41 |
), |
| 42 |
); |
| 43 |
$this->_requestMock |
| 44 |
->expects($this->once()) |
| 45 |
->method('exec') |
| 46 |
->will($this->returnValue(json_encode($response))); |
| 47 |
|
| 48 |
$this->_requestMock |
| 49 |
->expects($this->any()) |
| 50 |
->method('getinfo') |
| 51 |
->will($this->returnCallback(function($option) { |
| 52 |
switch($option) { |
| 53 |
case CURLINFO_HTTP_CODE: |
| 54 |
return 201; |
| 55 |
} |
| 56 |
return null; |
| 57 |
})); |
| 58 |
|
| 59 |
$authentication = Authentication::getKeysByLogin($email, $password); |
| 60 |
|
| 61 |
$this->assertEquals(201, $authentication['httpStatus']); |
| 62 |
$this->assertEquals('sk_test_everythingIsUnderControl', $authentication['httpResponse']['secret_keys']['test']); |
| 63 |
$this->assertEquals('sk_live_allYourBasesAreBelongToUs', $authentication['httpResponse']['secret_keys']['live']); |
| 64 |
} |
| 65 |
|
| 66 |
public function testGetAccount() |
| 67 |
{ |
| 68 |
$response = array( |
| 69 |
'is_live' => true, |
| 70 |
'object' => 'account', |
| 71 |
'id' => '12345', |
| 72 |
'configuration' => array( |
| 73 |
'currencies' => array(), |
| 74 |
'min_amounts' => array(), |
| 75 |
'max_amounts' => array(), |
| 76 |
), |
| 77 |
'permissions' => array( |
| 78 |
'use_live_mode' => true, |
| 79 |
'can_save_cards' => false, |
| 80 |
), |
| 81 |
); |
| 82 |
$this->_requestMock |
| 83 |
->expects($this->once()) |
| 84 |
->method('exec') |
| 85 |
->will($this->returnValue(json_encode($response))); |
| 86 |
|
| 87 |
$this->_requestMock |
| 88 |
->expects($this->any()) |
| 89 |
->method('getinfo') |
| 90 |
->will($this->returnCallback(function($option) { |
| 91 |
switch($option) { |
| 92 |
case CURLINFO_HTTP_CODE: |
| 93 |
return 200; |
| 94 |
} |
| 95 |
return null; |
| 96 |
})); |
| 97 |
|
| 98 |
$account = Authentication::getAccount($this->_configuration); |
| 99 |
|
| 100 |
$this->assertEquals(200, $account['httpStatus']); |
| 101 |
$this->assertEquals(true, $account['httpResponse']['is_live']); |
| 102 |
$this->assertEquals('account', $account['httpResponse']['object']); |
| 103 |
$this->assertEquals('12345', $account['httpResponse']['id']); |
| 104 |
} |
| 105 |
|
| 106 |
public function testGetPermissions() |
| 107 |
{ |
| 108 |
$response = array( |
| 109 |
'is_live' => true, |
| 110 |
'object' => 'account', |
| 111 |
'id' => '12345', |
| 112 |
'configuration' => array( |
| 113 |
'currencies' => array(), |
| 114 |
'min_amounts' => array(), |
| 115 |
'max_amounts' => array(), |
| 116 |
), |
| 117 |
'permissions' => array( |
| 118 |
'can_use_oney' => true, |
| 119 |
'use_live_mode' => false, |
| 120 |
'can_create_deferred_payment' => true, |
| 121 |
'can_create_installment_plan' => false, |
| 122 |
'can_save_cards' => false, |
| 123 |
), |
| 124 |
); |
| 125 |
$this->_requestMock |
| 126 |
->expects($this->once()) |
| 127 |
->method('exec') |
| 128 |
->will($this->returnValue(json_encode($response))); |
| 129 |
|
| 130 |
$this->_requestMock |
| 131 |
->expects($this->any()) |
| 132 |
->method('getinfo') |
| 133 |
->will($this->returnCallback(function($option) { |
| 134 |
switch($option) { |
| 135 |
case CURLINFO_HTTP_CODE: |
| 136 |
return 200; |
| 137 |
} |
| 138 |
return null; |
| 139 |
})); |
| 140 |
|
| 141 |
$permissions = Authentication::getPermissions($this->_configuration); |
| 142 |
|
| 143 |
$this->assertEquals(true, $permissions['can_use_oney']); |
| 144 |
$this->assertEquals(false, $permissions['use_live_mode']); |
| 145 |
$this->assertEquals(true, $permissions['can_create_deferred_payment']); |
| 146 |
$this->assertEquals(false, $permissions['can_create_installment_plan']); |
| 147 |
$this->assertEquals(false, $permissions['can_save_cards']); |
| 148 |
} |
| 149 |
} |
| 150 |
|