13
13
use Magento \Framework \Exception \InputException ;
14
14
use Magento \Framework \Exception \NoSuchEntityException ;
15
15
use Magento \Framework \Intl \DateTimeFactory ;
16
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
16
17
use Magento \Framework \TestFramework \Unit \Matcher \MethodInvokedAtIndex ;
17
18
use Magento \Payment \Helper \Data ;
18
19
use Magento \Sales \Api \Data \OrderInterface ;
29
30
use Magento \Vault \Model \Ui \TokenUiComponentProviderInterface ;
30
31
use Magento \Vault \Model \VaultPaymentInterface ;
31
32
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
32
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
33
33
34
34
/**
35
35
* Class TokensConfigProviderTest
@@ -104,11 +104,21 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase
104
104
*/
105
105
private $ orderRepository ;
106
106
107
+ /**
108
+ * @var TokenUiComponentProviderInterface|MockObject
109
+ */
110
+ private $ tokenComponentProvider ;
111
+
107
112
/**
108
113
* @var ObjectManager
109
114
*/
110
115
private $ objectManager ;
111
116
117
+ /**
118
+ * @var TokensConfigProvider
119
+ */
120
+ private $ configProvider ;
121
+
112
122
protected function setUp ()
113
123
{
114
124
$ this ->paymentTokenRepository = $ this ->getMockBuilder (PaymentTokenRepositoryInterface::class)
@@ -138,6 +148,38 @@ protected function setUp()
138
148
$ this ->vaultPayment = $ this ->getMockForAbstractClass (VaultPaymentInterface::class);
139
149
140
150
$ this ->objectManager = new ObjectManager ($ this );
151
+
152
+ $ this ->initStoreMock ();
153
+
154
+ $ this ->tokenComponentProvider = $ this ->getMock (TokenUiComponentProviderInterface::class);
155
+
156
+ $ this ->configProvider = new TokensConfigProvider (
157
+ $ this ->session ,
158
+ $ this ->paymentTokenRepository ,
159
+ $ this ->filterBuilder ,
160
+ $ this ->searchCriteriaBuilder ,
161
+ $ this ->storeManager ,
162
+ $ this ->dateTimeFactory ,
163
+ [
164
+ self ::VAULT_PROVIDER_CODE => $ this ->tokenComponentProvider
165
+ ]
166
+ );
167
+
168
+ $ this ->objectManager ->setBackwardCompatibleProperty (
169
+ $ this ->configProvider ,
170
+ 'paymentDataHelper ' ,
171
+ $ this ->paymentDataHelper
172
+ );
173
+ $ this ->objectManager ->setBackwardCompatibleProperty (
174
+ $ this ->configProvider ,
175
+ 'paymentTokenManagement ' ,
176
+ $ this ->paymentTokenManagement
177
+ );
178
+ $ this ->objectManager ->setBackwardCompatibleProperty (
179
+ $ this ->configProvider ,
180
+ 'orderRepository ' ,
181
+ $ this ->orderRepository
182
+ );
141
183
}
142
184
143
185
/**
@@ -147,8 +189,6 @@ public function testGetTokensComponentsRegisteredCustomer()
147
189
{
148
190
$ customerId = 1 ;
149
191
150
- $ this ->initStoreMock ();
151
-
152
192
$ this ->session ->expects (static ::once ())
153
193
->method ('getCustomerId ' )
154
194
->willReturn ($ customerId );
@@ -170,7 +210,7 @@ public function testGetTokensComponentsRegisteredCustomer()
170
210
$ token = $ this ->getMockBuilder (PaymentTokenInterface::class)
171
211
->getMockForAbstractClass ();
172
212
173
- list ( $ tokenUiComponent, $ tokenUiComponentProvider ) = $ this ->getTokenUiComponentProvider ($ token );
213
+ $ tokenUiComponent = $ this ->getTokenUiComponentProvider ($ token );
174
214
175
215
$ searchCriteria = $ this ->getSearchCriteria ($ customerId , self ::ENTITY_ID , self ::VAULT_PROVIDER_CODE );
176
216
@@ -197,25 +237,7 @@ public function testGetTokensComponentsRegisteredCustomer()
197
237
->method ('getItems ' )
198
238
->willReturn ([$ token ]);
199
239
200
- $ configProvider = new TokensConfigProvider (
201
- $ this ->session ,
202
- $ this ->paymentTokenRepository ,
203
- $ this ->filterBuilder ,
204
- $ this ->searchCriteriaBuilder ,
205
- $ this ->storeManager ,
206
- $ this ->dateTimeFactory ,
207
- [
208
- self ::VAULT_PROVIDER_CODE => $ tokenUiComponentProvider
209
- ]
210
- );
211
-
212
- $ this ->objectManager ->setBackwardCompatibleProperty (
213
- $ configProvider ,
214
- 'paymentDataHelper ' ,
215
- $ this ->paymentDataHelper
216
- );
217
-
218
- static ::assertEquals ([$ tokenUiComponent ], $ configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
240
+ static ::assertEquals ([$ tokenUiComponent ], $ this ->configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
219
241
}
220
242
221
243
/**
@@ -263,7 +285,7 @@ public function testGetTokensComponentsGuestCustomer()
263
285
->method ('getEntityId ' )
264
286
->willReturn (self ::ENTITY_ID );
265
287
266
- list ( $ tokenUiComponent, $ tokenUiComponentProvider ) = $ this ->getTokenUiComponentProvider ($ token );
288
+ $ tokenUiComponent = $ this ->getTokenUiComponentProvider ($ token );
267
289
268
290
$ searchCriteria = $ this ->getSearchCriteria ($ customerId , self ::ENTITY_ID , self ::VAULT_PROVIDER_CODE );
269
291
@@ -290,35 +312,7 @@ public function testGetTokensComponentsGuestCustomer()
290
312
->method ('getItems ' )
291
313
->willReturn ([$ token ]);
292
314
293
- $ configProvider = new TokensConfigProvider (
294
- $ this ->session ,
295
- $ this ->paymentTokenRepository ,
296
- $ this ->filterBuilder ,
297
- $ this ->searchCriteriaBuilder ,
298
- $ this ->storeManager ,
299
- $ this ->dateTimeFactory ,
300
- [
301
- self ::VAULT_PROVIDER_CODE => $ tokenUiComponentProvider
302
- ]
303
- );
304
-
305
- $ this ->objectManager ->setBackwardCompatibleProperty (
306
- $ configProvider ,
307
- 'paymentDataHelper ' ,
308
- $ this ->paymentDataHelper
309
- );
310
- $ this ->objectManager ->setBackwardCompatibleProperty (
311
- $ configProvider ,
312
- 'paymentTokenManagement ' ,
313
- $ this ->paymentTokenManagement
314
- );
315
- $ this ->objectManager ->setBackwardCompatibleProperty (
316
- $ configProvider ,
317
- 'orderRepository ' ,
318
- $ this ->orderRepository
319
- );
320
-
321
- static ::assertEquals ([$ tokenUiComponent ], $ configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
315
+ static ::assertEquals ([$ tokenUiComponent ], $ this ->configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
322
316
}
323
317
324
318
/**
@@ -330,8 +324,6 @@ public function testGetTokensComponentsGuestCustomerOrderNotFound($exception)
330
324
{
331
325
$ customerId = null ;
332
326
333
- $ this ->initStoreMock ();
334
-
335
327
$ this ->session ->expects (static ::once ())
336
328
->method ('getCustomerId ' )
337
329
->willReturn ($ customerId );
@@ -366,35 +358,7 @@ public function testGetTokensComponentsGuestCustomerOrderNotFound($exception)
366
358
$ this ->searchCriteriaBuilder ->expects (self ::never ())
367
359
->method ('addFilters ' );
368
360
369
- $ configProvider = new TokensConfigProvider (
370
- $ this ->session ,
371
- $ this ->paymentTokenRepository ,
372
- $ this ->filterBuilder ,
373
- $ this ->searchCriteriaBuilder ,
374
- $ this ->storeManager ,
375
- $ this ->dateTimeFactory ,
376
- [
377
- self ::VAULT_PROVIDER_CODE => $ this ->getMock (TokenUiComponentProviderInterface::class)
378
- ]
379
- );
380
-
381
- $ this ->objectManager ->setBackwardCompatibleProperty (
382
- $ configProvider ,
383
- 'paymentDataHelper ' ,
384
- $ this ->paymentDataHelper
385
- );
386
- $ this ->objectManager ->setBackwardCompatibleProperty (
387
- $ configProvider ,
388
- 'paymentTokenManagement ' ,
389
- $ this ->paymentTokenManagement
390
- );
391
- $ this ->objectManager ->setBackwardCompatibleProperty (
392
- $ configProvider ,
393
- 'orderRepository ' ,
394
- $ this ->orderRepository
395
- );
396
-
397
- static ::assertEmpty ($ configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
361
+ static ::assertEmpty ($ this ->configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
398
362
}
399
363
400
364
/**
@@ -453,18 +417,66 @@ public function testGetTokensComponentsEmptyComponentProvider()
453
417
static ::assertEmpty ($ configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
454
418
}
455
419
420
+ /**
421
+ * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
422
+ */
423
+ public function testGetTokensComponentsForGuestCustomerWithoutStoredTokens ()
424
+ {
425
+ $ this ->session ->expects (static ::once ())
426
+ ->method ('getCustomerId ' )
427
+ ->willReturn (null );
428
+
429
+ $ this ->paymentDataHelper ->expects (static ::once ())
430
+ ->method ('getMethodInstance ' )
431
+ ->with (self ::VAULT_PAYMENT_CODE )
432
+ ->willReturn ($ this ->vaultPayment );
433
+
434
+ $ this ->vaultPayment ->expects (static ::once ())
435
+ ->method ('isActive ' )
436
+ ->with (self ::STORE_ID )
437
+ ->willReturn (true );
438
+ $ this ->vaultPayment ->expects (static ::once ())
439
+ ->method ('getProviderCode ' )
440
+ ->willReturn (self ::VAULT_PROVIDER_CODE );
441
+
442
+ $ this ->session ->expects (static ::once ())
443
+ ->method ('getReordered ' )
444
+ ->willReturn (self ::ORDER_ID );
445
+ $ this ->orderRepository ->expects (static ::once ())
446
+ ->method ('get ' )
447
+ ->with (self ::ORDER_ID )
448
+ ->willReturn ($ this ->getOrderMock ());
449
+
450
+ $ this ->paymentTokenManagement ->expects (static ::once ())
451
+ ->method ('getByPaymentId ' )
452
+ ->with (self ::ORDER_PAYMENT_ENTITY_ID )
453
+ ->willReturn (null );
454
+
455
+ $ this ->filterBuilder ->expects (static ::once ())
456
+ ->method ('setField ' )
457
+ ->with (PaymentTokenInterface::ENTITY_ID )
458
+ ->willReturnSelf ();
459
+ $ this ->filterBuilder ->expects (static ::never ())
460
+ ->method ('setValue ' );
461
+
462
+ $ this ->searchCriteriaBuilder ->expects (static ::never ())
463
+ ->method ('addFilters ' );
464
+
465
+ static ::assertEmpty ($ this ->configProvider ->getTokensComponents (self ::VAULT_PAYMENT_CODE ));
466
+ }
467
+
456
468
/**
457
469
* Create mock object for store
458
470
*/
459
471
private function initStoreMock ()
460
472
{
461
473
$ this ->store = $ this ->getMock (StoreInterface::class);
462
- $ this ->store ->expects (static ::once ())
474
+ $ this ->store ->expects (static ::any ())
463
475
->method ('getId ' )
464
476
->willReturn (self ::STORE_ID );
465
477
466
478
$ this ->storeManager = $ this ->getMock (StoreManagerInterface::class);
467
- $ this ->storeManager ->expects (static ::once ())
479
+ $ this ->storeManager ->expects (static ::any ())
468
480
->method ('getStore ' )
469
481
->with (null )
470
482
->willReturn ($ this ->store );
@@ -476,39 +488,37 @@ private function initStoreMock()
476
488
*/
477
489
private function getOrderMock ()
478
490
{
479
- /** @var OrderInterface|MockObject $orderMock */
480
- $ orderMock = $ this ->getMockBuilder (OrderInterface::class)
491
+ /** @var OrderInterface|MockObject $order */
492
+ $ order = $ this ->getMockBuilder (OrderInterface::class)
481
493
->getMockForAbstractClass ();
482
- /** @var OrderPaymentInterface|MockObject $orderPaymentMock */
483
- $ orderPaymentMock = $ this ->getMockBuilder (OrderPaymentInterface::class)
494
+ /** @var OrderPaymentInterface|MockObject $orderPayment */
495
+ $ orderPayment = $ this ->getMockBuilder (OrderPaymentInterface::class)
484
496
->getMockForAbstractClass ();
485
497
486
- $ orderMock ->expects (static ::once ())
498
+ $ order ->expects (static ::once ())
487
499
->method ('getPayment ' )
488
- ->willReturn ($ orderPaymentMock );
489
- $ orderPaymentMock ->expects (static ::once ())
500
+ ->willReturn ($ orderPayment );
501
+ $ orderPayment ->expects (static ::once ())
490
502
->method ('getEntityId ' )
491
503
->willReturn (self ::ORDER_PAYMENT_ENTITY_ID );
492
504
493
- return $ orderMock ;
505
+ return $ order ;
494
506
}
495
507
496
508
/**
497
509
* Get mock for token ui component provider
498
510
* @param PaymentTokenInterface $token
499
- * @return array
511
+ * @return TokenUiComponentInterface|MockObject
500
512
*/
501
513
private function getTokenUiComponentProvider ($ token )
502
514
{
503
515
$ tokenUiComponent = $ this ->getMock (TokenUiComponentInterface::class);
504
-
505
- $ tokenUiComponentProvider = $ this ->getMock (TokenUiComponentProviderInterface::class);
506
- $ tokenUiComponentProvider ->expects (static ::once ())
516
+ $ this ->tokenComponentProvider ->expects (static ::once ())
507
517
->method ('getComponentForToken ' )
508
518
->with ($ token )
509
519
->willReturn ($ tokenUiComponent );
510
520
511
- return [ $ tokenUiComponent, $ tokenUiComponentProvider ] ;
521
+ return $ tokenUiComponent ;
512
522
}
513
523
514
524
/**
0 commit comments