You are here

protected function CommerceReportsTaxGenerationTests::generateTax in Commerce Reporting 7.3

1 call to CommerceReportsTaxGenerationTests::generateTax()
CommerceReportsTaxGenerationTests::testSingleTaxType in modules/tax/tests/commerce_reports_tax.test
The following test is unfinished thanks to an apparant bug in SimpleTest.

File

modules/tax/tests/commerce_reports_tax.test, line 52
Tests for commerce tax reporting module.

Class

CommerceReportsTaxGenerationTests
@file Tests for commerce tax reporting module.

Code

protected function generateTax($amount = 1) {

  // Create a tax rate of Salex Type.
  $tax_rate = $this
    ->createDummyTaxRate(array(
    '' => '',
  ));
  $taxed = array();

  // Login with normal user.
  $this
    ->drupalLogin($this->normal_user);
  for ($i = 0; $i < $amount; $i++) {

    // Create a dummy order in cart status.
    $order = $this
      ->createDummyOrder($this->normal_user->uid);

    // Get the checkout url and navigate to it.
    $links = commerce_line_item_summary_links();

    // Checkout order
    $this
      ->drupalPost($links['checkout']['href'], array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $this
        ->randomName(),
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $this
        ->randomName(),
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $this
        ->randomName(),
    ), t('Continue to next step'));
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_details][name]' => $this
        ->randomName(),
    ), t('Continue to next step'));
    $orders = commerce_order_load_multiple(array(
      $order->order_id,
    ), array(), TRUE);
    $order = reset($orders);
    foreach ($order->commerce_order_total['und'][0]['data']['components'] as $component) {
      if (!empty($component['price']['data']['tax_rate'])) {
        if (empty($taxed[$component['price']['data']['tax_rate']['name']])) {
          $taxed[$component['price']['data']['tax_rate']['name']] = 0;
        }
        $taxed[$component['price']['data']['tax_rate']['name']] += $component['price']['amount'] / 100;
      }
    }
    $this->orders[] = $order;
  }
  return $taxed;
}