public function PromotionCompatibilityTest::testCompatibility in Commerce Core 8.2
Tests the compatibility setting.
File
- modules/
promotion/ tests/ src/ Kernel/ PromotionCompatibilityTest.php, line 71
Class
- PromotionCompatibilityTest
- Tests promotion compatibility options.
Namespace
Drupal\Tests\commerce_promotion\KernelCode
public function testCompatibility() {
$order_type = OrderType::load('default');
// Starts now, enabled. No end time.
$promotion1 = Promotion::create([
'name' => 'Promotion 1',
'order_types' => [
$order_type,
],
'stores' => [
$this->store
->id(),
],
'status' => TRUE,
'offer' => [
'target_plugin_id' => 'order_percentage_off',
'target_plugin_configuration' => [
'percentage' => '0.10',
],
],
]);
$this
->assertEquals(SAVED_NEW, $promotion1
->save());
$promotion2 = Promotion::create([
'name' => 'Promotion 2',
'order_types' => [
$order_type,
],
'stores' => [
$this->store
->id(),
],
'status' => TRUE,
'offer' => [
'target_plugin_id' => 'order_percentage_off',
'target_plugin_configuration' => [
'percentage' => '0.10',
],
],
]);
$this
->assertEquals(SAVED_NEW, $promotion2
->save());
$this
->assertTrue($promotion1
->applies($this->order));
$this
->assertTrue($promotion2
->applies($this->order));
$promotion1
->setWeight(-10);
$promotion1
->save();
$promotion2
->setWeight(10);
$promotion2
->setCompatibility(PromotionInterface::COMPATIBLE_NONE);
$promotion2
->save();
$promotion1
->apply($this->order);
$this
->assertFalse($promotion2
->applies($this->order));
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertEquals(1, count($this->order
->collectAdjustments()));
}