public function PromotionAvailabilityTest::testAvailability in Commerce Core 8.2
Test general availability.
File
- modules/
promotion/ tests/ src/ Kernel/ PromotionAvailabilityTest.php, line 72
Class
- PromotionAvailabilityTest
- Tests the promotion availability logic.
Namespace
Drupal\Tests\commerce_promotion\KernelCode
public function testAvailability() {
$promotion = Promotion::create([
'order_types' => [
'default',
],
'stores' => [
$this->store
->id(),
],
'usage_limit' => 2,
'usage_limit_customer' => 0,
'start_date' => '2019-01-01T00:00:00',
'status' => TRUE,
]);
$promotion
->save();
$this
->assertTrue($promotion
->available($this->order));
$promotion
->setEnabled(FALSE);
$this
->assertFalse($promotion
->available($this->order));
$promotion
->setEnabled(TRUE);
$promotion
->setOrderTypeIds([
'test',
]);
$this
->assertFalse($promotion
->available($this->order));
$promotion
->setOrderTypeIds([
'default',
]);
$promotion
->setStoreIds([
'90',
]);
$this
->assertFalse($promotion
->available($this->order));
$promotion
->setStoreIds([
$this->store
->id(),
]);
}