You are here

function FacebookTrackingPixelTestCase::setUp in Facebook Tracking Pixel 8

Same name and namespace in other branches
  1. 7 tests/facebook_tracking_pixel.test \FacebookTrackingPixelTestCase::setUp()
1 call to FacebookTrackingPixelTestCase::setUp()
FacebookTrackingPixelTestCaseUser::setUp in tests/facebook_tracking_pixel.user.test
1 method overrides FacebookTrackingPixelTestCase::setUp()
FacebookTrackingPixelTestCaseUser::setUp in tests/facebook_tracking_pixel.user.test

File

tests/facebook_tracking_pixel.test, line 62
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.');
}