You are here

public function FacebookTrackingPixelTestCaseCommerce::testCommerceBaseTrackingPurchase in Facebook Tracking Pixel 8

Same name and namespace in other branches
  1. 7 tests/facebook_tracking_pixel.commerce.test \FacebookTrackingPixelTestCaseCommerce::testCommerceBaseTrackingPurchase()

Test completing a purchase tracking.

File

tests/facebook_tracking_pixel.commerce.test, line 189

Class

FacebookTrackingPixelTestCaseCommerce
Test case.

Code

public function testCommerceBaseTrackingPurchase() {
  $this
    ->drupalLogin($this->admin_user);
  $edit = [];
  $this
    ->drupalGet('admin/config/system/facebook_tracking_pixel/commercetracking');
  $edit['facebook_tracking_pixel_commerce_tracking_enable'] = TRUE;
  $this
    ->drupalPostAJAX(NULL, $edit, 'facebook_tracking_pixel_commerce_tracking_enable');
  $edit['facebook_tracking_pixel_commerce_tracking_options_selection[purchase]'] = TRUE;
  $edit['facebook_tracking_pixel_commerce_tracking_basecode'] = $this->baseCodeID;
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertText(t('Commerce Tracking Settings Saved.'), t('Commerce checkout start settings saved.'), 'FBTrkPx');

  // Order must be created via the UI and not programatically.
  // Access the product display node.
  $this
    ->drupalGet('node/' . $this->product_node_nid);

  // Add product to the shopping cart.
  $edit = [];
  $this
    ->drupalPost(NULL, $edit, t('Add to cart'));
  $this
    ->assertText(t($this->product_name . ' added to your cart'), t('Product added to cart successfully.'));

  // Go to checkout.
  $this
    ->drupalGet('checkout');

  // Fill out the address form and submit.
  $edit = [];

  // Using a US address because of familiarity.
  $edit['customer_profile_billing[commerce_customer_address][und][0][country]'] = 'US';
  $this
    ->drupalPostAJAX(NULL, $edit, 'customer_profile_billing[commerce_customer_address][und][0][country]');
  $edit['customer_profile_billing[commerce_customer_address][und][0][name_line]'] = $this
    ->randomString();
  $edit['customer_profile_billing[commerce_customer_address][und][0][thoroughfare]'] = '123 Main Street';
  $edit['customer_profile_billing[commerce_customer_address][und][0][locality]'] = 'Smallville';
  $edit['customer_profile_billing[commerce_customer_address][und][0][administrative_area]'] = 'AK';
  $edit['customer_profile_billing[commerce_customer_address][und][0][postal_code]'] = '12345';
  $this
    ->drupalPost(NULL, $edit, t('Continue to next step'));
  $this
    ->assertText(t('Review order'), t('Arrived on review order page.'));
  $this
    ->drupalPost(NULL, [], t('Continue to next step'));
  $this
    ->assertRaw('fbq(\'init\', \'' . $this->baseCodeFBID, t('Checkout tracking code JS found in head.'), 'FBTrkPx');
  $this
    ->assertRaw('fbq(\'track\', \'Purchase\'', t('Purchase complete JS found'), 'FBTrkPx');
}