You are here

protected function ProductVariationFieldRendererTest::setUp in Commerce Core 8.2

Overrides CommerceKernelTestBase::setUp

File

modules/product/tests/src/Kernel/ProductVariationFieldRendererTest.php, line 62

Class

ProductVariationFieldRendererTest
Tests the product variation field renderer.

Namespace

Drupal\Tests\commerce_product\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('commerce_product_variation');
  $this
    ->installEntitySchema('commerce_product');
  $this
    ->installEntitySchema('commerce_product_attribute_value');
  $this
    ->installConfig([
    'commerce_product',
  ]);
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();

  // We must have two languages installed. Otherwise it is not considered
  // multilingual because `en` is not installed as a configurable language.
  // @see \Drupal\language\ConfigurableLanguageManager::isMultilingual
  ConfigurableLanguage::createFromLangcode('de')
    ->save();
  $this->variationFieldRenderer = $this->container
    ->get('commerce_product.variation_field_renderer');
  $this->firstVariationType = ProductVariationType::create([
    'id' => 'shirt',
    'label' => 'Shirt',
  ]);
  $this->firstVariationType
    ->save();
  $this->secondVariationType = ProductVariationType::create([
    'id' => 'mug',
    'label' => 'Mug',
  ]);
  $this->secondVariationType
    ->save();
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'render_field',
    'entity_type' => 'commerce_product_variation',
    'type' => 'text',
    'cardinality' => 1,
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $this->secondVariationType
      ->id(),
    'label' => 'Render field',
    'required' => TRUE,
    'translatable' => FALSE,
  ]);
  $field
    ->save();
  $attribute = ProductAttribute::create([
    'id' => 'color',
    'label' => 'Color',
  ]);
  $attribute
    ->save();
  $this->container
    ->get('commerce_product.attribute_field_manager')
    ->createField($attribute, $this->secondVariationType
    ->id());
  $user = $this
    ->createUser([], [
    'administer commerce_product',
  ]);
  $this->container
    ->get('current_user')
    ->setAccount($user);
}