|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace InvoiceNinjaModuleTest\Options; |
|
5
|
|
|
|
|
6
|
|
|
use InvoiceNinjaModule\Module; |
|
7
|
|
|
use InvoiceNinjaModule\Options\AuthOptions; |
|
8
|
|
|
use InvoiceNinjaModule\Options\Interfaces\AuthOptionsInterface; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Zend\Http\Client; |
|
11
|
|
|
|
|
12
|
|
|
class AuthOptionsTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testCreateEmptySettings() :void |
|
15
|
|
|
{ |
|
16
|
|
|
$auth = new AuthOptions([]); |
|
17
|
|
|
self::assertInstanceOf(AuthOptionsInterface::class, $auth); |
|
18
|
|
|
self::assertFalse($auth->isAuthorization()); |
|
19
|
|
|
self::assertEquals('none', $auth->getAuthType()); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidParameterException |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testCreateMoreThanOneConfig() :void |
|
26
|
|
|
{ |
|
27
|
|
|
$authSettings = [ |
|
28
|
|
|
Client::AUTH_BASIC => [], |
|
29
|
|
|
Client::AUTH_DIGEST => [] |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
new AuthOptions($authSettings); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidParameterException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testCreateNoAuthConfig() :void |
|
39
|
|
|
{ |
|
40
|
|
|
$authSettings = [ |
|
41
|
|
|
'test' => [] |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
new AuthOptions($authSettings); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidParameterException |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testCreateNoUser() :void |
|
51
|
|
|
{ |
|
52
|
|
|
$authSettings = [ |
|
53
|
|
|
Client::AUTH_BASIC => [ |
|
54
|
|
|
Module::AUTH_PASS => 'password' |
|
55
|
|
|
], |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
new AuthOptions($authSettings); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidParameterException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testCreateEmptyUser() :void |
|
65
|
|
|
{ |
|
66
|
|
|
$authSettings = [ |
|
67
|
|
|
Client::AUTH_BASIC => [ |
|
68
|
|
|
Module::AUTH_USER => '', |
|
69
|
|
|
Module::AUTH_PASS => 'password' |
|
70
|
|
|
], |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
new AuthOptions($authSettings); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidParameterException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testCreateNoPassword() :void |
|
80
|
|
|
{ |
|
81
|
|
|
$authSettings = [ |
|
82
|
|
|
Client::AUTH_BASIC => [ |
|
83
|
|
|
Module::AUTH_USER => 'username' |
|
84
|
|
|
], |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
new AuthOptions($authSettings); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidParameterException |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testCreateEmptyPassword() :void |
|
94
|
|
|
{ |
|
95
|
|
|
$authSettings = [ |
|
96
|
|
|
Client::AUTH_BASIC => [ |
|
97
|
|
|
Module::AUTH_USER => 'username', |
|
98
|
|
|
Module::AUTH_PASS => '' |
|
99
|
|
|
], |
|
100
|
|
|
]; |
|
101
|
|
|
|
|
102
|
|
|
new AuthOptions($authSettings); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testCreateBasic() :void |
|
106
|
|
|
{ |
|
107
|
|
|
$authSettings = [ |
|
108
|
|
|
Client::AUTH_BASIC => [ |
|
109
|
|
|
Module::AUTH_USER => 'username', |
|
110
|
|
|
Module::AUTH_PASS => 'password' |
|
111
|
|
|
], |
|
112
|
|
|
]; |
|
113
|
|
|
|
|
114
|
|
|
$auth = new AuthOptions($authSettings); |
|
115
|
|
|
self::assertInstanceOf(AuthOptionsInterface::class, $auth); |
|
116
|
|
|
|
|
117
|
|
|
self::assertTrue($auth->isAuthorization()); |
|
118
|
|
|
self::assertEquals(Client::AUTH_BASIC, $auth->getAuthType()); |
|
119
|
|
|
self::assertEquals('username', $auth->getUsername()); |
|
120
|
|
|
self::assertEquals('password', $auth->getPassword()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function testCreateDigest() :void |
|
124
|
|
|
{ |
|
125
|
|
|
$authSettings = [ |
|
126
|
|
|
Client::AUTH_DIGEST => [ |
|
127
|
|
|
Module::AUTH_USER => 'username', |
|
128
|
|
|
Module::AUTH_PASS => 'password' |
|
129
|
|
|
], |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
$auth = new AuthOptions($authSettings); |
|
133
|
|
|
self::assertInstanceOf(AuthOptionsInterface::class, $auth); |
|
134
|
|
|
|
|
135
|
|
|
self::assertTrue($auth->isAuthorization()); |
|
136
|
|
|
self::assertEquals(Client::AUTH_DIGEST, $auth->getAuthType()); |
|
137
|
|
|
self::assertEquals('username', $auth->getUsername()); |
|
138
|
|
|
self::assertEquals('password', $auth->getPassword()); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|