public function EuropeanUnionVatTest::testVerify in Commerce Core 8.2
@covers ::doVerify
File
- modules/
tax/ tests/ src/ Kernel/ Plugin/ Commerce/ TaxNumberType/ EuropeanUnionVatTest.php, line 101
Class
- EuropeanUnionVatTest
- @coversDefaultClass \Drupal\commerce_tax\Plugin\Commerce\TaxNumberType\EuropeanUnionVat @group commerce
Namespace
Drupal\Tests\commerce_tax\Kernel\Plugin\Commerce\TaxNumberTypeCode
public function testVerify() {
$request_time = $this->container
->get('datetime.time')
->getRequestTime();
$wsdl = drupal_get_path('module', 'commerce_tax') . '/tests/fixtures/checkVatService.wsdl';
$soap_client = $this
->getMockFromWsdl($wsdl);
// Modify the plugin's protected property to use the mock.
$property = new \ReflectionProperty(EuropeanUnionVat::class, 'soapClient');
$property
->setAccessible(TRUE);
$property
->setValue($this->plugin, $soap_client);
$invalid_result = new \stdClass();
$invalid_result->valid = FALSE;
$invalid_result->name = '---';
$invalid_result->address = '---';
$valid_result = new \stdClass();
$valid_result->valid = TRUE;
$valid_result->name = 'SLRL ALTEA EXPERTISE COMPTABLE';
$valid_result->address = '59 RUE DU MURIER';
$parameters = [
'countryCode' => 'AT',
'vatNumber' => 'U13585626',
];
$soap_client
->expects($this
->at(0))
->method('__soapCall')
->with('checkVat', [
$parameters,
])
->will($this
->returnValue($invalid_result));
$parameters = [
'countryCode' => 'FR',
'vatNumber' => 'K7399859412',
];
$soap_client
->expects($this
->at(1))
->method('__soapCall')
->with('checkVat', [
$parameters,
])
->will($this
->returnValue($valid_result));
$result = $this->plugin
->verify('123456');
$this
->assertTrue($result
->isFailure());
$this
->assertEquals($request_time, $result
->getTimestamp());
$this
->assertEquals([
'error' => 'invalid_number',
], $result
->getData());
$result = $this->plugin
->verify('ATU13585626');
$this
->assertTrue($result
->isFailure());
$this
->assertEquals($request_time, $result
->getTimestamp());
$this
->assertEquals([], $result
->getData());
$result = $this->plugin
->verify('FRK7399859412');
$this
->assertTrue($result
->isSuccess());
$this
->assertEquals($request_time, $result
->getTimestamp());
$this
->assertEquals([
'name' => 'SLRL ALTEA EXPERTISE COMPTABLE',
'address' => '59 RUE DU MURIER',
], $result
->getData());
}