You are here

protected function ProductCacheTest::setUp in Commerce Pricelist 8.2

Overrides CommerceBrowserTestBase::setUp

File

tests/src/Functional/ProductCacheTest.php, line 61

Class

ProductCacheTest
Tests the interaction between price lists and product caches.

Namespace

Drupal\Tests\commerce_pricelist\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Turn off title generation to allow explicit values to be used.
  $variation_type = ProductVariationType::load('default');
  $variation_type
    ->setGenerateTitle(FALSE);
  $variation_type
    ->save();
  $this->priceList = $this
    ->createEntity('commerce_pricelist', [
    'type' => 'commerce_product_variation',
    'name' => $this
      ->randomMachineName(8),
    'start_date' => '2018-07-07',
    'stores' => [
      $this->store,
    ],
  ]);
  $this->variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => 'RED-SHIRT',
    'title' => 'Red shirt',
    'price' => new Price('12.00', 'USD'),
  ]);
  $this->product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => $this
      ->randomMachineName(),
    'stores' => [
      $this->store,
    ],
    'variations' => [
      $this->variation,
    ],
  ]);
  $this
    ->reloadEntity($this->variation);
  $this->variation
    ->save();

  // Use the "calculated" price display for the product, since this will give
  // us the resolved price including the price list.
  $variation_display = commerce_get_entity_display('commerce_product_variation', 'default', 'view');
  $variation_display
    ->setComponent('price', [
    'label' => 'above',
    'type' => 'commerce_price_calculated',
    'settings' => [],
  ]);
  $variation_display
    ->save();
}