You are here

public function OrderReportGenerateFormTest::testGenerateAllReports in Commerce Reporting 8

Tests bulk order report processing for all order report types.

File

tests/src/Functional/OrderReportGenerateFormTest.php, line 151

Class

OrderReportGenerateFormTest
Tests the OrderReportGenerateForm.

Namespace

Drupal\Tests\commerce_reports\Functional

Code

public function testGenerateAllReports() {
  $this
    ->assertEquals(self::ORDER_COUNT, count($this->orders));
  $report_count = self::ORDER_COUNT * 2 / 3;
  $this
    ->drupalGet('/admin/commerce/config/reports/generate-reports');

  // Check the integrity of the form and set values.
  $this
    ->assertSession()
    ->fieldExists('plugin_id');
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('plugin_id', '');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Generate');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains("Generated reports for {$report_count} orders.");
  $order_reports = OrderReport::loadMultiple();
  $this
    ->assertEquals(2 * $report_count, count($order_reports), 'Reports created');
  $order_report_count = 0;
  $order_item_report_count = 0;
  foreach ($order_reports as $order_report) {
    if ($order_report
      ->bundle() == 'order_report') {
      $order_report_count++;
    }
    if ($order_report
      ->bundle() == 'order_items_report') {
      $order_item_report_count++;
    }
  }
  $this
    ->assertEquals($report_count, $order_report_count);
  $this
    ->assertEquals($report_count, $order_item_report_count);
}