public function CommerceFreeShippingTestProcess::testCommerceFreeShippingWithFailingRulesConditionsCheckoutAuthenticatedUser in Commerce Free Shipping 7
Test the checkout process with a rules condition for free shipping that failed using an authenticated user.
File
- tests/
commerce_free_shipping.test, line 367 - Functional tests for the commerce free shipping module.
Class
- CommerceFreeShippingTestProcess
- Test checkout process.
Code
public function testCommerceFreeShippingWithFailingRulesConditionsCheckoutAuthenticatedUser() {
// Create a flat rate service.
$this->flat_rate_service = $this
->createFlateRateService();
$this
->enableFreeShipping();
$this
->enableFailingFreeShippingRules();
// Log in as normal user.
$this
->drupalLogin($this->store_customer);
// Create dummy product display nodes (and their corresponding product
// entities).
$sku = 'PROD-01';
$product_name = 'Product One';
$product = $this
->createDummyProduct($sku, $product_name, 8000);
// Order creation, in cart status.
$this->order = $this
->createDummyOrder($this->store_customer->uid, array(
$product->product_id => 1,
));
// Access to checkout page.
$this
->drupalGet($this
->getCommerceUrl('checkout'));
// Test if the product is in the cart at the good price.
$product_price = commerce_currency_format(8000, commerce_default_currency());
$this
->assertText($product_price, t('Product price is correct, and product is added to the order'));
// Generate random information, as city, postal code, etc.
$address_info = $this
->generateAddressInformation();
// Fill in the billing address information.
$billing_pane = $this
->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
$this
->drupalPostAJAX(NULL, array(
(string) $billing_pane[0]['name'] => 'US',
), (string) $billing_pane[0]['name']);
// Check if the country has been selected correctly, this uses XPath as the
// ajax call replaces the element and the id may change.
$this
->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-billing-commerce-customer-address')]//option[@selected='selected']", 'US', 'Billing country selected');
// Fill in the required information for billing pane, with a random State.
$info_billing = array(
'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
);
// Fill in the shipping address information.
$shipping_pane = $this
->xpath("//select[starts-with(@name, 'customer_profile_shipping[commerce_customer_address]')]");
$this
->drupalPostAJAX(NULL, array(
(string) $shipping_pane[0]['name'] => 'US',
), (string) $shipping_pane[0]['name']);
// Check if the country has been selected correctly, this uses XPath as the
// ajax call replaces the element and the id may change.
$this
->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-shipping-commerce-customer-address')]//option[@selected='selected']", 'US', 'Shipping country selected');
// Fill in the required information for billing pane, with a random State.
$info_shipping = array(
'customer_profile_shipping[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
'customer_profile_shipping[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
'customer_profile_shipping[commerce_customer_address][und][0][locality]' => $address_info['locality'],
'customer_profile_shipping[commerce_customer_address][und][0][administrative_area]' => 'KY',
'customer_profile_shipping[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
);
$this
->drupalPost(NULL, array_merge($info_billing, $info_shipping), t('Continue to next step'));
$this
->assertText('{explain your conditions}', t('The rules reject message is well displayed.'));
$price = commerce_currency_format($this->flat_rate_service['base_rate']['amount'], commerce_default_currency());
$this
->assertText($price, t('Flat rate price service is correct'));
}