diff --git a/commerce_winbiz.module b/commerce_winbiz.module
index 82d4777..5a8ed3b 100644
--- a/commerce_winbiz.module
+++ b/commerce_winbiz.module
@@ -463,7 +463,7 @@ function commerce_winbiz_commerce_taxes_available() {
 function commerce_winbiz_get_tax_rate($line_item) {
   if (variable_get('commerce_winbiz_use_commerce_tax', 0) > 0) {
     $items = field_get_items('commerce_line_item', $line_item, 'commerce_total');
-    foreach ($items[0]['data']['components'] as $key => $component) {
+    foreach ($items[0]['data']['components'] as $component) {
       $split = explode('|', $component['name']);
       if ($split[0] == 'tax') {
         return ($component['price']['data']['tax_rate']['rate'] * 100);
diff --git a/commerce_winbiz.test b/commerce_winbiz.test
index effecde..664e733 100644
--- a/commerce_winbiz.test
+++ b/commerce_winbiz.test
@@ -6,10 +6,14 @@
  */
 class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
 
-  protected $ordercount = 1;
   protected $order;
   protected $site_admin;
+  protected $tax_rate;
+  protected $product_price;
 
+  /**
+   * Implementation of getInfo().
+   */
   public static function getInfo() {
     return array(
       'name' => 'Export Tests',
@@ -18,6 +22,9 @@ class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
     );
   }
 
+  /**
+   * Implementation of setUp().
+   */
   public function setUp() {
     $modules = array(
       'commerce_winbiz',
@@ -26,6 +33,8 @@ class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
       'commerce_payment_example',
       'commerce_product_ui',
       'commerce_customer_ui',
+      'commerce_tax',
+      'commerce_tax_ui',
     );
 
     parent::setUp($modules);
@@ -33,8 +42,19 @@ class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
     // Set some variables of the winbiz module.
     variable_set('commerce_winbiz_profit_account_number', '3000');
     variable_set('commerce_winbiz_debit_account_number', '1100');
+
+    // Create and login the site admin if he's not already.
+    $this->site_admin = $this->createSiteAdmin();
+    user_role_change_permissions(DRUPAL_AUTHENTICATED_RID, array(
+      'access checkout' => TRUE,
+      'administer taxes' => TRUE,
+    ));
+    $this->drupalLogin($this->site_admin);
   }
 
+  /**
+   * Implementation of setUp().
+   */
   public function testCountExportedItems() {
     // Setup some testdata.
     $this->prepareOrderData();
@@ -57,18 +77,16 @@ class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
   public function testMandatoryFields() {
     // Setup some testdata and split the exported string already.
     $this->prepareOrderData();
-    $export = commerce_winbiz_export_orders(1, 1);
-    $itemsplit = explode('<br>', $export);
-    $fieldsplit = explode(';', $itemsplit[0]);
+    $field_split = $this->getExportSplit();
 
     // Print the exported data for informational purposes.
-    debug($fieldsplit, 'FIELDS');
+    debug($field_split, 'FIELDS');
 
     // Check if all the mandatory fields have a value.
     $export_is_valid = TRUE;
     $mandatory = array(1, 2, 3, 6, 11, 20, 51, 53, 54, 57, 60, 61, 62);
     for ($i = 0; $i < count($mandatory); $i++) {
-      if ($fieldsplit[$mandatory[$i]-1] == '') {
+      if ($field_split[$mandatory[$i]] == '') {
         $export_is_valid = FALSE;
         break;
       }
@@ -76,22 +94,101 @@ class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
     $this->assertEqual($export_is_valid, TRUE, t('All mandatory fields have a value.'));
   }
 
-  protected function prepareOrderData($tax_enabled = FALSE) {
-    $this->site_admin = $this->createSiteAdmin();
-    $this->drupalLogin($this->site_admin);
-    user_role_change_permissions(DRUPAL_AUTHENTICATED_RID, array(
-      'access checkout' => TRUE,
-    ));
+  function testPricingRulesAppliance() {
+    $discount_amount = rand(1, 10) * 1000;
+    // Import a pricing rule.
+    $config = '{ "rules_wbtest" : {
+        "LABEL" : "WBTest",
+        "PLUGIN" : "reaction rule",
+        "REQUIRES" : [ "commerce_line_item", "commerce_product_reference" ],
+        "ON" : [ "commerce_product_calculate_sell_price" ],
+        "DO" : [
+          { "commerce_line_item_unit_price_subtract" : {
+              "commerce_line_item" : [ "commerce_line_item" ],
+              "amount" : "' . $discount_amount . '",
+              "component_name" : "base_price",
+              "round_mode" : "1"
+            }
+          }
+        ]
+      }
+    }';
+    entity_import('rules_config', $config)->save();
+    $this->prepareOrderData();
+    $export = $this->getExportSplit();
+    $condition = $export[54] == commerce_currency_amount_to_decimal($this->product_price - $discount_amount, commerce_default_currency());
+    $this->assertTrue($condition, 'The exported product price takes pricing rules into account.');
+  }
+
+  function testPaymentMapping() {
+    $this->pass('Testing payment settings.');
+    variable_del('commerce_winbiz_payment_method_enabled_commerce_payment_example');
+    // Test if the set payment method code gets exported in the appropriate field.
+    $method_code = $this->randomName();
+    variable_set('commerce_winbiz_payment_method_code_commerce_payment_example', $method_code);
+    $this->prepareOrderData();
+    $export = $this->getExportSplit();
+    $this->assertEqual($export[147], $method_code, 'The payment method code was found in the export.');
+
+    // Check if the payment method code will change accordingly in the second exported row.
+    $method_code = $this->randomName();
+    variable_set('commerce_winbiz_payment_method_code_commerce_payment_example', $method_code);
+    $this->prepareOrderData();
+    $export = $this->getExportSplit(1);
+    $this->assertEqual($export[147], $method_code, 'The changed payment method code was found in the second exported order.');
+  }
+
+  function testOnlinePaymentExport() {
+    // Test if a payment row for online payments gets exported if the method is configured such.
+    variable_set('commerce_winbiz_payment_method_enabled_commerce_payment_example', TRUE);
+    $this->prepareOrderData(1, 2);
+    $method_data = array_shift(commerce_payment_methods());
+    $export = $this->getExportSplit(2);
+    $this->assertEqual($method_data['title'] . ' ' . t('Order') . ' ' . 1, $export[5], 'The payment row of for the order total is in the export.');
+  }
+
+  /**
+   * Tests if the right tax rate is applied.
+   */
+  function testTaxCalculation() {
+    // Setup test data and split the exported string.
+    $this->prepareOrderData();
+    $export = $this->getExportSplit();
+    variable_set('commerce_winbiz_use_commerce_tax', TRUE);
+    // Check the exported tax rate.
+    $this->assertEqual($export[61], '0', 'The exported tax rate is 0 because there is not commerce tax rate yet.');
+
+    // Create the tax rate and a new order.
+    $this->createTaxRate();
+    $this->prepareOrderData();
+    //$this->tax_rate = $this->createDummyTaxRate(array('type' => 'sales_tax'));
+    $export = $this->getExportSplit(1);
+
+    // Set variables to test commerce tax rate appliance,
+    variable_set('commerce_winbiz_commerce_tax_rate', $this->tax_rate);
+
+    // Check the exported tax rate.
+    debug($export[61]);
+    debug($this->tax_rate);
+    $this->assertEqual($export[61], $this->tax_rate, 'The exported tax rate equals the created commerce tax rate.');
+
+    variable_set('commerce_winbiz_use_commerce_tax', FALSE);
+    variable_set('commerce_winbiz_custom_tax_rate', 0.2);
+    $this->prepareOrderData();
+    $export = $this->getExportSplit(2);
+    $this->assertEqual($export[61], variable_get('commerce_winbiz_custom_tax_rate'), 'The exported tax rate equals the configured custom tax rate.');
+  }
+
+  protected function prepareOrderData($order_count = 1, $product_count = 1) {
     // Create a dummy product display content type.
     $this->createDummyProductDisplayContentType();
     // Create dummy product display nodes (and their corresponding product entities).
     $this->createProducts();
 
     // Create some order data.
-    for ($x = 1; $x <= $this->ordercount; $x++) {
-      // Add a couple of products to an order.
-      $productcount = rand(1, 5);
-      for ($i = 1; $i <= $productcount; $i++) {
+    for ($x = 1; $x <= $order_count; $x++) {
+      // Add a given number of products to an order.
+      for ($i = 1; $i <= $product_count; $i++) {
         // Submit the add to cart form.
         $this->drupalPost('node/' . $i, array(), t('Add to cart'));
       }
@@ -129,94 +226,78 @@ class CommerceWinBIZExportTestCase extends CommerceBaseTestCase {
     return $info;
   }
 
+  /**
+   * Creates 5 products with random name, sku and price 150.
+   */
   protected function createProducts() {
-    // Create 5 new products.
+    $this->product_price = 15000;
     for ($i = 1; $i <= 5; $i++) {
-      $sku = 'PROD-0' . $i;
-      $product_name = 'Product ' . $i;
-      $this->product = $this->createDummyProduct($sku, $product_name);
+      $sku = 'PROD-0' . $this->randomName();
+      $product_name = 'Product ' . $this->randomName();
+      $this->product = $this->createDummyProduct($sku, $product_name, $this->product_price);
       $this->product_node = $this->createDummyProductNode(array($this->product->product_id), $product_name);  
     }
   }
 
   /**
-   * Test the creation of a tax rate.
+   * Creates a commerce tax rate.
    *
-  public function testTaxCalculation() {
-    // Setup some testdata and split the exported string already.
-    $this->prepareOrderData();
-    $tax_rates = commerce_tax_rates();
-    debug($tax_rates);
-
-    variable_set('commerce_winbiz_use_commerce_tax', TRUE);
-    variable_set('commerce_winbiz_commerce_tax_rate', 0.00);
-  }
-
+   * Most of the code is borrowed from the commerce_tax module test.
+   */
   protected function createTaxRate() {
-
-    
-    $tax_rate = entity_create('commerce_tax', array());
-    entity->title = 'Example tax rate',
-      entityname]' => 'example_tax_rate',
-      entity->display_title]' => 'Example tax rate',
-      entity->description]' => 'Example tax rate for testing',
-      entity->rate]' => rand(1,100)/1000,
-      entity->type]' => 'example_tax_type',
-    // Login with normal user.
-    $this->drupalLogin($this->normal_user);
-
+    $this->tax_rate = 0.08;
     // Access the creation page for tax rates.
     $this->drupalGet('admin/commerce/config/taxes/rates/add');
 
-    // It should return a 403.
-    $this->assertResponse(403, t('Normal user is not able to access the creation page for tax rates'));
-
-    // Login with store admin user.
-    $this->drupalLogin($this->store_admin);
-
-    // Access the creation page for tax rates.
-    $this->drupalGet('admin/commerce/config/taxes/rates/add');
-
-    // It should return a 200.
-    $this->assertResponse(200, t('Store admin user can access the creation page for tax rates'));
-
     // Check the integrity of the tax rate form.
-    $this->pass(t('Test the integrity of the tax rate add form:'));
-    $this->assertFieldByXPath('//input[@id="edit-tax-rate-title" and contains(@class, "required")]', NULL, t('Tax rate title field is present and is required'));
-    $this->assertFieldById('edit-tax-rate-display-title', NULL, t('Tax rate display title field is present'));
-    $this->assertFieldById('edit-tax-rate-description', NULL, t('Tax rate description is present'));
-    $this->assertFieldByXPath('//input[@id="edit-tax-rate-rate" and contains(@class, "required")]', 0, t('Tax rate rate field is present, has 0 as default value and is required'));
-    $this->assertFieldByXPath('//select[@id="edit-tax-rate-type" and contains(@class, "required")]', NULL, t('Tax rate type field is present and is required'));
-
-    $tax_select_types = $this->xpath('//select[@id="edit-tax-rate-type"]//option');
-    foreach (commerce_tax_types() as $tax_type) {
-      $this->assertTrue(in_array($tax_type['display_title'], (array)$tax_select_types), t('Tax rate type %type is available for the rate', array('%type' => $tax_type['display_title'])));
-    }
-
-    $this->assertFieldById('edit-submit', t('Save tax rate'), t('\'Save tax rate\' button is present'));
-    $this->assertRaw(l(t('Cancel'), 'admin/commerce/config/taxes'), t('Cancel link is present'));
+    $this->pass(t('Creating a tax rate for the test'));
 
     // Fill the tax rate information and save tax rate.
     $edit = array(
-      'tax_rate[title]' => 'Example tax rate',
-      'tax_rate[name]' => 'example_tax_rate',
-      'tax_rate[display_title]' => 'Example tax rate',
+      'tax_rate[title]' => $this->randomName() . ' tax rate',
+      'tax_rate[name]' => strtolower($this->randomName()) . 'example_tax_rate',
+      'tax_rate[display_title]' => $this->randomName() . ' tax rate',
       'tax_rate[description]' => 'Example tax rate for testing',
-      'tax_rate[rate]' => rand(1,100)/1000,
-      'tax_rate[type]' => 'example_tax_type',
+      'tax_rate[rate]' => $this->tax_rate,
     );
     $this->drupalPost(NULL, $edit, t('Save tax rate'));
 
-    // Check the url after creation and if the values have been saved.
-    $this->assertTrue($this->url == url('admin/commerce/config/taxes', array('absolute' => TRUE)), t('After saving a tax rate we are in the list of tax rates'));
-    $this->assertText($edit['tax_rate[title]'], t('Title of the tax rate is present in the tax rates listing'));
-    $this->assertText($edit['tax_rate[name]'], t('Machine name of the tax rate is present in the tax rates listing'));
-    $this->assertText($edit['tax_rate[description]'], t('Description of the tax rate is present in the tax rates listing'));
-    $this->assertText(trim($edit['tax_rate[rate]']), t('Rate value of the tax rate is present in the tax rates listing'));
-
     // Check in database if the tax rate has been created.
     commerce_tax_rates_reset();
     $tax_rate = commerce_tax_rate_load($edit['tax_rate[name]']);
-    $this->assertFalse(empty($tax_rate), t('Tax is stored in database'));
-  }*/
+    $this->assertFalse(empty($tax_rate), 'Tax rate was created successfully.');
+    /* Here's some alternative for the above approach with the UI
+       Unfortunately the tax rate isn't applied correctly using this approach either.
+        // Fill the tax rate information and save tax rate.
+    $tax_rate = array(
+      'title' => $this->randomName() . ' tax rate',
+      'name' => strtolower($this->randomName()) . 'example_tax_rate',
+      'display_title' => $this->randomName() . ' tax rate',
+      'description' => 'Example tax rate for testing',
+      'rate' => $this->tax_rate,
+      'is_new' => TRUE,
+    );
+
+    commerce_tax_ui_tax_rate_save($tax_rate, TRUE);
+    $this->pass('Tax rate was saved');
+    $tax_rate = commerce_tax_rate_load($tax_rate['name']);
+    $this->assertFalse(empty($tax_rate), 'Tax rate was created successfully.');
+    */
+  }
+
+  /**
+   * Getter for the data as exported to WinBiz.
+   *
+   * @return array
+   *   Returns the split export string.
+   */
+  protected function getExportSplit($item_number = 0) {
+    $export = commerce_winbiz_export_orders(1, $item_number + 1);
+    $item_split = explode('<br>', $export);
+    $field_split = explode(';', $item_split[$item_number]);
+    // Add a virtual field for 0 index,
+    // because exports start at index 1.
+    array_unshift($field_split, '');
+    return $field_split;
+  }
 }
