public function EuropeanUnionVatTest::testRenderVerificationResult in Commerce Core 8.2
@covers ::renderVerificationResult
File
- modules/
tax/ tests/ src/ Kernel/ Plugin/ Commerce/ TaxNumberType/ EuropeanUnionVatTest.php, line 160
Class
- EuropeanUnionVatTest
- @coversDefaultClass \Drupal\commerce_tax\Plugin\Commerce\TaxNumberType\EuropeanUnionVat @group commerce
Namespace
Drupal\Tests\commerce_tax\Kernel\Plugin\Commerce\TaxNumberTypeCode
public function testRenderVerificationResult() {
$request_time = $this->container
->get('datetime.time')
->getRequestTime();
// Pre-defined error.
$result = VerificationResult::failure($request_time, [
'error' => 'invalid_number',
]);
$element = $this->plugin
->renderVerificationResult($result);
$this
->assertArrayHasKey('error', $element);
$this
->assertArrayNotHasKey('name', $element);
$this
->assertArrayNotHasKey('address', $element);
$this
->assertEquals('The tax number is not in the right format.', (string) $element['error']['#plain_text']);
// Unknown error.
$result = VerificationResult::failure($request_time, [
'error' => 'An unknown error occurred.',
]);
$element = $this->plugin
->renderVerificationResult($result);
$this
->assertArrayHasKey('error', $element);
$this
->assertArrayNotHasKey('name', $element);
$this
->assertArrayNotHasKey('address', $element);
$this
->assertEquals('An unknown error occurred.', $element['error']['#plain_text']);
// Name and address.
$result = VerificationResult::success($request_time, [
'name' => 'John Smith',
'address' => '9 Drupal Ave',
]);
$element = $this->plugin
->renderVerificationResult($result);
$this
->assertArrayNotHasKey('error', $element);
$this
->assertArrayHasKey('name', $element);
$this
->assertArrayHasKey('address', $element);
$this
->assertEquals('John Smith', $element['name']['#plain_text']);
$this
->assertEquals('9 Drupal Ave', $element['address']['#plain_text']);
}