public function PromotionReportTest::testNoPromotions in Commerce Reporting 8
Tests order report entity creation for orders without promotions.
File
- tests/
src/ Kernel/ ReportType/ PromotionReportTest.php, line 126
Class
- PromotionReportTest
- Tests the `commerce_order_report` entity.
Namespace
Drupal\Tests\commerce_reports\Kernel\ReportTypeCode
public function testNoPromotions() {
/** @var \Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeInterface $report_type_plugin */
$report_type_plugin = $this->reportTypeManager
->createInstance('promotion_report');
$order_item1 = OrderItem::create([
'title' => 'Product 1',
'type' => 'test',
'unit_price' => new Price('12.00', 'USD'),
'quantity' => 2,
]);
$order_item1
->save();
$this->order
->addItem($order_item1);
$order_item2 = OrderItem::create([
'title' => 'Product 2',
'type' => 'test',
'unit_price' => new Price('30.00', 'USD'),
'quantity' => 4,
]);
$order_item2
->save();
$this->order
->addItem($order_item2);
$this->order
->save();
$this
->assertEquals(2, count($this->order
->getItems()));
// Testing order without adjustments
$report_type_plugin
->generateReports($this->order);
/** @var \Drupal\commerce_reports\Entity\OrderReport[] $order_reports */
$order_reports = OrderReport::loadMultiple();
$this
->assertEquals(0, count($order_reports));
// Add non-promotion adjustments.
$adjustments = [];
$adjustments[] = new Adjustment([
'type' => 'custom',
'label' => '10% off',
'amount' => new Price('-3.00', 'USD'),
'percentage' => '0.1',
]);
$adjustments[] = new Adjustment([
'type' => 'custom',
'label' => 'Random fee',
'amount' => new Price('2.00', 'USD'),
]);
$order_item2
->setAdjustments($adjustments);
$order_item2
->save();
$report_type_plugin
->generateReports($this->order);
/** @var \Drupal\commerce_reports\Entity\OrderReport[] $order_reports */
$order_reports = OrderReport::loadMultiple();
$this
->assertEquals(0, count($order_reports));
}