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