10
10
use Magento \Store \Model \ScopeInterface ;
11
11
12
12
/**
13
+ * Class ValidationTest validates the agreement based on the payment method
13
14
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
15
*/
15
16
class ValidationTest extends \PHPUnit \Framework \TestCase
@@ -59,12 +60,24 @@ class ValidationTest extends \PHPUnit\Framework\TestCase
59
60
*/
60
61
private $ agreementsFilterMock ;
61
62
63
+ /**
64
+ * @var \PHPUnit_Framework_MockObject_MockObject
65
+ */
66
+ private $ quoteMock ;
67
+
68
+ /**
69
+ * @var \PHPUnit_Framework_MockObject_MockObject
70
+ */
71
+ private $ quoteRepositoryMock ;
72
+
62
73
protected function setUp ()
63
74
{
64
75
$ this ->agreementsValidatorMock = $ this ->createMock (\Magento \Checkout \Api \AgreementsValidatorInterface::class);
65
76
$ this ->subjectMock = $ this ->createMock (\Magento \Checkout \Api \PaymentInformationManagementInterface::class);
66
77
$ this ->paymentMock = $ this ->createMock (\Magento \Quote \Api \Data \PaymentInterface::class);
67
78
$ this ->addressMock = $ this ->createMock (\Magento \Quote \Api \Data \AddressInterface::class);
79
+ $ this ->quoteMock = $ this ->createPartialMock (\Magento \Quote \Model \Quote::class, ['getIsMultiShipping ' ]);
80
+ $ this ->quoteRepositoryMock = $ this ->createMock (\Magento \Quote \Api \CartRepositoryInterface::class);
68
81
$ this ->extensionAttributesMock = $ this ->createPartialMock (
69
82
\Magento \Quote \Api \Data \PaymentExtension::class,
70
83
['getAgreementIds ' ]
@@ -81,7 +94,8 @@ protected function setUp()
81
94
$ this ->agreementsValidatorMock ,
82
95
$ this ->scopeConfigMock ,
83
96
$ this ->checkoutAgreementsListMock ,
84
- $ this ->agreementsFilterMock
97
+ $ this ->agreementsFilterMock ,
98
+ $ this ->quoteRepositoryMock
85
99
);
86
100
}
87
101
@@ -95,6 +109,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrder()
95
109
->with (AgreementsProvider::PATH_ENABLED , ScopeInterface::SCOPE_STORE )
96
110
->willReturn (true );
97
111
$ searchCriteriaMock = $ this ->createMock (\Magento \Framework \Api \SearchCriteria::class);
112
+ $ this ->quoteMock
113
+ ->expects ($ this ->once ())
114
+ ->method ('getIsMultiShipping ' )
115
+ ->willReturn (false );
116
+ $ this ->quoteRepositoryMock
117
+ ->expects ($ this ->once ())
118
+ ->method ('getActive ' )
119
+ ->with ($ cartId )
120
+ ->willReturn ($ this ->quoteMock );
98
121
$ this ->agreementsFilterMock ->expects ($ this ->once ())
99
122
->method ('buildSearchCriteria ' )
100
123
->willReturn ($ searchCriteriaMock );
@@ -128,6 +151,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
128
151
->with (AgreementsProvider::PATH_ENABLED , ScopeInterface::SCOPE_STORE )
129
152
->willReturn (true );
130
153
$ searchCriteriaMock = $ this ->createMock (\Magento \Framework \Api \SearchCriteria::class);
154
+ $ this ->quoteMock
155
+ ->expects ($ this ->once ())
156
+ ->method ('getIsMultiShipping ' )
157
+ ->willReturn (false );
158
+ $ this ->quoteRepositoryMock
159
+ ->expects ($ this ->once ())
160
+ ->method ('getActive ' )
161
+ ->with ($ cartId )
162
+ ->willReturn ($ this ->quoteMock );
131
163
$ this ->agreementsFilterMock ->expects ($ this ->once ())
132
164
->method ('buildSearchCriteria ' )
133
165
->willReturn ($ searchCriteriaMock );
@@ -151,4 +183,38 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
151
183
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again. "
152
184
);
153
185
}
186
+
187
+ public function testBeforeSavePaymentInformation ()
188
+ {
189
+ $ cartId = 100 ;
190
+ $ agreements = [1 , 2 , 3 ];
191
+ $ this ->scopeConfigMock
192
+ ->expects ($ this ->once ())
193
+ ->method ('isSetFlag ' )
194
+ ->with (AgreementsProvider::PATH_ENABLED , ScopeInterface::SCOPE_STORE )
195
+ ->willReturn (true );
196
+ $ this ->quoteMock
197
+ ->expects ($ this ->once ())
198
+ ->method ('getIsMultiShipping ' )
199
+ ->willReturn (false );
200
+ $ this ->quoteRepositoryMock
201
+ ->expects ($ this ->once ())
202
+ ->method ('getActive ' )
203
+ ->with ($ cartId )
204
+ ->willReturn ($ this ->quoteMock );
205
+ $ searchCriteriaMock = $ this ->createMock (\Magento \Framework \Api \SearchCriteria::class);
206
+ $ this ->agreementsFilterMock ->expects ($ this ->once ())
207
+ ->method ('buildSearchCriteria ' )
208
+ ->willReturn ($ searchCriteriaMock );
209
+ $ this ->checkoutAgreementsListMock ->expects ($ this ->once ())
210
+ ->method ('getList ' )
211
+ ->with ($ searchCriteriaMock )
212
+ ->willReturn ([1 ]);
213
+ $ this ->extensionAttributesMock ->expects ($ this ->once ())->method ('getAgreementIds ' )->willReturn ($ agreements );
214
+ $ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->with ($ agreements )->willReturn (true );
215
+ $ this ->paymentMock ->expects (static ::atLeastOnce ())
216
+ ->method ('getExtensionAttributes ' )
217
+ ->willReturn ($ this ->extensionAttributesMock );
218
+ $ this ->model ->beforeSavePaymentInformation ($ this ->subjectMock , $ cartId , $ this ->paymentMock , $ this ->addressMock );
219
+ }
154
220
}
0 commit comments