public function BuyXGetYTest::testNotApplicable in Commerce Core 8.2
Tests the non-applicable use cases.
@covers ::apply
File
- modules/
promotion/ tests/ src/ Kernel/ Plugin/ Commerce/ PromotionOffer/ BuyXGetYTest.php, line 170
Class
- BuyXGetYTest
- Tests the "Buy X Get Y" offer.
Namespace
Drupal\Tests\commerce_promotion\Kernel\Plugin\Commerce\PromotionOfferCode
public function testNotApplicable() {
/** @var \Drupal\commerce_order\OrderItemStorageInterface $order_item_storage */
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '2',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[1], [
'quantity' => '4',
]);
$second_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
]);
$this->order
->save();
// Insufficient purchase quantity.
// Only the first order item is counted (due to the product type condition),
// and its quantity is too small (2 < 6).
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertEmpty($this->order
->collectAdjustments());
// Sufficient purchase quantity, but no offer order item found.
$first_order_item
->setQuantity(6);
$first_order_item
->save();
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertEmpty($this->order
->collectAdjustments());
}