You are here

protected function EuropeanUnionVatTest::buildOrder in Commerce Core 8.2

Builds an order for testing purposes.

Parameters

string $customer_country: The customer's country code.

string $store_country: The store's country code.

string $tax_number: The customer's tax number.

array $store_registrations: The store's tax registrations.

bool $digital: Whether the order will be used for a digital product.

Return value

\Drupal\commerce_order\Entity\OrderInterface The order.

4 calls to EuropeanUnionVatTest::buildOrder()
EuropeanUnionVatTest::testApplication in modules/tax/tests/src/Kernel/Plugin/Commerce/TaxType/EuropeanUnionVatTest.php
@covers ::applies @covers ::apply
NorwegianVatTest::testApplication in modules/tax/tests/src/Kernel/Plugin/Commerce/TaxType/NorwegianVatTest.php
@covers ::applies @covers ::apply
SwissVatTest::testApplication in modules/tax/tests/src/Kernel/Plugin/Commerce/TaxType/SwissVatTest.php
@covers ::applies @covers ::apply
UnitedKingdomVatTest::testApplication in modules/tax/tests/src/Kernel/Plugin/Commerce/TaxType/UnitedKingdomVatTest.php
@covers ::applies @covers ::apply

File

modules/tax/tests/src/Kernel/Plugin/Commerce/TaxType/EuropeanUnionVatTest.php, line 224

Class

EuropeanUnionVatTest
@coversDefaultClass \Drupal\commerce_tax\Plugin\Commerce\TaxType\EuropeanUnionVat @group commerce

Namespace

Drupal\Tests\commerce_tax\Kernel\Plugin\Commerce\TaxType

Code

protected function buildOrder($customer_country, $store_country, $tax_number = '', array $store_registrations = [], $digital = FALSE) {
  $store = Store::create([
    'type' => 'default',
    'label' => 'My store',
    'address' => [
      'country_code' => $store_country,
    ],
    'prices_include_tax' => FALSE,
    'tax_registrations' => $store_registrations,
  ]);
  $store
    ->save();
  $customer_profile = Profile::create([
    'type' => 'customer',
    'uid' => $this->user
      ->id(),
    'address' => [
      'country_code' => $customer_country,
    ],
  ]);
  if ($tax_number) {
    $customer_profile
      ->set('tax_number', [
      'type' => 'european_union_vat',
      'value' => $tax_number,
      'verification_state' => 'success',
    ]);
  }
  $customer_profile
    ->save();
  $order_item = OrderItem::create([
    'type' => $digital ? 'test_digital' : 'test_physical',
    'quantity' => 1,
    // Intentionally uneven number, to test rounding.
    'unit_price' => new Price('10.33', 'USD'),
  ]);
  $order_item
    ->save();
  $order = Order::create([
    'type' => 'default',
    'uid' => $this->user
      ->id(),
    'store_id' => $store,
    'billing_profile' => $customer_profile,
    'order_items' => [
      $order_item,
    ],
  ]);
  $order
    ->save();
  return $order;
}