|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\Tests\commerce_tax\FunctionalJavascript\Plugin\Commerce\TaxType; |
| 4 | + |
| 5 | +use Drupal\commerce_tax\Entity\TaxType; |
| 6 | +use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase; |
| 7 | +use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait; |
| 8 | + |
| 9 | +/** |
| 10 | + * Tests the commerce_tax custom plugin. |
| 11 | + * |
| 12 | + * @group commerce |
| 13 | + */ |
| 14 | +class CustomTest extends CommerceBrowserTestBase { |
| 15 | + |
| 16 | + use JavascriptTestTrait; |
| 17 | + |
| 18 | + /** |
| 19 | + * Modules to enable. |
| 20 | + * |
| 21 | + * @var array |
| 22 | + */ |
| 23 | + public static $modules = [ |
| 24 | + 'commerce_tax', |
| 25 | + ]; |
| 26 | + |
| 27 | + /** |
| 28 | + * {@inheritdoc} |
| 29 | + */ |
| 30 | + protected function getAdministratorPermissions() { |
| 31 | + return array_merge([ |
| 32 | + 'administer commerce_tax_type', |
| 33 | + ], parent::getAdministratorPermissions()); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Tests the custom plugin. |
| 38 | + */ |
| 39 | + public function testTaxTypeCustom() { |
| 40 | + /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $tax_type */ |
| 41 | + $tax_type = $this->createEntity('commerce_tax_type', [ |
| 42 | + 'id' => 'custom', |
| 43 | + 'plugin' => 'custom', |
| 44 | + 'label' => 'Custom', |
| 45 | + ]); |
| 46 | + |
| 47 | + $this->drupalGet($tax_type->toUrl('edit-form')); |
| 48 | + $this->getSession()->getPage()->pressButton('remove_rate0'); |
| 49 | + $this->waitForAjaxToFinish(); |
| 50 | + $this->getSession()->getPage()->pressButton('remove_territory0'); |
| 51 | + $this->waitForAjaxToFinish(); |
| 52 | + $this->submitForm([], t('Save')); |
| 53 | + $this->assertSession()->pageTextContains('Please add at least one rate.'); |
| 54 | + $this->assertSession()->pageTextContains('Please add at least one territory.'); |
| 55 | + |
| 56 | + $this->getSession()->getPage()->selectFieldOption('configuration[custom][display_label]', 'vat'); |
| 57 | + $this->getSession()->getPage()->pressButton('Add rate'); |
| 58 | + $this->waitForAjaxToFinish(); |
| 59 | + $this->getSession()->getPage()->fillField('configuration[custom][rates][0][rate][label]', 'Sample rate'); |
| 60 | + $this->getSession()->getPage()->fillField('configuration[custom][rates][0][percentage]', '15'); |
| 61 | + $this->getSession()->getPage()->pressButton('Add rate'); |
| 62 | + $this->waitForAjaxToFinish(); |
| 63 | + $this->getSession()->getPage()->fillField('configuration[custom][rates][1][rate][label]', 'Sample rate 2'); |
| 64 | + $this->getSession()->getPage()->fillField('configuration[custom][rates][1][percentage]', '17.5'); |
| 65 | + |
| 66 | + $this->getSession()->getPage()->pressButton('Add territory'); |
| 67 | + $this->waitForAjaxToFinish(); |
| 68 | + $this->getSession()->getPage()->selectFieldOption('configuration[custom][territories][0][territory][country_code]', 'FR'); |
| 69 | + $this->waitForAjaxToFinish(); |
| 70 | + $this->getSession()->getPage()->pressButton('Add territory'); |
| 71 | + $this->waitForAjaxToFinish(); |
| 72 | + $this->getSession()->getPage()->selectFieldOption('configuration[custom][territories][1][territory][country_code]', 'IT'); |
| 73 | + $this->waitForAjaxToFinish(); |
| 74 | + $this->submitForm([], t('Save')); |
| 75 | + \Drupal::service('entity_type.manager')->getStorage('commerce_tax_type')->resetCache([$tax_type->id()]); |
| 76 | + $tax_type = TaxType::load($tax_type->id()); |
| 77 | + $plugin_configuration = $tax_type->getPlugin()->getConfiguration(); |
| 78 | + $this->assertEquals('vat', $plugin_configuration['display_label']); |
| 79 | + $this->assertEquals('Sample rate', $plugin_configuration['rates'][0]['label']); |
| 80 | + $this->assertEquals('0.15', $plugin_configuration['rates'][0]['percentage']); |
| 81 | + $this->assertEquals('Sample rate 2', $plugin_configuration['rates'][1]['label']); |
| 82 | + $this->assertEquals('0.175', $plugin_configuration['rates'][1]['percentage']); |
| 83 | + |
| 84 | + $this->assertEquals('FR', $plugin_configuration['territories'][0]['country_code']); |
| 85 | + $this->assertEquals('IT', $plugin_configuration['territories'][1]['country_code']); |
| 86 | + } |
| 87 | + |
| 88 | +} |
0 commit comments