You are here

public function PriceListRepositoryTest::testVariation in Commerce Pricelist 8.2

Tests variation-based loading.

@covers ::loadItem @covers ::loadItems

File

tests/src/Kernel/PriceListRepositoryTest.php, line 84

Class

PriceListRepositoryTest
Tests the price list repository.

Namespace

Drupal\Tests\commerce_pricelist\Kernel

Code

public function testVariation() {
  $repository = $this->container
    ->get('commerce_pricelist.repository');
  $other_variation = ProductVariation::create([
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'title' => $this
      ->randomString(),
    'price' => new Price('8.00', 'USD'),
  ]);
  $other_variation
    ->save();
  $context = new Context($this->user, $this->store);
  $price_list_item = $repository
    ->loadItem($this->variation, 1, $context);
  $this
    ->assertEquals(new Price('5.00', 'USD'), $price_list_item
    ->getPrice());
  $this
    ->assertEquals(new Price('7.70', 'USD'), $price_list_item
    ->getListPrice());
  $price_list_item = $repository
    ->loadItem($other_variation, 1, $context);
  $this
    ->assertEmpty($price_list_item);
}