1010use Magento \Store \Model \ScopeInterface ;
1111
1212/**
13+ * Class ValidationTest validates the agreement based on the payment method
1314 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1415 */
1516class ValidationTest extends \PHPUnit \Framework \TestCase
@@ -59,12 +60,24 @@ class ValidationTest extends \PHPUnit\Framework\TestCase
5960 */
6061 private $ agreementsFilterMock ;
6162
63+ /**
64+ * @var \PHPUnit_Framework_MockObject_MockObject
65+ */
66+ private $ quoteMock ;
67+
68+ /**
69+ * @var \PHPUnit_Framework_MockObject_MockObject
70+ */
71+ private $ quoteRepositoryMock ;
72+
6273 protected function setUp ()
6374 {
6475 $ this ->agreementsValidatorMock = $ this ->createMock (\Magento \Checkout \Api \AgreementsValidatorInterface::class);
6576 $ this ->subjectMock = $ this ->createMock (\Magento \Checkout \Api \PaymentInformationManagementInterface::class);
6677 $ this ->paymentMock = $ this ->createMock (\Magento \Quote \Api \Data \PaymentInterface::class);
6778 $ 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);
6881 $ this ->extensionAttributesMock = $ this ->createPartialMock (
6982 \Magento \Quote \Api \Data \PaymentExtension::class,
7083 ['getAgreementIds ' ]
@@ -81,7 +94,8 @@ protected function setUp()
8194 $ this ->agreementsValidatorMock ,
8295 $ this ->scopeConfigMock ,
8396 $ this ->checkoutAgreementsListMock ,
84- $ this ->agreementsFilterMock
97+ $ this ->agreementsFilterMock ,
98+ $ this ->quoteRepositoryMock
8599 );
86100 }
87101
@@ -95,6 +109,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrder()
95109 ->with (AgreementsProvider::PATH_ENABLED , ScopeInterface::SCOPE_STORE )
96110 ->willReturn (true );
97111 $ 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 );
98121 $ this ->agreementsFilterMock ->expects ($ this ->once ())
99122 ->method ('buildSearchCriteria ' )
100123 ->willReturn ($ searchCriteriaMock );
@@ -128,6 +151,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
128151 ->with (AgreementsProvider::PATH_ENABLED , ScopeInterface::SCOPE_STORE )
129152 ->willReturn (true );
130153 $ 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 );
131163 $ this ->agreementsFilterMock ->expects ($ this ->once ())
132164 ->method ('buildSearchCriteria ' )
133165 ->willReturn ($ searchCriteriaMock );
@@ -151,4 +183,38 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
151183 "The order wasn't placed. First, agree to the terms and conditions, then try placing your order again. "
152184 );
153185 }
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+ }
154220}
0 commit comments