protected function EntityReferenceNormalizerTest::setUp in Commerce Cart API 8
Overrides OrderKernelTestBase::setUp
File
- tests/
src/ Kernel/ Normalizer/ EntityReferenceNormalizerTest.php, line 98
Class
- EntityReferenceNormalizerTest
- @group commerce_cart_api
Namespace
Drupal\Tests\commerce_cart_api\Kernel\NormalizerCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_product');
$this
->installEntitySchema('commerce_product_variation');
$this
->installEntitySchema('commerce_product_attribute_value');
EntityFormMode::create([
'id' => 'commerce_order_item.add_to_cart',
'label' => 'Add to cart',
'targetEntityType' => 'commerce_order_item',
])
->save();
$this
->installConfig([
'commerce_product',
'commerce_order',
]);
$color_attribute = ProductAttribute::create([
'id' => 'color',
'label' => 'Color',
]);
$this->container
->get('commerce_product.attribute_field_manager')
->createField($color_attribute, 'default');
$color_blue = ProductAttributeValue::create([
'attribute' => 'color',
'name' => 'Blue',
]);
$color_blue
->save();
/** @var \Drupal\commerce_order\Entity\Order $order */
$order = Order::create([
'type' => 'default',
]);
/** @var \Drupal\commerce_order\Entity\OrderItem $order_item */
$order_item = OrderItem::create([
'type' => 'default',
]);
/** @var \Drupal\commerce_product\Entity\Product $product */
$product = Product::create([
'type' => 'default',
]);
/** @var \Drupal\commerce_product\Entity\ProductVariation $product_variation */
$product_variation = ProductVariation::create([
'type' => 'default',
'attribute_color' => $color_blue
->id(),
]);
$product_variation
->save();
$product
->addVariation($product_variation);
$product
->save();
$order_item
->get('purchased_entity')
->appendItem($product_variation);
$order
->addItem($order_item);
$this->order = $order;
}