You are here

function FacebookTrackingPixelTestCaseCommerce::setUp in Facebook Tracking Pixel 7

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

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/facebook_tracking_pixel.commerce.test, line 93

Class

FacebookTrackingPixelTestCaseCommerce
Test case.

Code

function setUp() {

  // Setup the modules needed for testing.
  $modules = parent::setUpHelper('all', [
    'facebook_tracking_pixel',
  ]);
  parent::setUp($modules);

  // Enable all roles for tracking.
  $fbHelper = new facebookTrackingPixel\FacebookTrackingPixelTestHelper();
  $fbHelper
    ->enable_tracking_all_roles();
  $permissions = array_merge($this
    ->permissionBuilder('store admin'), [
    'administer facebook tracking pixels',
    'access content',
    'create page content',
    'edit own page content',
    'administer url aliases',
    'create url aliases',
    'administer users',
    'administer permissions',
  ]);
  $this->admin_user = $this
    ->drupalCreateUser($permissions);
  $this->store_customer = $this
    ->createStoreCustomer();

  // Create a Dummy product type for testing.
  $this->product_type = $this
    ->createDummyProductType();

  // Create a Dummy product using the product type just created with SKU 555.
  $this->product = $this
    ->createDummyProduct($this->product_sku, $this->product_name, -1, 'USD', 1, $this->product_type['type']);

  // Create a product display content type and attach a product field to it.
  $this
    ->createDummyProductDisplayContentType();

  // Create a product display node using the testing SKU.
  $node = $this
    ->createDummyProductNode([
    $this->product->product_id,
  ], 'Test Product Page');
  $this->product_node_nid = $node->nid;

  // Just in case, we clear all caches.
  cache_clear_all();

  // Test Basecode ID.
  db_insert('facebook_tracking_pixel_base_codes')
    ->fields([
    'base_code_name' => 'Test Basecode',
    'base_code_fbid' => $this->baseCodeFBID,
    'base_code_global' => 1,
    'weight' => 10,
  ])
    ->execute();

  // Retreieve the base id created.
  $this->baseCodeID = db_select('facebook_tracking_pixel_base_codes', 'c')
    ->fields('c', [
    'base_code_id',
  ])
    ->condition('base_code_fbid', $this->baseCodeFBID, '=')
    ->execute()
    ->fetchField();
}