You are here

function CommerceReportsViewsExportTestCase::testSalesViewsDataExport in Commerce Reporting 7.4

File

src/Tests/CommerceReportsViewsExportTestCase.php, line 83

Class

CommerceReportsViewsExportTestCase
Class CommerceReportsViewsExportTestCase

Namespace

Drupal\commerce_reports\Tests

Code

function testSalesViewsDataExport() {
  $this
    ->createCustomers(5);
  $this
    ->createOrders(20, FALSE, $this
    ->sampleDates());

  // Monthly
  $rendered = $this
    ->getRenderedExport('commerce_reports_sales');
  $this
    ->assertCsvHeaders('"Created date","Number of Orders","Total Revenue","Average Order"', $rendered[0]);
  $months = $this
    ->ordersGroupedByTime('F Y');
  array_shift($rendered);
  $this
    ->assertEqual(count($rendered), count($months), t('The amount of months (%reported) that is reported (%generated) upon is correct.', array(
    '%reported' => count($rendered),
    '%generated' => count($months),
  )));

  // Weekly
  $rendered = $this
    ->getRenderedExport('commerce_reports_sales', 'views_data_export_3');
  $this
    ->assertCsvHeaders('"Created date","Number of Orders","Total Revenue","Average Order"', $rendered[0]);
  $months = $this
    ->ordersGroupedByTime('\\w\\e\\e\\k W \\o\\f Y');
  array_shift($rendered);
  $this
    ->assertEqual(count($rendered), count($months), t('The amount of weeks (%reported) that is reported (%generated) upon is correct.', array(
    '%reported' => count($rendered),
    '%generated' => count($months),
  )));

  // Daily
  $rendered = $this
    ->getRenderedExport('commerce_reports_sales', 'views_data_export_4');
  $this
    ->assertCsvHeaders('"Created date","Number of Orders","Total Revenue","Average Order"', $rendered[0]);
  $months = $this
    ->ordersGroupedByTime('j F Y');
  array_shift($rendered);
  $this
    ->assertEqual(count($rendered), count($months), t('The amount of days (%reported) that is reported (%generated) upon is correct.', array(
    '%reported' => count($rendered),
    '%generated' => count($months),
  )));

  // Yearly
  $rendered = $this
    ->getRenderedExport('commerce_reports_sales', 'views_data_export_2');
  $this
    ->assertCsvHeaders('"Created date","Number of Orders","Total Revenue","Average Order"', $rendered[0]);
  $months = $this
    ->ordersGroupedByTime('Y');
  array_shift($rendered);
  $this
    ->assertEqual(count($rendered), count($months), t('The amount of years (%reported) that is reported (%generated) upon is correct.', array(
    '%reported' => count($rendered),
    '%generated' => count($months),
  )));
}