13
13
use Magento \CheckoutAgreements \Model \AgreementsProvider ;
14
14
use Magento \CheckoutAgreements \Model \Api \SearchCriteria \ActiveStoreAgreementsFilter ;
15
15
use Magento \CheckoutAgreements \Model \Checkout \Plugin \GuestValidation ;
16
- use Magento \CheckoutAgreements \Model \EmulateStore ;
17
16
use Magento \Framework \Api \SearchCriteria ;
18
17
use Magento \Framework \App \Config \ScopeConfigInterface ;
19
18
use Magento \Quote \Api \CartRepositoryInterface ;
20
19
use Magento \Quote \Api \Data \AddressInterface ;
21
- use Magento \Quote \Api \Data \PaymentExtension ;
22
20
use Magento \Quote \Api \Data \PaymentExtensionInterface ;
23
21
use Magento \Quote \Api \Data \PaymentInterface ;
22
+ use Magento \Quote \Api \GuestCartRepositoryInterface ;
24
23
use Magento \Quote \Model \MaskedQuoteIdToQuoteId ;
25
24
use Magento \Quote \Model \Quote ;
25
+ use Magento \Store \Model \App \Emulation ;
26
26
use Magento \Store \Model \ScopeInterface ;
27
27
use PHPUnit \Framework \MockObject \MockObject ;
28
28
use PHPUnit \Framework \MockObject \RuntimeException ;
@@ -94,9 +94,9 @@ class GuestValidationTest extends TestCase
94
94
private CartRepositoryInterface |MockObject $ cartRepositoryMock ;
95
95
96
96
/**
97
- * @var EmulateStore |MockObject
97
+ * @var Emulation |MockObject
98
98
*/
99
- private EmulateStore |MockObject $ emulateStoreMock ;
99
+ private Emulation |MockObject $ storeEmulationMock ;
100
100
101
101
protected function setUp (): void
102
102
{
@@ -114,29 +114,25 @@ protected function setUp(): void
114
114
);
115
115
$ this ->quoteMock = $ this ->createMock (Quote::class);
116
116
$ this ->maskedQuoteIdToQuoteIdMock = $ this ->createMock (MaskedQuoteIdToQuoteId::class);
117
- $ this ->cartRepositoryMock = $ this ->createMock (CartRepositoryInterface ::class);
118
- $ this ->emulateStoreMock = $ this ->createMock (EmulateStore ::class);
117
+ $ this ->cartRepositoryMock = $ this ->createMock (GuestCartRepositoryInterface ::class);
118
+ $ this ->storeEmulationMock = $ this ->createMock (Emulation ::class);
119
119
120
120
$ storeId = 1 ;
121
121
$ this ->quoteMock ->expects ($ this ->once ())
122
122
->method ('getStoreId ' )
123
123
->willReturn ($ storeId );
124
- $ this ->maskedQuoteIdToQuoteIdMock ->expects ($ this ->once ())
125
- ->method ('execute ' )
126
- ->with ('0CQwCntNHR4yN9P5PUAzbxatvDvBXOce ' )
127
- ->willReturn (1000 );
128
124
$ this ->cartRepositoryMock ->expects ($ this ->once ())
129
125
->method ('get ' )
126
+ ->with ('0CQwCntNHR4yN9P5PUAzbxatvDvBXOce ' )
130
127
->willReturn ($ this ->quoteMock );
131
128
132
129
$ this ->model = new GuestValidation (
133
130
$ this ->agreementsValidatorMock ,
134
131
$ this ->scopeConfigMock ,
135
132
$ this ->checkoutAgreementsListMock ,
136
133
$ this ->agreementsFilterMock ,
137
- $ this ->maskedQuoteIdToQuoteIdMock ,
138
134
$ this ->cartRepositoryMock ,
139
- $ this ->emulateStoreMock
135
+ $ this ->storeEmulationMock
140
136
);
141
137
}
142
138
@@ -160,15 +156,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrder()
160
156
->with ($ searchCriteriaMock )
161
157
->willReturn ([1 ]);
162
158
$ this ->extensionAttributesMock ->expects ($ this ->once ())->method ('getAgreementIds ' )->willReturn ($ agreements );
159
+ $ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->with ($ agreements )->willReturn (true );
163
160
$ this ->paymentMock ->expects (static ::atLeastOnce ())
164
161
->method ('getExtensionAttributes ' )
165
162
->willReturn ($ this ->extensionAttributesMock );
166
- $ this ->emulateStoreMock ->expects ($ this ->once ())
167
- ->method ('execute ' )
168
- ->with ($ storeId , $ this ->callback (function ($ callback ) {
169
- return is_callable ($ callback );
170
- }))
171
- ->willReturn (true );
163
+ $ this ->storeEmulationMock ->expects ($ this ->once ())
164
+ ->method ('startEnvironmentEmulation ' )
165
+ ->with ($ storeId );
166
+ $ this ->storeEmulationMock ->expects ($ this ->once ())
167
+ ->method ('stopEnvironmentEmulation ' );
172
168
$ this ->model ->beforeSavePaymentInformationAndPlaceOrder (
173
169
$ this ->subjectMock ,
174
170
$ cartId ,
@@ -185,12 +181,6 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
185
181
$ cartId = '0CQwCntNHR4yN9P5PUAzbxatvDvBXOce ' ;
186
182
$ email = 'email@example.com ' ;
187
183
$ agreements = [1 , 2 , 3 ];
188
- $ this ->emulateStoreMock ->expects ($ this ->once ())
189
- ->method ('execute ' )
190
- ->with ($ storeId , $ this ->callback (function ($ callback ) {
191
- return is_callable ($ callback );
192
- }))
193
- ->willReturn (false );
194
184
$ this ->scopeConfigMock
195
185
->expects ($ this ->once ())
196
186
->method ('isSetFlag ' )
@@ -205,9 +195,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
205
195
->with ($ searchCriteriaMock )
206
196
->willReturn ([1 ]);
207
197
$ this ->extensionAttributesMock ->expects ($ this ->once ())->method ('getAgreementIds ' )->willReturn ($ agreements );
198
+ $ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->with ($ agreements )->willReturn (false );
208
199
$ this ->paymentMock ->expects (static ::atLeastOnce ())
209
200
->method ('getExtensionAttributes ' )
210
201
->willReturn ($ this ->extensionAttributesMock );
202
+ $ this ->storeEmulationMock ->expects ($ this ->once ())
203
+ ->method ('startEnvironmentEmulation ' )
204
+ ->with ($ storeId );
205
+ $ this ->storeEmulationMock ->expects ($ this ->once ())
206
+ ->method ('stopEnvironmentEmulation ' );
211
207
$ this ->model ->beforeSavePaymentInformationAndPlaceOrder (
212
208
$ this ->subjectMock ,
213
209
$ cartId ,
0 commit comments