public function PromotionAvailabilityTest::testEndDate in Commerce Core 8.2
Tests the end date logic.
File
- modules/
promotion/ tests/ src/ Kernel/ PromotionAvailabilityTest.php, line 129
Class
- PromotionAvailabilityTest
- Tests the promotion availability logic.
Namespace
Drupal\Tests\commerce_promotion\KernelCode
public function testEndDate() {
// No end date date.
$promotion = Promotion::create([
'order_types' => [
'default',
],
'stores' => [
$this->store
->id(),
],
'usage_limit' => 1,
'usage_limit_customer' => 0,
'start_date' => '2019-01-01T00:00:00',
'status' => TRUE,
]);
$promotion
->save();
$this
->assertTrue($promotion
->available($this->order));
// End date equal to the order placed date.
$date = new DrupalDateTime('2019-11-15 10:14:00');
$promotion
->setEndDate($date);
$this
->assertFalse($promotion
->available($this->order));
// Past end date.
$date = new DrupalDateTime('2017-01-01 00:00:00');
$promotion
->setEndDate($date);
$this
->assertFalse($promotion
->available($this->order));
// Future end date.
$date = new DrupalDateTime('2019-11-20 10:14:00');
$promotion
->setEndDate($date);
$this
->assertTrue($promotion
->available($this->order));
}