You are here

class CommerceReportsSalesTestCase in Commerce Reporting 7.4

Hierarchy

Expanded class hierarchy of CommerceReportsSalesTestCase

File

src/Tests/CommerceReportsSalesTestCase.php, line 5

Namespace

Drupal\commerce_reports\Tests
View source
class CommerceReportsSalesTestCase extends CommerceReportsBaseTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Sales reports',
      'description' => 'Test the sales reports.',
      'group' => 'Commerce Reports',
    );
  }
  public function testNoOrders() {
    $this
      ->_getDates();
    $this
      ->_test();
  }
  public function testSingleOrder() {
    $this
      ->createOrders(1, FALSE, $this
      ->_getDates());
    $this
      ->_test();
  }
  public function testMultipleOrders() {
    $this
      ->createCustomers(5);
    $this
      ->createOrders(20, FALSE, $this
      ->_getDates());
    $this
      ->_test();
  }
  protected function _getDates() {
    $report = views_get_view_result('commerce_reports_sales', 'page');
    $possibleDates = array();
    foreach ($report as $line) {
      $possibleDates[] = $this
        ->getOrderCreated($line);
    }
    return $possibleDates;
  }
  protected function getOrderCreated($line) {
    return $line->_field_data['order_id_1']['entity']->created;
  }
  protected function _test() {
    $sales = array();
    foreach ($this->orders as $order) {
      $created = $order['commerce_order']->created;
      if (empty($sales[$created])) {
        $sales[$created] = array(
          'orders' => 0,
          'revenue' => 0,
        );
      }
      $sales[$created]['orders']++;
      foreach ($order['products'] as $product_id => $quantity) {
        $sales[$created]['revenue'] += $quantity * $this->products[$product_id]->commerce_price[LANGUAGE_NONE][0]['amount'];
      }
    }
    $report = views_get_view_result('commerce_reports_sales', 'page');
    foreach ($report as $line) {
      $created = $this
        ->getOrderCreated($line);
      if (empty($sales[$created])) {
        $this
          ->assertTrue(empty($line->order_id) && empty($line->commerce_order_total) && empty($line->commerce_order_total_1), t('There was no unintented activity.'));
      }
      else {
        $orders = $sales[$created]['orders'];
        $revenue = $sales[$created]['revenue'];
        $average = (int) floor($revenue / $orders);
        $this
          ->assertEqual($line->order_id, $orders, t('The right amount of orders was reported.'));
        $this
          ->assertEqual($line->field_data_commerce_order_total_commerce_order_total_amount, $revenue, t('The right amount of revenue was reported.'));
        $this
          ->assertEqual((int) floor($line->field_data_commerce_order_total_commerce_order_total_amount_1), $average, t('The right average of revenue was reported.'));
      }
    }
  }

}

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
CommerceReportsSalesTestCase::getInfo public static function
CommerceReportsSalesTestCase::getOrderCreated protected function
CommerceReportsSalesTestCase::testMultipleOrders public function
CommerceReportsSalesTestCase::testNoOrders public function
CommerceReportsSalesTestCase::testSingleOrder public function
CommerceReportsSalesTestCase::_getDates protected function
CommerceReportsSalesTestCase::_test protected function