18
18
use Magento \Framework \Api \DataObjectHelper ;
19
19
use Magento \Framework \App \RequestInterface ;
20
20
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
21
+ use Magento \Quote \Api \CartRepositoryInterface ;
21
22
use Magento \Quote \Model \Quote ;
22
23
use Magento \Quote \Model \Quote \Address ;
23
24
use Magento \Quote \Model \Quote \Item ;
24
25
use Magento \Quote \Model \Quote \Item \Updater ;
25
26
use Magento \Sales \Model \AdminOrder \Create ;
26
27
use Magento \Sales \Model \AdminOrder \Product ;
28
+ use Magento \Quote \Model \QuoteFactory ;
27
29
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
28
30
29
31
/**
@@ -39,6 +41,16 @@ class CreateTest extends \PHPUnit\Framework\TestCase
39
41
*/
40
42
private $ adminOrderCreate ;
41
43
44
+ /**
45
+ * @var CartRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
46
+ */
47
+ private $ quoteRepository ;
48
+
49
+ /**
50
+ * @var QuoteFactory|\PHPUnit_Framework_MockObject_MockObject
51
+ */
52
+ private $ quoteFactory ;
53
+
42
54
/**
43
55
* @var SessionQuote|MockObject
44
56
*/
@@ -76,12 +88,22 @@ class CreateTest extends \PHPUnit\Framework\TestCase
76
88
77
89
protected function setUp ()
78
90
{
79
- $ this ->sessionQuote = $ this ->createMock (SessionQuote::class);
80
91
$ this ->formFactory = $ this ->createPartialMock (FormFactory::class, ['create ' ]);
92
+ $ this ->quoteFactory = $ this ->createPartialMock (QuoteFactory::class, ['create ' ]);
81
93
$ this ->customerFactory = $ this ->createPartialMock (CustomerInterfaceFactory::class, ['create ' ]);
82
94
83
95
$ this ->itemUpdater = $ this ->createMock (Updater::class);
84
96
97
+ $ this ->quoteRepository = $ this ->getMockBuilder (CartRepositoryInterface::class)
98
+ ->disableOriginalConstructor ()
99
+ ->setMethods (['getForCustomer ' ])
100
+ ->getMockForAbstractClass ();
101
+
102
+ $ this ->sessionQuote = $ this ->getMockBuilder (\Magento \Backend \Model \Session \Quote::class)
103
+ ->disableOriginalConstructor ()
104
+ ->setMethods (['getQuote ' , 'getStoreId ' , 'getCustomerId ' ])
105
+ ->getMock ();
106
+
85
107
$ this ->customerMapper = $ this ->getMockBuilder (Mapper::class)
86
108
->setMethods (['toFlatArray ' ])
87
109
->disableOriginalConstructor ()
@@ -103,6 +125,8 @@ protected function setUp()
103
125
'quoteItemUpdater ' => $ this ->itemUpdater ,
104
126
'customerMapper ' => $ this ->customerMapper ,
105
127
'dataObjectHelper ' => $ this ->dataObjectHelper ,
128
+ 'quoteRepository ' => $ this ->quoteRepository ,
129
+ 'quoteFactory ' => $ this ->quoteFactory ,
106
130
]
107
131
);
108
132
}
@@ -264,4 +288,28 @@ public function testApplyCoupon()
264
288
$ object = $ this ->adminOrderCreate ->applyCoupon ($ couponCode );
265
289
self ::assertEquals ($ this ->adminOrderCreate , $ object );
266
290
}
291
+
292
+ public function testGetCustomerCart ()
293
+ {
294
+ $ storeId = 2 ;
295
+ $ customerId = 2 ;
296
+ $ cartResult = [
297
+ 'cart ' => true ,
298
+ ];
299
+
300
+ $ this ->quoteFactory ->expects ($ this ->once ())
301
+ ->method ('create ' );
302
+ $ this ->sessionQuote ->expects ($ this ->once ())
303
+ ->method ('getStoreId ' )
304
+ ->willReturn ($ storeId );
305
+ $ this ->sessionQuote ->expects ($ this ->once ())
306
+ ->method ('getCustomerId ' )
307
+ ->willReturn ($ customerId );
308
+ $ this ->quoteRepository ->expects ($ this ->once ())
309
+ ->method ('getForCustomer ' )
310
+ ->with ($ customerId , [$ storeId ])
311
+ ->willReturn ($ cartResult );
312
+
313
+ $ this ->assertEquals ($ cartResult , $ this ->adminOrderCreate ->getCustomerCart ());
314
+ }
267
315
}
0 commit comments