public function TaxNumberTest::testVerificationEndpointAccess in Commerce Core 8.2
Tests access control for the verification endpoints.
File
- modules/
tax/ tests/ src/ FunctionalJavascript/ TaxNumberTest.php, line 313
Class
- TaxNumberTest
- Tests the tax number widget and formatter.
Namespace
Drupal\Tests\commerce_tax\FunctionalJavascriptCode
public function testVerificationEndpointAccess() {
$this->customerProfile
->set('tax_number', [
'type' => 'serbian_vat',
'value' => '124',
'verification_state' => VerificationResult::STATE_FAILURE,
'verification_timestamp' => strtotime('2019/08/09'),
'verification_result' => [
'name' => 'Google LLC',
],
]);
$this->customerProfile
->save();
// Valid url.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => UrlData::encode([
'profile',
$this->customerProfile
->id(),
'tax_number',
'default',
]),
]));
$this
->assertSession()
->pageTextNotContains('Access Denied');
$this
->assertSession()
->pageTextContains('Google LLC');
// The tax_number doesn't match the one on the parent entity.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '125',
'context' => UrlData::encode([
'profile',
$this->customerProfile
->id(),
'tax_number',
'default',
]),
]));
$this
->assertSession()
->pageTextContains('Access Denied');
// Invalid context.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => 'INVALID',
]));
$this
->assertSession()
->pageTextContains('Access Denied');
// Incorrect number of parameters.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => UrlData::encode([
'profile',
]),
]));
$this
->assertSession()
->pageTextContains('Access Denied');
// Invalid entity type.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => UrlData::encode([
'profile2',
$this->customerProfile
->id(),
'tax_number',
'default',
]),
]));
$this
->assertSession()
->pageTextContains('Access Denied');
// Invalid entity.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => UrlData::encode([
'profile',
'99',
'tax_number',
'default',
]),
]));
$this
->assertSession()
->pageTextContains('Access Denied');
// Invalid field.
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => UrlData::encode([
'profile',
$this->customerProfile
->id(),
'address',
'default',
]),
]));
$this
->assertSession()
->pageTextContains('Access Denied');
// No access to parent entity.
$this
->drupalLogout();
$this
->drupalGet(Url::fromRoute('commerce_tax.verification_result', [
'tax_number' => '124',
'context' => UrlData::encode([
'profile',
$this->customerProfile
->id(),
'tax_number',
'default',
]),
]));
$this
->assertSession()
->pageTextContains('Access Denied');
}