You are here

function FacebookTrackingPixelTestCase::setUp in Facebook Tracking Pixel 7

Same name and namespace in other branches
  1. 8 tests/facebook_tracking_pixel.test \FacebookTrackingPixelTestCase::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()

1 call to FacebookTrackingPixelTestCase::setUp()
FacebookTrackingPixelTestCaseUser::setUp in tests/facebook_tracking_pixel.user.test
Sets up a Drupal site for running functional and integration tests.
1 method overrides FacebookTrackingPixelTestCase::setUp()
FacebookTrackingPixelTestCaseUser::setUp in tests/facebook_tracking_pixel.user.test
Sets up a Drupal site for running functional and integration tests.

File

tests/facebook_tracking_pixel.test, line 65
Contains tests for the Facebook Tracking Pixel module.

Class

FacebookTrackingPixelTestCase
Test case.

Code

function setUp() {

  // Call the parent with an array of modules to enable for the test.
  $modules[] = 'facebook_tracking_pixel';
  parent::setUp($modules);

  // Create a test role to test visibility settings for roles.
  if ($testrid = $this
    ->drupalCreateRole([], 'fb pixel tester')) {

    // Create a generic authenticated user.
    $this->webUser = $this
      ->drupalCreateUser([
      'access content',
    ]);
    $edit = [
      'roles' => [
        $testrid => 'fb pixel tester',
      ],
    ];
    user_save($this->webUser, $edit);
  }

  // Create an admin user and log them in.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer facebook tracking pixels',
    'access content',
    'create page content',
    'edit own page content',
    'administer url aliases',
    'create url aliases',
    'administer users',
    'administer permissions',
  ]);
  $this
    ->drupalLogin($this->adminUser);

  // Set the role as admin for the admin user just created.
  $this
    ->drupalPost('user/' . $this->adminUser->uid . '/edit', [
    'roles[3]' => TRUE,
  ], t('Save'));
  $this->baseCodeFBID = '123123123';

  // 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();

  // Create a Node with a path alias for testing.
  // Create node to edit.
  $node = $this
    ->drupalCreateNode();
  $this->nodeTitle = $node->title;
  $this
    ->assertTrue(!empty($node->nid), t('A basic page has been created with node ID %nid and title %title and path alias', [
    '%nid' => $node->nid,
    '%title' => $node->title,
  ]), t('FBTrkPx'));

  // Create alias for the node just created above.
  $edit = [];
  $edit['source'] = 'node/' . $node->nid;
  $edit['alias'] = 'nodetest';
  $this
    ->drupalPost('admin/config/search/path/add', $edit, t('Save'));
  $this->testFacebookTrackingPixelNodeAlias = $edit['alias'];
  $this->nodeID = $node->nid;

  // Visit the system path for the node and confirm a cache entry is
  // created.
  cache_clear_all('*', 'cache_path', TRUE);
  $this
    ->drupalGet($edit['source']);
  $this
    ->assertTrue(cache_get($edit['source'], 'cache_path'), 'Cache entry was created.');

  // Visit the alias for the node and confirm a cache entry is created.
  cache_clear_all('*', 'cache_path', TRUE);
  $this
    ->drupalGet($edit['alias']);
  $this
    ->assertTrue(cache_get($edit['source'], 'cache_path'), 'Cache entry was created.');
}