You are here

public function CommerceWebformTestCase::testSingleProductNoQuantitiesCommerceWebform in Commerce Webform 7.2

Test the ability to create a webform and add a product to it.

File

tests/commerce_webform.test, line 158
Commerce Webform tests.

Class

CommerceWebformTestCase
Test Commerce Webform module's features.

Code

public function testSingleProductNoQuantitiesCommerceWebform() {
  $product = $this
    ->createDummyProduct('SKU101', 'Special Product', 1000, 'GBP', 1, 'product');
  if (empty($product)) {
    throw new Exception('Could not make product');
  }
  $this
    ->drupalLogin($this->privileged_user);

  // Create a webform node with a product field and text field.
  $webform_node = $this
    ->createWebformNode();
  $this
    ->addProductFieldToWebformNode($webform_node, 'Product', 'product', array(), array(
    'SKU101',
  ), 'SKU101');
  $this
    ->addTextFieldToWebform($webform_node, 'Name', 'name', '', TRUE);

  // Logout and purchase a product.
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->basic_user);
  $settings = array(
    'submitted[name]' => 'My name',
    'submitted[product][0]' => $product->product_id,
  );
  $this
    ->drupalPost("node/{$webform_node->nid}", $settings, 'Submit');

  // Click through the cart screen.
  $this
    ->drupalPost('cart', array(), 'Checkout');

  // Click through the billing address.
  $this
    ->drupalPost('checkout/1', array(
    'customer_profile_billing[commerce_customer_address][und][0][country]' => 'AF',
    'customer_profile_billing[commerce_customer_address][und][0][name_line]' => 'Example Name',
    'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => 'Address Line 1',
    'customer_profile_billing[commerce_customer_address][und][0][premise]' => 'Address Line 2',
    'customer_profile_billing[commerce_customer_address][und][0][locality]' => 'City',
  ), 'Continue to next step');

  // Make a full example payment.
  $this
    ->drupalPost('checkout/1/review', array(
    'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    'commerce_payment[payment_details][credit_card][number]' => '4111111111111111',
    'commerce_payment[payment_details][credit_card][exp_month]' => '12',
    'commerce_payment[payment_details][credit_card][exp_year]' => date('Y'),
  ), 'Continue to next step');

  // Logout to check its all worked.
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->privileged_user);

  // Asset that the submission and order are linked.
  $this
    ->drupalGet('node/1/submission/1');
  $this
    ->clickLink('Paid');
  $this
    ->assertUrl('/admin/commerce/orders/1/view');
  $this
    ->assertText('Webform submission');
}