public function TaxNumberItemTest::testCheckValue in Commerce Core 8.2
Tests checking whether value can be used for tax calculation.
File
- modules/
tax/ tests/ src/ Kernel/ TaxNumberItemTest.php, line 109
Class
- TaxNumberItemTest
- Tests the 'commerce_tax_number' field type.
Namespace
Drupal\Tests\commerce_tax\KernelCode
public function testCheckValue() {
$entity = EntityTest::create([
'test_tax_number' => [
'type' => 'serbian_vat',
'value' => '123456',
'verification_state' => VerificationResult::STATE_UNKNOWN,
],
]);
$entity
->save();
$entity = $this
->reloadEntity($entity);
/** @var \Drupal\commerce_tax\Plugin\Field\FieldType\TaxNumberItemInterface $tax_number_item */
$tax_number_item = $entity
->get('test_tax_number')
->first();
$this
->assertTrue($tax_number_item
->checkValue('serbian_vat'));
// Type mismatch.
$this
->assertFalse($tax_number_item
->checkValue('european_union_vat'));
// Empty value.
$tax_number_item->value = '';
$this
->assertFalse($tax_number_item
->checkValue('other'));
// No verification_state specified.
$tax_number_item->value = '123456';
$tax_number_item->verification_state = NULL;
$this
->assertFalse($tax_number_item
->checkValue('serbian_vat'));
// Verification required.
$this->field
->setSetting('allow_unverified', FALSE);
$this->field
->save();
$entity = $this
->reloadEntity($entity);
/** @var \Drupal\commerce_tax\Plugin\Field\FieldType\TaxNumberItemInterface $tax_number_item */
$tax_number_item = $entity
->get('test_tax_number')
->first();
$this
->assertFalse($tax_number_item
->checkValue('serbian_vat'));
$tax_number_item->verification_state = VerificationResult::STATE_SUCCESS;
$this
->assertTrue($tax_number_item
->checkValue('serbian_vat'));
$entity = EntityTest::create([
'test_tax_number' => [
'type' => 'other',
'value' => '123',
],
]);
$entity
->save();
$entity = $this
->reloadEntity($entity);
/** @var \Drupal\commerce_tax\Plugin\Field\FieldType\TaxNumberItemInterface $tax_number_item */
$tax_number_item = $entity
->get('test_tax_number')
->first();
// Confirm that the verification_state is not checked
// if the type doesn't support verification.
$this
->assertTrue($tax_number_item
->checkValue('other'));
}