public function PromotionTest::testEditPromotion in Commerce Core 8.2
Tests editing a promotion.
File
- modules/
promotion/ tests/ src/ FunctionalJavascript/ PromotionTest.php, line 298
Class
- PromotionTest
- Tests the admin UI for promotions.
Namespace
Drupal\Tests\commerce_promotion\FunctionalJavascriptCode
public function testEditPromotion() {
$promotion = $this
->createEntity('commerce_promotion', [
'name' => '10% off',
'status' => TRUE,
'offer' => [
'target_plugin_id' => 'order_item_percentage_off',
'target_plugin_configuration' => [
'percentage' => '0.10',
],
],
'conditions' => [
[
'target_plugin_id' => 'order_total_price',
'target_plugin_configuration' => [
'amount' => [
'number' => '9.10',
'currency_code' => 'USD',
],
],
],
],
'start_date' => '2019-10-07T13:37:00',
]);
/** @var \Drupal\commerce\Plugin\Field\FieldType\PluginItem $offer_field */
$offer_field = $promotion
->get('offer')
->first();
$this
->assertEquals('0.10', $offer_field->target_plugin_configuration['percentage']);
$this
->drupalGet($promotion
->toUrl('edit-form'));
$this
->assertSession()
->pageTextContains('Restricted');
$this
->assertSession()
->checkboxChecked('Current order total');
$this
->assertSession()
->fieldValueEquals('conditions[form][order][order_total_price][configuration][form][amount][number]', '9.10');
$this
->setRawFieldValue('start_date[0][value][time]', '14:15:13');
$edit = [
'name[0][value]' => '20% off',
'offer[0][target_plugin_configuration][order_item_percentage_off][percentage]' => '20',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Saved the 20% off promotion.');
/** @var \Drupal\commerce_promotion\Entity\PromotionInterface $promotion */
$promotion = $this
->reloadEntity($promotion);
$this
->assertEquals('20% off', $promotion
->getName());
$offer = $promotion
->getOffer();
$this
->assertEquals('0.20', $offer
->getConfiguration()['percentage']);
$this
->assertEquals('2019-10-07 14:15:13', $promotion
->getStartDate()
->format('Y-m-d H:i:s'));
}