You are here

class CommerceReportsSalesOverviewTestCase in Commerce Reporting 7.4

Hierarchy

Expanded class hierarchy of CommerceReportsSalesOverviewTestCase

File

src/Tests/CommerceReportsSalesOverviewTestCase.php, line 5

Namespace

Drupal\commerce_reports\Tests
View source
class CommerceReportsSalesOverviewTestCase extends CommerceReportsBaseTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Sales overview reports',
      'description' => 'Test the sales overview reports.',
      'group' => 'Commerce Reports',
    );
  }
  protected function _test($data = array()) {
    foreach ($data as $display => $information) {
      $report = views_get_view_result('commerce_reports_sales_overview', $display);
      $line = reset($report);
      foreach ($information as &$metric) {
        if (empty($metric)) {
          $metric = NULL;
        }
      }
      if (empty($line->field_data_commerce_order_total_commerce_order_total_amount)) {
        $amount = 0;
      }
      else {
        $amount = $line->field_data_commerce_order_total_commerce_order_total_amount;
      }
      if (empty($line->order_id)) {
        $sales = NULL;
      }
      else {
        $sales = $line->order_id;
      }
      $this
        ->assertEqual($information['count'], $sales, t('The expected amount of orders is equal to the derived amount of orders.'));
      $this
        ->assertEqual($information['amount'], $amount, t('The expected total amount is equal to the derived total amount.'));
    }
  }
  public function testTodayOverview() {
    $this
      ->createCustomers(2);
    $this
      ->createOrders(10, TRUE, array(
      time(),
    ));
    $total = $this
      ->getTotal();
    $testData = array(
      'today' => array(
        'count' => 10,
        'amount' => $total,
      ),
      'yesterday' => array(
        'count' => 0,
        'amount' => 0,
      ),
      'month' => array(
        'count' => 10,
        'amount' => $total,
      ),
    );
    $this
      ->_test($testData);
  }
  public function testYesterdayOverview() {
    $this
      ->createCustomers(2);
    $this
      ->createOrders(10, TRUE, array(
      time() - 86400,
    ));
    $total = $this
      ->getTotal();
    $testData = array(
      'today' => array(
        'count' => 0,
        'amount' => 0,
      ),
      'yesterday' => array(
        'count' => 10,
        'amount' => $total,
      ),
      'month' => array(
        'count' => 10,
        'amount' => $total,
      ),
    );
    $this
      ->_test($testData);
  }
  public function testMonthlyOverview() {
    $this
      ->createCustomers(2);
    $this
      ->createOrders(10, TRUE, array(
      time() - 3 * 86400,
      time() - 5 * 86400,
      time() - 15 * 86400,
      time() - 20 * 86400,
      time() - 30 * 86400,
    ));
    $total = $this
      ->getTotal();
    $testData = array(
      'today' => array(
        'count' => 0,
        'amount' => 0,
      ),
      'yesterday' => array(
        'count' => 0,
        'amount' => 0,
      ),
      'month' => array(
        'count' => 10,
        'amount' => $total,
      ),
    );
    $this
      ->_test($testData);
  }
  public function testOutsideOverviewScope() {
    $this
      ->createCustomers(2);
    $this
      ->createOrders(10, TRUE, array(
      time() - 31 * 86400,
    ));
    $total = $this
      ->getTotal();
    $testData = array(
      'today' => array(
        'count' => 0,
        'amount' => 0,
      ),
      'yesterday' => array(
        'count' => 0,
        'amount' => 0,
      ),
      'month' => array(
        'count' => 0,
        'amount' => 0,
      ),
    );
    $this
      ->_test($testData);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceReportsBaseTestCase::$additional_modules protected property
CommerceReportsBaseTestCase::$customers protected property
CommerceReportsBaseTestCase::$orders protected property
CommerceReportsBaseTestCase::$products protected property
CommerceReportsBaseTestCase::$profile protected property Don't need most of default core modules.
CommerceReportsBaseTestCase::$store_admin protected property
CommerceReportsBaseTestCase::createCustomers protected function Helper function creating multiple dummy customers.
CommerceReportsBaseTestCase::createdCustomersData protected function Returns information about created customers for tests.
CommerceReportsBaseTestCase::createdProductsData protected function Returns information about created products for tests.
CommerceReportsBaseTestCase::createOrders protected function Helper function creating multiple dummy orders. If no customers or products exist, then one of each get created.
CommerceReportsBaseTestCase::createProducts protected function Helper function creating multiple dummy products with a variable price.
CommerceReportsBaseTestCase::getTotal protected function
CommerceReportsBaseTestCase::getView protected function Return a an executed View.
CommerceReportsBaseTestCase::permissionBuilder protected function Overrides CommerceBaseTestCase::permissionBuilder().
CommerceReportsBaseTestCase::setUp function Overrides DrupalWebTestCase::setUp(). 3
CommerceReportsSalesOverviewTestCase::getInfo public static function
CommerceReportsSalesOverviewTestCase::testMonthlyOverview public function
CommerceReportsSalesOverviewTestCase::testOutsideOverviewScope public function
CommerceReportsSalesOverviewTestCase::testTodayOverview public function
CommerceReportsSalesOverviewTestCase::testYesterdayOverview public function
CommerceReportsSalesOverviewTestCase::_test protected function