47 $this->customerAddressMock = $this->createMock(\
Magento\Customer\Helper\Address::class);
48 $this->customerVatMock = $this->createMock(\
Magento\Customer\Model\Vat::class);
49 $this->customerVatMock->expects($this->any())
50 ->method(
'getMerchantCountryCode')
51 ->willReturn(
'merchantCountryCode');
52 $this->customerVatMock->expects($this->any())
53 ->method(
'getMerchantVatNumber')
54 ->willReturn(
'merchantVatNumber');
56 $this->storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
58 $this->quoteAddressMock = $this->createPartialMock(\
Magento\Quote\Model\Quote\Address::class, [
61 'getValidatedCountryCode',
62 'getValidatedVatNumber',
66 'getVatRequestSuccess',
74 'request_identifier' =>
'test_request_identifier',
75 'request_date' =>
'test_request_date',
76 'request_success' =>
true,
79 $this->quoteAddressMock->expects(
84 $this->returnValue($this->testData[
'is_valid'])
86 $this->quoteAddressMock->expects(
91 $this->returnValue($this->testData[
'request_identifier'])
93 $this->quoteAddressMock->expects(
98 $this->returnValue($this->testData[
'request_date'])
100 $this->quoteAddressMock->expects(
103 'getVatRequestSuccess' 105 $this->returnValue($this->testData[
'request_success'])
107 $this->quoteAddressMock->expects($this->any())->method(
'getCountryId')->will($this->returnValue(
'en'));
108 $this->quoteAddressMock->expects($this->any())->method(
'getVatId')->will($this->returnValue(
'testVatID'));
110 $this->validationResult = new \Magento\Framework\DataObject($this->testData);
112 $this->model = new \Magento\Quote\Observer\Frontend\Quote\Address\VatValidator(
113 $this->customerAddressMock,
114 $this->customerVatMock
120 $this->customerVatMock->expects($this->never())->method(
'checkVatNumber');
122 $this->customerAddressMock->expects(
125 'hasValidateOnEachTransaction' 129 $this->returnValue(
false)
132 $this->quoteAddressMock->expects(
135 'getValidatedCountryCode' 137 $this->returnValue(
'en')
140 $this->quoteAddressMock->expects(
143 'getValidatedVatNumber' 145 $this->returnValue(
'testVatID')
148 $this->quoteAddressMock->expects($this->never())->method(
'save');
151 $this->validationResult,
152 $this->model->validate($this->quoteAddressMock, $this->storeMock)
158 $this->customerVatMock->expects(
165 'merchantCountryCode',
168 $this->returnValue($this->validationResult)
171 $this->customerAddressMock->expects(
174 'hasValidateOnEachTransaction' 178 $this->returnValue(
true)
181 $this->quoteAddressMock->expects(
184 'getValidatedCountryCode' 186 $this->returnValue(
'en')
189 $this->quoteAddressMock->expects(
192 'getValidatedVatNumber' 194 $this->returnValue(
'testVatID')
197 $this->quoteAddressMock->expects($this->once())->method(
'save');
200 $this->validationResult,
201 $this->model->validate($this->quoteAddressMock, $this->storeMock)
207 $this->customerVatMock->expects(
214 'merchantCountryCode',
217 $this->returnValue($this->validationResult)
220 $this->customerAddressMock->expects(
223 'hasValidateOnEachTransaction' 227 $this->returnValue(
false)
230 $this->quoteAddressMock->expects(
233 'getValidatedCountryCode' 235 $this->returnValue(
'someCountryCode')
238 $this->quoteAddressMock->expects($this->any())->method(
'getVatId')->will($this->returnValue(
'testVatID'));
240 $this->quoteAddressMock->expects($this->once())->method(
'save');
243 $this->validationResult,
244 $this->model->validate($this->quoteAddressMock, $this->storeMock)
250 $this->customerVatMock->expects(
257 'merchantCountryCode',
260 $this->returnValue($this->validationResult)
263 $this->customerAddressMock->expects(
266 'hasValidateOnEachTransaction' 270 $this->returnValue(
false)
273 $this->quoteAddressMock->expects(
276 'getValidatedCountryCode' 278 $this->returnValue(
'en')
281 $this->quoteAddressMock->expects($this->any())->method(
'getVatId')->will($this->returnValue(
'someVatID'));
283 $this->quoteAddressMock->expects($this->once())->method(
'save');
286 $this->validationResult,
287 $this->model->validate($this->quoteAddressMock, $this->storeMock)
293 $this->customerAddressMock->expects(
296 'isVatValidationEnabled' 298 $this->returnValue(
true)
301 $this->customerAddressMock->expects(
304 'getTaxCalculationAddressType' 306 $this->returnValue(\
Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING)
309 $this->quoteAddressMock->expects(
314 $this->returnValue(\
Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING)
317 $result = $this->model->isEnabled($this->quoteAddressMock, $this->storeMock);
323 $this->customerAddressMock->expects(
326 'isVatValidationEnabled' 328 $this->returnValue(
true)
330 $result = $this->model->isEnabled($this->quoteAddressMock, $this->storeMock);
testValidateWithDisabledValidationOnEachTransaction()
testIsEnabledWithBillingTaxCalculationAddressType()
testValidateWithDifferentCountryIdAndValidatedCountryCode()
testValidateWithEnabledValidationOnEachTransaction()
testValidateWithDifferentVatNumberAndValidatedVatNumber()
testIsEnabledWithEnabledVatValidation()