public function PromotionTest::testCreatePromotionWithEndDate in Commerce Core 8.2
Tests creating a promotion with an end date.
File
- modules/
promotion/ tests/ src/ FunctionalJavascript/ PromotionTest.php, line 241
Class
- PromotionTest
- Tests the admin UI for promotions.
Namespace
Drupal\Tests\commerce_promotion\FunctionalJavascriptCode
public function testCreatePromotionWithEndDate() {
$this
->drupalGet('admin/commerce/promotions');
$this
->getSession()
->getPage()
->clickLink('Add promotion');
$this
->drupalGet('promotion/add');
$this
->assertSession()
->fieldExists('name[0][value]');
$this
->getSession()
->getPage()
->fillField('offer[0][target_plugin_id]', 'order_percentage_off');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$end_date = new DrupalDateTime('now', 'UTC');
$end_date = $end_date
->modify('+1 month');
$name = $this
->randomMachineName(8);
$this
->getSession()
->getPage()
->checkField('end_date[0][has_value]');
$this
->setRawFieldValue('end_date[0][container][value][date]', $end_date
->format('Y-m-d'));
$this
->setRawFieldValue('end_date[0][container][value][time]', $end_date
->format('H:i:s'));
$edit = [
'name[0][value]' => $name,
'offer[0][target_plugin_configuration][order_percentage_off][percentage]' => '10.0',
];
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->pageTextContains("Saved the {$name} promotion.");
$rows = $this
->getSession()
->getPage()
->findAll('xpath', '//table/tbody/tr/td[text()="' . $name . '"]');
$this
->assertCount(1, $rows);
/** @var \Drupal\commerce_promotion\Entity\PromotionInterface $promotion */
$promotion = Promotion::load(1);
$offer = $promotion
->getOffer();
$this
->assertEquals('0.10', $offer
->getConfiguration()['percentage']);
$storage_format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
$this
->assertEquals($end_date
->format($storage_format), $promotion
->getEndDate()
->format($storage_format));
}