You are here

class CommerceReportsProductTestCase in Commerce Reporting 7.4

Hierarchy

Expanded class hierarchy of CommerceReportsProductTestCase

File

src/Tests/CommerceReportsProductTestCase.php, line 5

Namespace

Drupal\commerce_reports\Tests
View source
class CommerceReportsProductTestCase extends CommerceReportsBaseTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Product reports',
      'description' => 'Test the product reports.',
      'group' => 'Commerce Reports',
    );
  }
  function setUp() {
    $this
      ->resetAll();
    parent::setUp();
  }

  /**
   * Tests creating a single order, containing a single product with a variable quantity.
   * Then verifies if the reporting is correct.
   */
  function testSingleProduct() {
    $this
      ->createOrders();
    $this
      ->_test();
  }

  /**
   * Tests creating a single order, containing multiple products with a variable quantity.
   * Then verifies if the reporting is correct.
   */
  function testMultipleProducts() {
    $this
      ->createProducts(10);
    $this
      ->createOrders();
    $this
      ->_test();
  }

  /**
   * Tests creating a multiple orders, containing multiple products with a variable quantity.
   * Then verifies if the reporting is correct.
   */
  function testMultipleOrdersProducts() {
    $this
      ->createProducts(5);
    $this
      ->createOrders(5);
    $this
      ->_test();
  }
  protected function _test() {
    $products = array();
    foreach ($this->orders as $order) {
      foreach ($order['products'] as $product_id => $quantity) {
        $sku = $this->products[$product_id]->sku;
        if (empty($products[$sku])) {
          $products[$sku] = array(
            'quantity' => 0,
            'revenue' => 0,
          );
        }
        $products[$sku]['quantity'] += $quantity;
        $products[$sku]['revenue'] += $quantity * $this->products[$product_id]->commerce_price[LANGUAGE_NONE][0]['amount'];
      }
    }
    $report = views_get_view_result('commerce_reports_products', 'default');
    $this
      ->assertEqual(count($report), min(count($products), 10), t('The amount of products (%reported) that is reported (%generated) upon is correct.', array(
      '%reported' => count($report),
      '%generated' => count($products),
    )));
    foreach ($report as $line) {
      $sku = $line->commerce_product_field_data_commerce_product_sku;
      $quantity = $line->commerce_line_item_quantity;
      $revenue = $line->field_data_commerce_total_commerce_total_amount;
      $this
        ->assertFalse(empty($products[$sku]), t('The product %sku that is reported upon exists.', array(
        '%sku' => $sku,
      )));
      if (!empty($products[$sku])) {
        $this
          ->assertEqual($products[$sku]['quantity'], $quantity, t('The reported quantity %reported matches the generated quantity %generated.', array(
          '%sku' => $sku,
          '%reported' => $quantity,
          '%generated' => $products[$sku]['quantity'],
        )));
        $this
          ->assertEqual($products[$sku]['revenue'], $revenue, t('The reported revenue %reported matches the generated revenue %generated.', array(
          '%sku' => $sku,
          '%reported' => $revenue,
          '%generated' => $products[$sku]['revenue'],
        )));
      }
    }
  }

}

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().
CommerceReportsProductTestCase::getInfo public static function
CommerceReportsProductTestCase::setUp function Overrides DrupalWebTestCase::setUp(). Overrides CommerceReportsBaseTestCase::setUp
CommerceReportsProductTestCase::testMultipleOrdersProducts function Tests creating a multiple orders, containing multiple products with a variable quantity. Then verifies if the reporting is correct.
CommerceReportsProductTestCase::testMultipleProducts function Tests creating a single order, containing multiple products with a variable quantity. Then verifies if the reporting is correct.
CommerceReportsProductTestCase::testSingleProduct function Tests creating a single order, containing a single product with a variable quantity. Then verifies if the reporting is correct.
CommerceReportsProductTestCase::_test protected function