6
6
7
7
namespace Magento \Webapi \Test \Unit \Model \Authorization ;
8
8
9
+ use Magento \Webapi \Model \Authorization \TokenUserContext ;
10
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
9
11
use Magento \Authorization \Model \UserContextInterface ;
12
+ use Magento \Integration \Model \Oauth \TokenFactory ;
13
+ use Magento \Integration \Model \Oauth \Token ;
14
+ use Magento \Integration \Api \IntegrationServiceInterface ;
15
+ use Magento \Framework \Webapi \Request ;
16
+ use Magento \Integration \Helper \Oauth \Data as OauthHelper ;
17
+ use Magento \Framework \Stdlib \DateTime \DateTime as Date ;
18
+ use Magento \Framework \Stdlib \DateTime ;
19
+ use Magento \Integration \Model \Integration ;
10
20
11
21
/**
12
- * Tests \Magento\Webapi\Model\Authorization\ TokenUserContext
22
+ * Tests TokenUserContext
13
23
*/
14
24
class TokenUserContextTest extends \PHPUnit \Framework \TestCase
15
25
{
16
26
/**
17
- * @var \Magento\Framework\TestFramework\Unit\Helper\ ObjectManager
27
+ * @var ObjectManager
18
28
*/
19
29
protected $ objectManager ;
20
30
21
31
/**
22
- * @var \Magento\Webapi\Model\Authorization\ TokenUserContext
32
+ * @var TokenUserContext
23
33
*/
24
34
protected $ tokenUserContext ;
25
35
26
36
/**
27
- * @var \Magento\Integration\Model\Oauth\ TokenFactory|\PHPUnit_Framework_MockObject_MockObject
37
+ * @var TokenFactory|\PHPUnit_Framework_MockObject_MockObject
28
38
*/
29
39
protected $ tokenFactory ;
30
40
31
41
/**
32
- * @var \Magento\Integration\Api\ IntegrationServiceInterface|\PHPUnit_Framework_MockObject_MockObject
42
+ * @var IntegrationServiceInterface|\PHPUnit_Framework_MockObject_MockObject
33
43
*/
34
44
protected $ integrationService ;
35
45
36
46
/**
37
- * @var \Magento\Framework\Webapi\ Request|\PHPUnit_Framework_MockObject_MockObject
47
+ * @var Request|\PHPUnit_Framework_MockObject_MockObject
38
48
*/
39
49
protected $ request ;
40
50
41
51
/**
42
- * @var \Magento\Integration\Helper\Oauth\Data |\PHPUnit_Framework_MockObject_MockObject
52
+ * @var OauthHelper |\PHPUnit_Framework_MockObject_MockObject
43
53
*/
44
54
private $ oauthHelperMock ;
45
55
46
56
/**
47
- * @var \Magento\Framework\Stdlib\DateTime\DateTime |\PHPUnit_Framework_MockObject_MockObject
57
+ * @var Date |\PHPUnit_Framework_MockObject_MockObject
48
58
*/
49
59
private $ dateMock ;
50
60
51
61
/**
52
- * @var \Magento\Framework\Stdlib\ DateTime|\PHPUnit_Framework_MockObject_MockObject
62
+ * @var DateTime|\PHPUnit_Framework_MockObject_MockObject
53
63
*/
54
64
private $ dateTimeMock ;
55
65
56
66
protected function setUp ()
57
67
{
58
- $ this ->objectManager = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
68
+ $ this ->objectManager = new ObjectManager ($ this );
59
69
60
- $ this ->request = $ this ->getMockBuilder (\ Magento \ Framework \ Webapi \ Request::class)
70
+ $ this ->request = $ this ->getMockBuilder (Request::class)
61
71
->disableOriginalConstructor ()
62
72
->setMethods (['getHeader ' ])
63
73
->getMock ();
64
74
65
- $ this ->tokenFactory = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Oauth \ TokenFactory::class)
75
+ $ this ->tokenFactory = $ this ->getMockBuilder (TokenFactory::class)
66
76
->disableOriginalConstructor ()
67
77
->setMethods (['create ' ])
68
78
->getMock ();
69
79
70
- $ this ->integrationService = $ this ->getMockBuilder (\ Magento \ Integration \ Api \ IntegrationServiceInterface::class)
80
+ $ this ->integrationService = $ this ->getMockBuilder (IntegrationServiceInterface::class)
71
81
->disableOriginalConstructor ()
72
82
->setMethods (
73
83
[
@@ -83,17 +93,17 @@ protected function setUp()
83
93
)
84
94
->getMock ();
85
95
86
- $ this ->oauthHelperMock = $ this ->getMockBuilder (\ Magento \ Integration \ Helper \ Oauth \Data ::class)
96
+ $ this ->oauthHelperMock = $ this ->getMockBuilder (OauthHelper ::class)
87
97
->disableOriginalConstructor ()
88
98
->setMethods (['getAdminTokenLifetime ' , 'getCustomerTokenLifetime ' ])
89
99
->getMock ();
90
100
91
- $ this ->dateMock = $ this ->getMockBuilder (\ Magento \ Framework \ Stdlib \ DateTime \DateTime ::class)
101
+ $ this ->dateMock = $ this ->getMockBuilder (Date ::class)
92
102
->disableOriginalConstructor ()
93
103
->setMethods (['gmtTimestamp ' ])
94
104
->getMock ();
95
105
96
- $ this ->dateTimeMock = $ this ->getMockBuilder (\ Magento \ Framework \ Stdlib \ DateTime::class)
106
+ $ this ->dateTimeMock = $ this ->getMockBuilder (DateTime::class)
97
107
->disableOriginalConstructor ()
98
108
->setMethods (['strToTime ' ])
99
109
->getMock ();
@@ -109,7 +119,7 @@ function ($str) {
109
119
);
110
120
111
121
$ this ->tokenUserContext = $ this ->objectManager ->getObject (
112
- \ Magento \ Webapi \ Model \ Authorization \ TokenUserContext::class,
122
+ TokenUserContext::class,
113
123
[
114
124
'request ' => $ this ->request ,
115
125
'tokenFactory ' => $ this ->tokenFactory ,
@@ -160,7 +170,7 @@ public function testNoTokenInDatabase()
160
170
->with ('Authorization ' )
161
171
->will ($ this ->returnValue ("Bearer {$ bearerToken }" ));
162
172
163
- $ token = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Oauth \ Token::class)
173
+ $ token = $ this ->getMockBuilder (Token::class)
164
174
->disableOriginalConstructor ()
165
175
->setMethods (['loadByToken ' , 'getId ' , '__wakeup ' ])
166
176
->getMock ();
@@ -188,7 +198,7 @@ public function testRevokedToken()
188
198
->with ('Authorization ' )
189
199
->will ($ this ->returnValue ("Bearer {$ bearerToken }" ));
190
200
191
- $ token = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Oauth \ Token::class)
201
+ $ token = $ this ->getMockBuilder (Token::class)
192
202
->disableOriginalConstructor ()
193
203
->setMethods (['loadByToken ' , 'getId ' , 'getRevoked ' , '__wakeup ' ])
194
204
->getMock ();
@@ -222,7 +232,7 @@ public function testValidToken($userType, $userId, $expectedUserType, $expectedU
222
232
->with ('Authorization ' )
223
233
->will ($ this ->returnValue ("Bearer {$ bearerToken }" ));
224
234
225
- $ token = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Oauth \ Token::class)
235
+ $ token = $ this ->getMockBuilder (Token::class)
226
236
->disableOriginalConstructor ()
227
237
->setMethods (
228
238
[
@@ -255,7 +265,7 @@ public function testValidToken($userType, $userId, $expectedUserType, $expectedU
255
265
256
266
switch ($ userType ) {
257
267
case UserContextInterface::USER_TYPE_INTEGRATION :
258
- $ integration = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Integration::class)
268
+ $ integration = $ this ->getMockBuilder (Integration::class)
259
269
->disableOriginalConstructor ()
260
270
->setMethods (['getId ' , '__wakeup ' ])
261
271
->getMock ();
@@ -333,7 +343,7 @@ public function testExpiredToken($tokenData, $tokenTtl, $currentTime, $expectedU
333
343
->with ('Authorization ' )
334
344
->will ($ this ->returnValue ("Bearer {$ bearerToken }" ));
335
345
336
- $ token = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Oauth \ Token::class)
346
+ $ token = $ this ->getMockBuilder (Token::class)
337
347
->disableOriginalConstructor ()
338
348
->setMethods (
339
349
[
@@ -378,7 +388,7 @@ public function testExpiredToken($tokenData, $tokenTtl, $currentTime, $expectedU
378
388
379
389
switch ($ tokenData ['user_type ' ]) {
380
390
case UserContextInterface::USER_TYPE_INTEGRATION :
381
- $ integration = $ this ->getMockBuilder (\ Magento \ Integration \ Model \ Integration::class)
391
+ $ integration = $ this ->getMockBuilder (Integration::class)
382
392
->disableOriginalConstructor ()
383
393
->setMethods (['getId ' , '__wakeup ' ])
384
394
->getMock ();
@@ -411,7 +421,8 @@ public function testExpiredToken($tokenData, $tokenTtl, $currentTime, $expectedU
411
421
}
412
422
413
423
/**
414
- * Data provider for expired token test
424
+ * Data provider for expired token test.
425
+ *
415
426
* @return array
416
427
*/
417
428
public function getExpiredTestTokenData ()
@@ -426,7 +437,7 @@ public function getExpiredTestTokenData()
426
437
],
427
438
'tokenTtl ' => 1 ,
428
439
'currentTime ' => $ time ,
429
- 'expedtedUserType ' => null ,
440
+ 'expectedUserType ' => null ,
430
441
'expectedUserId ' => null ,
431
442
],
432
443
'token_vigent_admin ' => [
@@ -437,7 +448,7 @@ public function getExpiredTestTokenData()
437
448
],
438
449
'tokenTtl ' => 1 ,
439
450
'currentTime ' => $ time ,
440
- 'expedtedUserType ' => UserContextInterface::USER_TYPE_ADMIN ,
451
+ 'expectedUserType ' => UserContextInterface::USER_TYPE_ADMIN ,
441
452
'expectedUserId ' => 1234 ,
442
453
],
443
454
'token_expired_customer ' => [
@@ -448,7 +459,7 @@ public function getExpiredTestTokenData()
448
459
],
449
460
'tokenTtl ' => 1 ,
450
461
'currentTime ' => $ time ,
451
- 'expedtedUserType ' => null ,
462
+ 'expectedUserType ' => null ,
452
463
'expectedUserId ' => null ,
453
464
],
454
465
'token_vigent_customer ' => [
@@ -459,7 +470,7 @@ public function getExpiredTestTokenData()
459
470
],
460
471
'tokenTtl ' => 1 ,
461
472
'currentTime ' => $ time ,
462
- 'expedtedUserType ' => UserContextInterface::USER_TYPE_CUSTOMER ,
473
+ 'expectedUserType ' => UserContextInterface::USER_TYPE_CUSTOMER ,
463
474
'expectedUserId ' => 1234 ,
464
475
],
465
476
'token_expired_integration ' => [
@@ -481,7 +492,7 @@ public function getExpiredTestTokenData()
481
492
],
482
493
'tokenTtl ' => 1 ,
483
494
'currentTime ' => $ time ,
484
- 'expedtedUserType ' => UserContextInterface::USER_TYPE_INTEGRATION ,
495
+ 'expectedUserType ' => UserContextInterface::USER_TYPE_INTEGRATION ,
485
496
'expectedUserId ' => 1234 ,
486
497
],
487
498
'token_expired_guest ' => [
@@ -492,7 +503,7 @@ public function getExpiredTestTokenData()
492
503
],
493
504
'tokenTtl ' => 1 ,
494
505
'currentTime ' => $ time ,
495
- 'expedtedUserType ' => null ,
506
+ 'expectedUserType ' => null ,
496
507
'expectedUserId ' => null ,
497
508
],
498
509
'token_vigent_guest ' => [
@@ -503,7 +514,7 @@ public function getExpiredTestTokenData()
503
514
],
504
515
'tokenTtl ' => 1 ,
505
516
'currentTime ' => $ time ,
506
- 'expedtedUserType ' => null ,
517
+ 'expectedUserType ' => null ,
507
518
'expectedUserId ' => null ,
508
519
],
509
520
];
0 commit comments