6
6
7
7
namespace Magento \Quote \Test \Unit \Model ;
8
8
9
+ use Magento \Framework \App \RequestInterface ;
9
10
use Magento \Framework \Exception \NoSuchEntityException ;
10
11
12
+ use Magento \Framework \HTTP \PhpEnvironment \RemoteAddress ;
11
13
use Magento \Quote \Model \CustomerManagement ;
14
+ use Magento \Quote \Model \QuoteIdMaskFactory ;
12
15
use Magento \Sales \Api \Data \OrderAddressInterface ;
13
16
14
17
/**
@@ -137,6 +140,21 @@ class QuoteManagementTest extends \PHPUnit\Framework\TestCase
137
140
*/
138
141
private $ quoteFactoryMock ;
139
142
143
+ /**
144
+ * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
145
+ */
146
+ private $ requestMock ;
147
+
148
+ /**
149
+ * @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress|\PHPUnit_Framework_MockObject_MockObject
150
+ */
151
+ private $ remoteAddressMock ;
152
+
153
+ /**
154
+ * @var \Magento\Quote\Model\QuoteIdMaskFactory|\PHPUnit_Framework_MockObject_MockObject
155
+ */
156
+ private $ quoteIdMaskFactoryMock ;
157
+
140
158
/**
141
159
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
142
160
*/
@@ -178,18 +196,20 @@ protected function setUp()
178
196
);
179
197
180
198
$ this ->quoteMock = $ this ->createPartialMock (\Magento \Quote \Model \Quote::class, [
181
- 'getId ' ,
182
- 'getCheckoutMethod ' ,
183
- 'setCheckoutMethod ' ,
184
- 'setCustomerId ' ,
185
- 'setCustomerEmail ' ,
186
- 'getBillingAddress ' ,
187
- 'setCustomerIsGuest ' ,
188
- 'setCustomerGroupId ' ,
189
- 'assignCustomer ' ,
190
- 'getPayment ' ,
191
- 'collectTotals '
192
- ]);
199
+ 'assignCustomer ' ,
200
+ 'collectTotals ' ,
201
+ 'getBillingAddress ' ,
202
+ 'getCheckoutMethod ' ,
203
+ 'getPayment ' ,
204
+ 'setCheckoutMethod ' ,
205
+ 'setCustomerEmail ' ,
206
+ 'setCustomerGroupId ' ,
207
+ 'setCustomerId ' ,
208
+ 'setCustomerIsGuest ' ,
209
+ 'setRemoteIp ' ,
210
+ 'setXForwardedFor ' ,
211
+ 'getId ' ,
212
+ ]);
193
213
194
214
$ this ->quoteAddressFactory = $ this ->createPartialMock (
195
215
\Magento \Quote \Model \Quote \AddressFactory::class,
@@ -237,8 +257,11 @@ protected function setUp()
237
257
238
258
// Set the new dependency
239
259
$ this ->quoteIdMock = $ this ->createMock (\Magento \Quote \Model \QuoteIdMask::class);
240
- $ quoteIdFactoryMock = $ this ->createPartialMock (\Magento \Quote \Model \QuoteIdMaskFactory::class, ['create ' ]);
241
- $ this ->setPropertyValue ($ this ->model , 'quoteIdMaskFactory ' , $ quoteIdFactoryMock );
260
+ $ this ->quoteIdMaskFactoryMock = $ this ->createPartialMock (QuoteIdMaskFactory::class, ['create ' ]);
261
+ $ this ->setPropertyValue ($ this ->model , 'quoteIdMaskFactory ' , $ this ->quoteIdMaskFactoryMock );
262
+
263
+ $ this ->requestMock = $ this ->createPartialMockForAbstractClass (RequestInterface::class, ['getServer ' ]);
264
+ $ this ->remoteAddressMock = $ this ->createMock (RemoteAddress::class);
242
265
}
243
266
244
267
public function testCreateEmptyCartAnonymous ()
@@ -676,7 +699,11 @@ public function testPlaceOrderIfCustomerIsGuest()
676
699
'checkoutSession ' => $ this ->checkoutSessionMock ,
677
700
'customerSession ' => $ this ->customerSessionMock ,
678
701
'accountManagement ' => $ this ->accountManagementMock ,
679
- 'quoteFactory ' => $ this ->quoteFactoryMock
702
+ 'quoteFactory ' => $ this ->quoteFactoryMock ,
703
+ 'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
704
+ 'addressRepository ' => $ this ->addressRepositoryMock ,
705
+ 'request ' => $ this ->requestMock ,
706
+ 'remoteAddress ' => $ this ->remoteAddressMock ,
680
707
]
681
708
)
682
709
->getMock ();
@@ -709,13 +736,15 @@ public function testPlaceOrder()
709
736
$ orderId = 332 ;
710
737
$ orderIncrementId = 100003332 ;
711
738
$ orderStatus = 'status1 ' ;
739
+ $ remoteAddress = '192.168.1.10 ' ;
740
+ $ forwardedForIp = '192.168.1.11 ' ;
712
741
713
742
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\QuoteManagement $service */
714
743
$ service = $ this ->getMockBuilder (\Magento \Quote \Model \QuoteManagement::class)
715
744
->setMethods (['submit ' ])
716
745
->setConstructorArgs (
717
746
[
718
- 'eventManager ' => $ this ->eventManager ,
747
+ 'eventManager ' => $ this ->eventManager ,
719
748
'quoteValidator ' => $ this ->quoteValidator ,
720
749
'orderFactory ' => $ this ->orderFactory ,
721
750
'orderManagement ' => $ this ->orderManagement ,
@@ -734,7 +763,11 @@ public function testPlaceOrder()
734
763
'checkoutSession ' => $ this ->checkoutSessionMock ,
735
764
'customerSession ' => $ this ->customerSessionMock ,
736
765
'accountManagement ' => $ this ->accountManagementMock ,
737
- 'quoteFactory ' => $ this ->quoteFactoryMock
766
+ 'quoteFactory ' => $ this ->quoteFactoryMock ,
767
+ 'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
768
+ 'addressRepository ' => $ this ->addressRepositoryMock ,
769
+ 'request ' => $ this ->requestMock ,
770
+ 'remoteAddress ' => $ this ->remoteAddressMock ,
738
771
]
739
772
)
740
773
->getMock ();
@@ -762,6 +795,17 @@ public function testPlaceOrder()
762
795
->method ('setCustomerIsGuest ' )
763
796
->with (true );
764
797
798
+ $ this ->remoteAddressMock
799
+ ->method ('getRemoteAddress ' )
800
+ ->willReturn ($ remoteAddress );
801
+
802
+ $ this ->requestMock
803
+ ->method ('getServer ' )
804
+ ->willReturn ($ forwardedForIp );
805
+
806
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('setRemoteIp ' )->with ($ remoteAddress );
807
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('setXForwardedFor ' )->with ($ forwardedForIp );
808
+
765
809
$ service ->expects ($ this ->once ())->method ('submit ' )->willReturn ($ orderMock );
766
810
767
811
$ this ->quoteMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ cartId );
0 commit comments