-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2873394 by bojanz: Make taxes functional
- Loading branch information
Showing
6 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\commerce_tax\Kernel; | ||
|
||
use Drupal\commerce_order\Entity\Order; | ||
use Drupal\commerce_order\Entity\OrderItem; | ||
use Drupal\commerce_order\Entity\OrderItemType; | ||
use Drupal\commerce_price\Price; | ||
use Drupal\commerce_tax\Entity\TaxType; | ||
use Drupal\profile\Entity\Profile; | ||
use Drupal\Tests\commerce\Kernel\CommerceKernelTestBase; | ||
|
||
/** | ||
* Tests integration with orders. | ||
* | ||
* @group commerce | ||
*/ | ||
class OrderIntegrationTest extends CommerceKernelTestBase { | ||
|
||
/** | ||
* A sample order. | ||
* | ||
* @var \Drupal\commerce_order\Entity\OrderInterface | ||
*/ | ||
protected $order; | ||
|
||
/** | ||
* Modules to enable. | ||
* | ||
* @var array | ||
*/ | ||
public static $modules = [ | ||
'entity_reference_revisions', | ||
'path', | ||
'profile', | ||
'state_machine', | ||
'commerce_order', | ||
'commerce_tax', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->installEntitySchema('profile'); | ||
$this->installEntitySchema('commerce_order'); | ||
$this->installEntitySchema('commerce_order_item'); | ||
$this->installConfig(['commerce_order']); | ||
$user = $this->createUser(['mail' => $this->randomString() . '@example.com']); | ||
|
||
$this->store->set('prices_include_tax', TRUE); | ||
$this->store->save(); | ||
|
||
// The default store is US-WI, so imagine that the US has VAT. | ||
TaxType::create([ | ||
'id' => 'us_vat', | ||
'label' => 'US VAT', | ||
'plugin' => 'custom', | ||
'configuration' => [ | ||
'display_inclusive' => TRUE, | ||
'rates' => [ | ||
[ | ||
'id' => 'standard', | ||
'label' => 'Standard', | ||
'amount' => '0.2', | ||
], | ||
], | ||
'territories' => [ | ||
['country_code' => 'US', 'administrative_area' => 'WI'], | ||
['country_code' => 'US', 'administrative_area' => 'SC'], | ||
], | ||
], | ||
])->save(); | ||
OrderItemType::create([ | ||
'id' => 'test', | ||
'label' => 'Test', | ||
'orderType' => 'default', | ||
])->save(); | ||
$order = Order::create([ | ||
'type' => 'default', | ||
'store_id' => $this->store->id(), | ||
'state' => 'draft', | ||
'mail' => $user->getEmail(), | ||
'uid' => $user->id(), | ||
'ip_address' => '127.0.0.1', | ||
'order_number' => '6', | ||
]); | ||
$order->save(); | ||
$this->order = $this->reloadEntity($order); | ||
} | ||
|
||
/** | ||
* Tests that the store address is used as a default for new orders. | ||
*/ | ||
public function testDefaultProfile() { | ||
$order_item = OrderItem::create([ | ||
'type' => 'test', | ||
'quantity' => '1', | ||
'unit_price' => new Price('12.00', 'USD'), | ||
]); | ||
$order_item->save(); | ||
$this->order->addItem($order_item); | ||
$this->order->save(); | ||
$adjustments = $this->order->collectAdjustments(); | ||
$adjustment = reset($adjustments); | ||
$this->assertCount(1, $adjustments); | ||
$this->assertEquals(new Price('2.00', 'USD'), $adjustment->getAmount()); | ||
$this->assertEquals('us_vat|default|standard', $adjustment->getSourceId()); | ||
} | ||
|
||
/** | ||
* Tests the usage of default billing profile. | ||
*/ | ||
public function testBillingProfile() { | ||
$profile = Profile::create([ | ||
'type' => 'customer', | ||
'address' => [ | ||
'country_code' => 'US', | ||
'administrative_area' => 'SC', | ||
], | ||
]); | ||
$profile->save(); | ||
$order_item = OrderItem::create([ | ||
'type' => 'test', | ||
'quantity' => '1', | ||
'unit_price' => new Price('12.00', 'USD'), | ||
]); | ||
$order_item->save(); | ||
$this->order->addItem($order_item); | ||
$this->order->setBillingProfile($profile); | ||
$this->order->save(); | ||
$adjustments = $this->order->collectAdjustments(); | ||
$adjustment = reset($adjustments); | ||
$this->assertCount(1, $adjustments); | ||
$this->assertEquals(new Price('2.00', 'USD'), $adjustment->getAmount()); | ||
$this->assertEquals('us_vat|default|standard', $adjustment->getSourceId()); | ||
} | ||
|
||
} |