You are here

class FacebookTrackingPixelTestCaseUser in Facebook Tracking Pixel 8

Same name and namespace in other branches
  1. 7 tests/facebook_tracking_pixel.user.test \FacebookTrackingPixelTestCaseUser

Hierarchy

Expanded class hierarchy of FacebookTrackingPixelTestCaseUser

File

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

View source
class FacebookTrackingPixelTestCaseUser extends FacebookTrackingPixelTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return [
      'name' => 'User Registration Test',
      'description' => 'Test user registration tracking.',
      'group' => 'Facebook Tracking Pixel',
    ];
  }

  /**
   * Basecode ID number for user testing.
   *
   * @var int
   */
  public $userBaseCodeID;

  /**
   * Fictional FBID for user testing.
   * @var string
   */
  public $userBaseCodeFBID = '345345345345';

  /**
   * {@inheritdoc}
   */
  function setUp() {
    parent::setUp();

    // Enable all roles for tracking.
    $fbHelper = new facebookTrackingPixel\FacebookTrackingPixelTestHelper();
    $fbHelper
      ->enable_tracking_all_roles();

    // Create a non-global base code to test with user tracking.
    // Test Basecode ID.
    db_insert('facebook_tracking_pixel_base_codes')
      ->fields([
      'base_code_name' => 'Test Basecode 2',
      'base_code_fbid' => $this->userBaseCodeFBID,
      'base_code_global' => 0,
      'weight' => 20,
    ])
      ->execute();

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

  /**
   * Test to enable user tracking on global base code.
   */
  public function testFacebookTrackingPixelUserRegistrationGlobal() {

    // Turn on user registration and select test global base code.
    $edit = [];
    $this
      ->drupalGet('admin/config/system/facebook_tracking_pixel/user_registration');
    $edit['facebook_tracking_pixel_user_registration_enable'] = TRUE;
    $this
      ->drupalPostAJAX(NULL, $edit, 'facebook_tracking_pixel_user_registration_enable');
    $edit['facebook_tracking_pixel_user_registration_basecode'] = $this->baseCodeID;
    $this
      ->drupalPost(NULL, $edit, t('Save configuration'));
    $this
      ->assertText(t('User tracking settings saved.'), t('User registration tracking enabled.'), 'FBTrkPx');

    // Logout and drop into creating a normal user to test user registration.
    $this
      ->drupalLogout();
    variable_set('user_email_verification', 0);
    variable_set('user_register', 1);
    $this
      ->drupalGet('user/register');
    $edit = [];
    $edit['name'] = $this
      ->randomName(8);
    $edit['mail'] = $edit['name'] . '@example.com';
    $pass = user_password(12);
    $edit['pass[pass1]'] = $pass;
    $edit['pass[pass2]'] = $pass;
    $this
      ->drupalPost(NULL, $edit, t('Create new account'));
    $this
      ->assertText(t('Registration successful. You are now logged in.'), t('Created a user using the UI and logged in.'), 'FBTrkPx');
    $this
      ->assertRaw('facebook_tracking_pixel/registrationtracking/fb_trk_user_registration.js', t('Path tracking code JS found in head.'), 'FBTrkPx');
  }

  /**
   * Test tracking on a non-global tracking code.
   */
  public function testFacebookTrackingPixelUserRegistrationNonGlobal() {

    // Turn on user registration and select test global base code.
    $edit = [];
    $this
      ->drupalGet('admin/config/system/facebook_tracking_pixel/user_registration');
    $edit['facebook_tracking_pixel_user_registration_enable'] = TRUE;
    $this
      ->drupalPostAJAX(NULL, $edit, 'facebook_tracking_pixel_user_registration_enable');
    $edit['facebook_tracking_pixel_user_registration_basecode'] = $this->userBaseCodeID;
    $this
      ->drupalPost(NULL, $edit, t('Save configuration'));
    $this
      ->assertText(t('User tracking settings saved.'), t('User registration tracking enabled.'), 'FBTrkPx');

    // Logout and drop into creating a normal user to test user registration.
    $this
      ->drupalLogout();
    variable_set('user_email_verification', 0);
    variable_set('user_register', 1);
    $this
      ->drupalGet('user/register');
    $edit = [];
    $edit['name'] = $this
      ->randomName(8);
    $edit['mail'] = $edit['name'] . '@example.com';
    $pass = user_password(12);
    $edit['pass[pass1]'] = $pass;
    $edit['pass[pass2]'] = $pass;
    $this
      ->drupalPost(NULL, $edit, t('Create new account'));
    $this
      ->assertText(t('Registration successful. You are now logged in.'), t('Created a user using the UI and logged in.'), 'FBTrkPx');
    $this
      ->assertRaw('facebook_tracking_pixel/registrationtracking/fb_trk_user_registration.js', t('Path tracking code JS found in head.'), 'FBTrkPx');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FacebookTrackingPixelTestCase::$adminUser protected property Adminstrative user.
FacebookTrackingPixelTestCase::$baseCodeFBID protected property Test base code FB ID number.
FacebookTrackingPixelTestCase::$baseCodeID protected property Facebook Basecode database ID number.
FacebookTrackingPixelTestCase::$nodeID protected property Test node id number.
FacebookTrackingPixelTestCase::$nodeTitle protected property Test node title.
FacebookTrackingPixelTestCase::$testFacebookTrackingPixelNodeAlias protected property Node alias created during testing.
FacebookTrackingPixelTestCase::$webUser protected property Generic web user.
FacebookTrackingPixelTestCaseUser::$userBaseCodeFBID public property Fictional FBID for user testing.
FacebookTrackingPixelTestCaseUser::$userBaseCodeID public property Basecode ID number for user testing.
FacebookTrackingPixelTestCaseUser::getInfo public static function
FacebookTrackingPixelTestCaseUser::setUp function Overrides FacebookTrackingPixelTestCase::setUp
FacebookTrackingPixelTestCaseUser::testFacebookTrackingPixelUserRegistrationGlobal public function Test to enable user tracking on global base code.
FacebookTrackingPixelTestCaseUser::testFacebookTrackingPixelUserRegistrationNonGlobal public function Test tracking on a non-global tracking code.