You are here

protected function PriceCalculatorTest::setUp in Commerce Core 8.2

Overrides OrderKernelTestBase::setUp

File

modules/order/tests/src/Kernel/PriceCalculatorTest.php, line 70

Class

PriceCalculatorTest
Tests the price calculator.

Namespace

Drupal\Tests\commerce_order\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('commerce_promotion');
  $this
    ->installSchema('commerce_promotion', [
    'commerce_promotion_usage',
  ]);
  $promotion = Promotion::create([
    'name' => 'Promotion 1',
    'order_types' => [
      'default',
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'status' => TRUE,
    'offer' => [
      'target_plugin_id' => 'order_item_percentage_off',
      'target_plugin_configuration' => [
        'percentage' => '0.5',
      ],
    ],
  ]);
  $promotion
    ->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',
          'percentage' => '0.2',
        ],
      ],
      'territories' => [
        [
          'country_code' => 'US',
          'administrative_area' => 'WI',
        ],
        [
          'country_code' => 'US',
          'administrative_area' => 'SC',
        ],
      ],
    ],
  ])
    ->save();
  $first_variation = ProductVariation::create([
    'type' => 'default',
    'sku' => 'TEST_CALCULATED_PRICE',
    'status' => 1,
    'price' => new Price('3.00', 'USD'),
  ]);
  $first_variation
    ->save();
  $second_variation = ProductVariation::create([
    'type' => 'default',
    'sku' => 'TEST_CALCULATED_PRICE2',
    'status' => 1,
    'price' => new Price('4.00', 'USD'),
  ]);
  $second_variation
    ->save();
  $product = Product::create([
    'type' => 'default',
    'title' => 'Default testing product',
    'stores' => [
      $this->store
        ->id(),
    ],
    'variations' => [
      $first_variation,
      $second_variation,
    ],
  ]);
  $product
    ->save();
  $this->firstVariation = $this
    ->reloadEntity($first_variation);
  $this->secondVariation = $this
    ->reloadEntity($second_variation);
  $this->firstUser = $this
    ->createUser([
    'mail' => 'user1@example.com',
  ]);
  $this->secondUser = $this
    ->createUser([
    'mail' => 'user2@example.com',
  ]);
  $this->priceCalculator = $this->container
    ->get('commerce_order.price_calculator');
}