You are here

public function FacebookTrackingPixelTestCaseCommerce::testCommerceBaseTrackingAddtoCart in Facebook Tracking Pixel 7

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

Test tracking of items added to the cart.

File

tests/facebook_tracking_pixel.commerce.test, line 149

Class

FacebookTrackingPixelTestCaseCommerce
Test case.

Code

public function testCommerceBaseTrackingAddtoCart() {
  $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[addtocart]'] = 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);
  $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.'));
  $this
    ->assertRaw('facebook_tracking_pixel/commercetracking/fb_trk_addtocart_' . $this->baseCodeFBID . '.js', t('Add to cart tracking code JS found in head.'), 'FBTrkPx');
}