You are here

protected function ProductVariationFieldInjectionTest::setUp in Commerce Core 8.2

Overrides ProductBrowserTestBase::setUp

File

modules/product/tests/src/Functional/ProductVariationFieldInjectionTest.php, line 22

Class

ProductVariationFieldInjectionTest
Tests the product variation field display injection.

Namespace

Drupal\Tests\commerce_product\Functional

Code

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

  // Create an attribute, so we can test it displays, too.
  $attribute = $this
    ->createEntity('commerce_product_attribute', [
    'id' => 'color',
    'label' => 'Color',
  ]);
  $attribute
    ->save();
  $this->container
    ->get('commerce_product.attribute_field_manager')
    ->createField($attribute, 'default');
  $attribute_values = [];
  foreach ([
    'Cyan',
    'Magenta',
    'Yellow',
    'Black',
  ] as $color_attribute_value) {
    $attribute_values[strtolower($color_attribute_value)] = $this
      ->createEntity('commerce_product_attribute_value', [
      'attribute' => $attribute
        ->id(),
      'name' => $color_attribute_value,
    ]);
  }
  $this->product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => $this
      ->randomMachineName(),
    'stores' => $this->stores,
    'body' => [
      'value' => 'Testing product variation field injection!',
    ],
    'variations' => [
      $this
        ->createEntity('commerce_product_variation', [
        'type' => 'default',
        'sku' => 'INJECTION-CYAN',
        'attribute_color' => $attribute_values['cyan']
          ->id(),
        'price' => [
          'number' => 999,
          'currency_code' => 'USD',
        ],
      ]),
      $this
        ->createEntity('commerce_product_variation', [
        'type' => 'default',
        'sku' => 'INJECTION-MAGENTA',
        'attribute_color' => $attribute_values['magenta']
          ->id(),
        'price' => [
          'number' => 999,
          'currency_code' => 'USD',
        ],
      ]),
    ],
  ]);
}