class CommerceReportsCustomerTestCase in Commerce Reporting 7.4
Hierarchy
- class \Drupal\commerce_reports\Tests\CommerceReportsBaseTestCase extends \Drupal\commerce_reports\Tests\CommerceBaseTestCase
- class \Drupal\commerce_reports\Tests\CommerceReportsCustomerTestCase
Expanded class hierarchy of CommerceReportsCustomerTestCase
File
- src/
Tests/ CommerceReportsCustomerTestCase.php, line 5
Namespace
Drupal\commerce_reports\TestsView source
class CommerceReportsCustomerTestCase extends CommerceReportsBaseTestCase {
public static function getInfo() {
return array(
'name' => 'Customer reports',
'description' => 'Test the customer reports.',
'group' => 'Commerce Reports',
);
}
function setUp() {
$this
->resetAll();
parent::setUp();
}
/**
* Tests creating a single order for a single customer, containing a single product with a variable quantity.
* Then verifies if the reporting is correct.
*/
function testSingleCustomer() {
$this
->createOrders();
$this
->_test();
}
/**
* Make one customer perform multiple orders with multiple products.
* Then verifies if the reporting is correct.
*/
function testSingleCustomerMultipleProducts() {
$this
->createProducts(5);
$this
->createOrders();
$this
->_test();
}
/**
* Make one customer perform multiple orders with multiple products.
* Then verifies if the reporting is correct.
*/
function testMultipleCustomers() {
$this
->createCustomers(3);
$this
->createProducts(2);
$this
->createOrders(10);
$this
->_test();
}
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[LANGUAGE_NONE][0]['amount'];
}
}
$report = views_get_view_result('commerce_reports_customers', 'page');
$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'],
)));
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceReportsBaseTestCase:: |
protected | property | ||
CommerceReportsBaseTestCase:: |
protected | property | ||
CommerceReportsBaseTestCase:: |
protected | property | ||
CommerceReportsBaseTestCase:: |
protected | property | ||
CommerceReportsBaseTestCase:: |
protected | property | Don't need most of default core modules. | |
CommerceReportsBaseTestCase:: |
protected | property | ||
CommerceReportsBaseTestCase:: |
protected | function | Helper function creating multiple dummy customers. | |
CommerceReportsBaseTestCase:: |
protected | function | Returns information about created customers for tests. | |
CommerceReportsBaseTestCase:: |
protected | function | Returns information about created products for tests. | |
CommerceReportsBaseTestCase:: |
protected | function | Helper function creating multiple dummy orders. If no customers or products exist, then one of each get created. | |
CommerceReportsBaseTestCase:: |
protected | function | Helper function creating multiple dummy products with a variable price. | |
CommerceReportsBaseTestCase:: |
protected | function | ||
CommerceReportsBaseTestCase:: |
protected | function | Return a an executed View. | |
CommerceReportsBaseTestCase:: |
protected | function | Overrides CommerceBaseTestCase::permissionBuilder(). | |
CommerceReportsCustomerTestCase:: |
public static | function | ||
CommerceReportsCustomerTestCase:: |
function |
Overrides DrupalWebTestCase::setUp(). Overrides CommerceReportsBaseTestCase:: |
||
CommerceReportsCustomerTestCase:: |
function | Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct. | ||
CommerceReportsCustomerTestCase:: |
function | 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:: |
function | Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct. | ||
CommerceReportsCustomerTestCase:: |
protected | function |