You are here

public function ProductVariationStorageTest::testLoadBySku in Commerce Core 8.2

Tests loading variations by SKU.

File

modules/product/tests/src/Kernel/ProductVariationStorageTest.php, line 53

Class

ProductVariationStorageTest
Tests the product variation storage.

Namespace

Drupal\Tests\commerce_product\Kernel

Code

public function testLoadBySku() {
  $sku = strtolower($this
    ->randomMachineName());
  $variation = ProductVariation::create([
    'type' => 'default',
    'sku' => $sku,
    'title' => $this
      ->randomString(),
  ]);
  $variation
    ->save();
  $product = Product::create([
    'type' => 'default',
    'variations' => [
      $variation,
    ],
  ]);
  $product
    ->save();
  $result = $this->variationStorage
    ->loadBySku('FAKE');
  $this
    ->assertNull($result);
  $result = $this->variationStorage
    ->loadBySku($sku);
  $this
    ->assertEquals($result
    ->id(), $variation
    ->id());
}