commerce_reports_tax.test in Commerce Reporting 7.3
Tests for commerce tax reporting module.
File
modules/tax/tests/commerce_reports_tax.testView source
<?php
/**
* @file
* Tests for commerce tax reporting module.
*/
class CommerceReportsTaxGenerationTests extends CommerceBaseTestCase {
protected $tax_rates;
protected $orders;
public static function getInfo() {
return array(
'name' => 'Tax reports',
'description' => 'Tests if the tax reporting module correctly catches tax information.',
'group' => 'Drupal Commerce',
);
}
/**
* Helper function to get different combinations of permission sets.
*
* @param $set
* Can be a single string (from the following) or can be an array containing
* multiple values that should be merged:
* 'site admin': Admin permissions for Drupal core modules
* 'store admin': All commerce "administer X" permissions
*/
protected function permissionBuilder($sets) {
if (is_string($sets)) {
$sets = array(
$sets,
);
}
$store_admin = array(
'access commerce tax reports',
'configure commerce tax reports',
);
$final_permissions = parent::permissionBuilder($sets);
foreach ($sets as $set) {
switch ($set) {
case 'store admin':
$final_permissions = array_unique(array_merge($final_permissions, $store_admin));
break;
}
}
return $final_permissions;
}
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;
}
function setUp() {
$this
->resetAll();
$modules = parent::setUpHelper('all', array(
'commerce_reports_tax',
));
parent::setUp($modules);
$this->store_admin = $this
->createUserWithPermissionHelper(array(
'site admin',
'store admin',
));
$this
->drupalLogin($this->store_admin);
$this
->drupalGet('admin/commerce/config/tax-reports/generate');
$this->normal_user = $this
->drupalCreateUser(array(
'access checkout',
'view own commerce_order entities',
));
$this->tax_type = $this
->createDummyTaxType();
}
/**
* The following test is unfinished thanks to an apparant bug in SimpleTest.
*/
function testSingleTaxType() {
debug($this
->generateTax());
debug(commerce_reports_tax());
$this
->drupalLogin($this->store_admin);
$this
->drupalGet('admin/commerce/reports/tax');
}
}
Classes
Name | Description |
---|---|
CommerceReportsTaxGenerationTests | @file Tests for commerce tax reporting module. |