You are here

protected function AlterProductPurchasedEntityEventTest::setUp in Commerce Google Tag Manager 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/AlterProductPurchasedEntityEventTest.php \Drupal\Tests\commerce_google_tag_manager\Kernel\AlterProductPurchasedEntityEventTest::setUp()

Overrides CommerceKernelTestBase::setUp

File

tests/src/Kernel/AlterProductPurchasedEntityEventTest.php, line 56

Class

AlterProductPurchasedEntityEventTest
@coversDefaultClass \Drupal\commerce_google_tag_manager\Event\AlterProductPurchasedEntityEvent

Namespace

Drupal\Tests\commerce_google_tag_manager\Kernel

Code

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

  // The purchased entity to test with.
  $this->purchasedEntity = ProductVariation::create([
    'type' => 'default',
    'sku' => $this
      ->randomString(10),
    'status' => TRUE,
  ]);
  $this->purchasedEntity
    ->save();
  $order_item_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_order_item');
  $this->orderItem = $order_item_storage
    ->createFromPurchasableEntity($this->purchasedEntity, [
    'quantity' => 1,
  ]);
  $this->product = new Product();
  $this->product
    ->setName($this
    ->randomString(16))
    ->setId(1)
    ->setVariant($this->purchasedEntity
    ->getTitle())
    ->setPrice('11.99');
}