protected function CommerceReportsCustomerTestCase::_test in Commerce Reporting 7.3
3 calls to CommerceReportsCustomerTestCase::_test()
- CommerceReportsCustomerTestCase::testMultipleCustomers in tests/
commerce_reports.test - Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct.
- CommerceReportsCustomerTestCase::testSingleCustomer in tests/
commerce_reports.test - Tests creating a single order for a single customer, containing a single product with a variable quantity. Then verifies if the reporting is correct.
- CommerceReportsCustomerTestCase::testSingleCustomerMultipleProducts in tests/
commerce_reports.test - Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct.
File
- tests/
commerce_reports.test, line 487 - Unit tests for the commerce reports module.
Class
Code
protected function _test() {
$customers = array();
foreach ($this->orders as $order) {
$uid = $order['commerce_order']->uid;
if (empty($customers[$uid])) {
$customers[$uid] = array(
'orders' => 0,
'products' => 0,
'revenue' => 0,
);
}
$customers[$uid]['orders']++;
foreach ($order['products'] as $product_id => $quantity) {
$customers[$uid]['products'] += $quantity;
$customers[$uid]['revenue'] += $quantity * $this->products[$product_id]->commerce_price['und'][0]['amount'];
}
}
$report = views_get_view_result('commerce_reports_customers', 'default');
$this
->assertEqual(count($report), min(count($customers), 10), t('The amount of customers (%reported) that is reported (%generated) upon is correct.', array(
'%reported' => count($report),
'%generated' => count($customers),
)));
foreach ($report as $line) {
$uid = $line->uid;
$orders = $line->commerce_order_users_order_id;
$revenue = $line->commerce_order_users__field_data_commerce_order_total_commer;
$average = $line->commerce_order_users__field_data_commerce_order_total_commer_2;
$this
->assertFalse(empty($customers[$uid]), t('The customer %uid that is reported upon exists.', array(
'%uid' => $uid,
)));
if (!empty($customers[$uid])) {
$this
->assertEqual($customers[$uid]['orders'], $orders, t('The reported amount of orders %reported matches the generated amount of orders %generated.', array(
'%reported' => $orders,
'%generated' => $customers[$uid]['orders'],
)));
// $this->assertEqual($customers[$uid]['products'], $products, t('The reported amount of line items %reported matches the generated amount of line items %generated.', array('%reported' => $products, '%generated' => $customers[$uid]['products'])));
$this
->assertEqual($customers[$uid]['revenue'], $revenue, t('The reported revenue %reported matches the generated revenue %generated.', array(
'%reported' => $revenue,
'%generated' => $customers[$uid]['revenue'],
)));
}
}
}