protected function CartTest::setUp in Commerce Core 8.2
Overrides OrderBrowserTestBase::setUp
File
- modules/
cart/ tests/ src/ Functional/ CartTest.php, line 58
Class
- CartTest
- Tests the cart page.
Namespace
Drupal\Tests\commerce_cart\FunctionalCode
protected function setUp() : void {
parent::setUp();
$this->variations = [
$this->variation,
];
// Create an additional variation in order to test updating multiple
// quantities in cart.
$variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 350,
'currency_code' => 'USD',
],
]);
// Add a test variation that shouldn't be available.
$test_variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => 'TEST_' . strtolower($this
->randomMachineName()),
'price' => [
'number' => 500,
'currency_code' => 'USD',
],
]);
// We need a product too otherwise tests complain about the missing
// backreference.
$this
->createEntity('commerce_product', [
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$variation,
$test_variation,
],
]);
$this->variations[] = $variation;
$this->variations[] = $test_variation;
$this->cart = $this->container
->get('commerce_cart.cart_provider')
->createCart('default');
$this->cartManager = $this->container
->get('commerce_cart.cart_manager');
// Add variations to the cart.
foreach ($this->variations as $variation) {
$this->cartManager
->addEntity($this->cart, $variation, '1', TRUE, FALSE);
}
$this->cart
->setRefreshState(OrderInterface::REFRESH_SKIP);
$this->cart
->save();
}