You are here

acquia_lift_profiles.test in Acquia Lift Connector 7.2

Same filename and directory in other branches
  1. 7 acquia_lift_profiles/tests/acquia_lift_profiles.test

Tests for Acquia Lift Profiles module.

File

acquia_lift_profiles/tests/acquia_lift_profiles.test
View source
<?php

/**
 * @file
 * Tests for Acquia Lift Profiles module.
 */

/**
 * Tests Acquia Lift Profiles functionality.
 */
class ALProfilesWebTest extends DrupalWebTestCase {
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => t('Acquia Lift Profiles Tests'),
      'description' => t('Tests basic functionality of Acquia Lift Profiles module.'),
      'group' => t('Personalize'),
    );
  }
  function setUp() {
    parent::setUp(array(
      'ctools',
      'visitor_actions',
      'acquia_lift_profiles',
    ));
    require_once dirname(__FILE__) . '/acquia_lift_profiles.test_classes.inc';
    variable_set('user_register', USER_REGISTER_VISITORS);
    variable_set('user_email_verification', FALSE);
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'access administration pages',
      'administer acquia_lift_profiles configuration',
      'administer content types',
      'administer nodes',
      'bypass node access',
      'administer visitor actions',
    ));
    variable_set('acquia_lift_profiles_web_test_data', array(
      'segments' => array(
        'segment1',
        'segment2',
      ),
    ));
  }
  function tearDown() {
    variable_del('acquia_lift_profiles_web_test_data');
    parent::tearDown();
  }
  function testAdminLink() {

    // Verify that the Acquia Lift Web Admin link is the default.
    $this
      ->assertAcquiaLiftWebAdminLink('http://lift.acquia.com');
    $this
      ->configureALProfiles();

    // Assert that the web admin link was updated.
    $this
      ->assertAcquiaLiftWebAdminLink('http://api.example.com');
  }
  function testALProfilesJSSettings() {
    $this
      ->configureALProfiles();

    // Register as a new user, identity should not be captured.
    $user_name_1 = $this
      ->randomName();
    $password_1 = $this
      ->randomName();
    $new_user_fields = array(
      'name' => $user_name_1,
      'mail' => $user_name_1 . '@example.com',
      'pass[pass1]' => $password_1,
      'pass[pass2]' => $password_1,
    );
    $this
      ->drupalPost('user/register', $new_user_fields, t('Create new account'));
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertFalse($settings['acquia_lift_profiles']['captureIdentity']);

    // Log out and log back in and there still shouldn't be any settings for
    // capturing identity.
    $this
      ->drupalLogout();
    $this
      ->drupalPost('user/login', array(
      'name' => $user_name_1,
      'pass' => $password_1,
    ), t('Log in'));
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertFalse($settings['acquia_lift_profiles']['captureIdentity']);
    $this
      ->drupalLogout();

    // Login as admin again and set the "capture identity" setting.
    $this
      ->drupalLogin($this->admin_user);
    $edit = array(
      'acquia_lift_profiles_identity[acquia_lift_profiles_capture_identity]' => TRUE,
    );
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift_profiles', $edit, t('Save'));
    $this
      ->drupalLogout();
    $this
      ->resetAll();

    // Now log in as the first new user and check that we do have settings for
    // capturing identity.
    $this
      ->drupalPost('user/login', array(
      'name' => $user_name_1,
      'pass' => $password_1,
    ), t('Log in'));
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue($settings['acquia_lift_profiles']['captureIdentity']);
    $this
      ->assertEqual(array(
      'form_submit',
      'user_login',
    ), array_keys($settings['acquia_lift_profiles']['serverSideActions']));
    $this
      ->drupalLogout();

    // Register as another new user, identity should now be captured.
    $user_name_2 = $this
      ->randomName();
    $password_2 = $this
      ->randomName();
    $new_user_fields = array(
      'name' => $user_name_2,
      'mail' => $user_name_2 . '@example.com',
      'pass[pass1]' => $password_2,
      'pass[pass2]' => $password_2,
    );
    $this
      ->drupalPost('user/register', $new_user_fields, t('Create new account'));
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue($settings['acquia_lift_profiles']['captureIdentity']);
    $this
      ->assertEqual(array(
      'form_submit',
      'user_login',
      'user_register',
    ), array_keys($settings['acquia_lift_profiles']['serverSideActions']));
    $this
      ->drupalLogout();

    // When registration process requires user email verification,
    // identity should not be captured.
    variable_set('user_email_verification', TRUE);
    $user_name_3 = $this
      ->randomName();
    $new_user_fields = array(
      'name' => $user_name_3,
      'mail' => $user_name_3 . '@example.com',
    );
    $this
      ->drupalPost('user/register', $new_user_fields, t('Create new account'));
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue($settings['acquia_lift_profiles']['captureIdentity']);
    $this
      ->assertEqual(array(
      'form_submit',
    ), array_keys($settings['acquia_lift_profiles']['serverSideActions']));
  }
  function testThumbnailImage() {
    $this
      ->configureALProfiles();
    $this
      ->drupalLogin($this->admin_user);

    // Create a new article node of this type.
    $test_image = current($this
      ->drupalGetTestFiles('image'));
    $edit = array(
      'title' => $this
        ->randomName(),
    );
    $edit['files[field_image_' . LANGUAGE_NONE . '_0]'] = drupal_realpath($test_image->uri);
    $this
      ->drupalPost('node/add/article', $edit, t('Save'));
    $nid = $this
      ->getNidFromCurrentUrl();
    $items = field_get_items('node', node_load($nid), 'field_image');
    $image_uri = $items[0]['uri'];

    // Verify that the image thumbnail is empty in the page context.
    $this
      ->drupalGet('node/' . $nid);
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue($settings['acquia_lift_profiles']['pageContext']['thumbnail_url'] == '', 'Thumbnail image is blank');

    // Set the thumbnail fields for articles.
    $edit = array(
      'acquia_lift_profiles[thumbnail]' => 'field_image|image_image',
      'acquia_lift_profiles[style]' => 'thumbnail',
    );
    $this
      ->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));

    // Verify that the thumbnail is set (after stripping off the token).
    $token_regex = '/\\?itok=[a-zA-Z0-9]*/';
    $thumbnail_image = preg_replace($token_regex, '', image_style_url('thumbnail', $image_uri));
    $this
      ->drupalGet('node/' . $nid);
    $settings = $this
      ->drupalGetSettings();
    $settings_image = preg_replace($token_regex, '', $settings['acquia_lift_profiles']['pageContext']['thumbnail_url']);
    $this
      ->assertEqual($thumbnail_image, $settings_image);

    // Change the image style.
    $edit['acquia_lift_profiles[style]'] = 'medium';
    $this
      ->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));

    // Verify that the new image style appears in the page context.
    $this
      ->drupalGet('node/' . $nid);
    $thumbnail_image = preg_replace($token_regex, '', image_style_url('medium', $image_uri));
    $this
      ->drupalGet('node/' . $nid);
    $settings = $this
      ->drupalGetSettings();
    $settings_image = preg_replace($token_regex, '', $settings['acquia_lift_profiles']['pageContext']['thumbnail_url']);
    $this
      ->assertEqual($thumbnail_image, $settings_image);

    // Create an article without an image.
    $edit = array(
      'title' => $this
        ->randomName(),
    );
    $this
      ->drupalPost('node/add/article', $edit, t('Save'));
    $second_nid = $this
      ->getNidFromCurrentUrl();

    // Verify that the image is blank in the page context.
    $this
      ->drupalGet('node/' . $second_nid);
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue($settings['acquia_lift_profiles']['pageContext']['thumbnail_url'] == '', 'Thumbnail image is blank');

    // Verify image is not passed on node aggregate pages.
    $this
      ->drupalGet('node');
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue(!isset($settings['acquia_lift_profiles']['pageContext']['thumbnail_url']), 'Thumbnail image is not set');

    // Remove the thumbnail setting.
    $edit = array(
      'acquia_lift_profiles[thumbnail]' => '',
    );
    $this
      ->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));

    // Verify that no thumbnail is passed in page context.
    $this
      ->drupalGet('node/' . $nid);
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertTrue($settings['acquia_lift_profiles']['pageContext']['thumbnail_url'] == '', 'Thumbnail image is blank');
  }

  /**
   * Tests that available segments are added to the page.
   */
  function testSegments() {
    $this
      ->configureALProfiles();
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalGet('');

    // The dummy http client used during web tests has two segments set up that
    // will always be returned by a call to getSegments().
    $test_segments = array(
      'segment1',
      'segment2',
    );

    // Test that the segments show up in the js settings.
    $settings = $this
      ->drupalGetSettings();
    $this
      ->assertEqual($settings['acquia_lift_profiles']['available_segments'], $test_segments);
  }

  /**
   * Tests identity param configuration and js settings.
   */
  function testIdentityParams() {
    $this
      ->configureALProfiles();
    $this
      ->drupalLogin($this->admin_user);

    // Test specifying a querystring param to use for capturing identity.
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift_profiles', array(
      'acquia_lift_profiles_identity[acquia_lift_profiles_identity_param]' => 'ali',
    ), t('Save'));
    $this
      ->drupalLogout();

    // Now visit the site as anon without passing any querystring params.
    $this
      ->drupalGet('');
    $settings = $this
      ->drupalGetSettings();
    $alp_settings = $settings['acquia_lift_profiles'];
    $this
      ->assertFalse(isset($alp_settings['identity']));

    // Now pass the configured identity param
    $my_id = 'ohai';
    $this
      ->drupalGet('', array(
      'query' => array(
        'ali' => $my_id,
      ),
    ));
    $settings = $this
      ->drupalGetSettings();
    $alp_settings = $settings['acquia_lift_profiles'];
    $this
      ->assertEqual($alp_settings['identity'], $my_id);
    $this
      ->assertEqual($alp_settings['identityType'], ACQUIA_LIFT_PROFILES_DEFAULT_IDENTITY_TYPE_DEFAULT);

    // Set the identity type param
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift_profiles', array(
      'acquia_lift_profiles_identity[acquia_lift_profiles_identity_type_param]' => 'alit',
    ), t('Save'));
    $this
      ->drupalLogout();

    // Pass the configured identity param and the identity_type param
    $my_type = 'socialtastic';
    $this
      ->drupalGet('', array(
      'query' => array(
        'ali' => $my_id,
        'alit' => $my_type,
      ),
    ));
    $settings = $this
      ->drupalGetSettings();
    $alp_settings = $settings['acquia_lift_profiles'];
    $this
      ->assertEqual($alp_settings['identity'], $my_id);
    $this
      ->assertEqual($alp_settings['identityType'], $my_type);

    // Pass the configured identity type param without the identity param
    $this
      ->drupalGet('', array(
      'query' => array(
        'alit' => $my_type,
      ),
    ));
    $settings = $this
      ->drupalGetSettings();
    $alp_settings = $settings['acquia_lift_profiles'];
    $this
      ->assertFalse(isset($alp_settings['identity']));
    $this
      ->assertFalse(isset($alp_settings['identityType']));

    // Set the default identity type
    $default_type = 'tknr';
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift_profiles', array(
      'acquia_lift_profiles_identity[acquia_lift_profiles_default_identity_type]' => $default_type,
    ), t('Save'));
    $this
      ->drupalLogout();

    // Pass the configured identity param but without the identity_type param
    $this
      ->drupalGet('', array(
      'query' => array(
        'ali' => $my_id,
      ),
    ));
    $settings = $this
      ->drupalGetSettings();
    $alp_settings = $settings['acquia_lift_profiles'];
    $this
      ->assertEqual($alp_settings['identity'], $my_id);
    $this
      ->assertEqual($alp_settings['identityType'], $default_type);

    // Pass the configured identity param and with the identity_type param
    $this
      ->drupalGet('', array(
      'query' => array(
        'ali' => $my_id,
        'alit' => $my_type,
      ),
    ));
    $settings = $this
      ->drupalGetSettings();
    $alp_settings = $settings['acquia_lift_profiles'];
    $this
      ->assertEqual($alp_settings['identity'], $my_id);
    $this
      ->assertEqual($alp_settings['identityType'], $my_type);
  }

  // Tests that configuring events to track in Acquia Lift Profiles makes the required calls to
  // the Acquia Lift Profiles API.
  function testSyncEvents() {
    $this
      ->configureALProfiles();
    $this
      ->drupalLogin($this->admin_user);
    ALProfilesAPI::setTestInstance();

    // Create a custom action with a label.
    $action_name = 'my_action_with_label';
    $action_label = 'My Friendly Event';
    $action = array(
      'machine_name' => $action_name,
      'label' => $action_label,
      'plugin' => 'link',
      'client_side' => 1,
      'module' => 'visitor_actions',
      'identifier' => '#some-id',
      'event' => 'click',
      'pages' => '',
      'data' => array(),
      'limited_use' => 1,
    );
    visitor_actions_save_action($action);

    // An action with no label should send the machine name as the label to
    // Lift Web.
    $new_action_name = 'my_action_without_label';
    $new_action = $action;
    unset($new_action['label']);
    $new_action['machine_name'] = $new_action_name;
    visitor_actions_save_action($new_action);

    // Check that the expected requests have been made to the Event CRUD API.
    $requests = DummyALProfilesHttpClient::getLoggedRequests();
    $this
      ->assertEqual('http://api.example.com/dashboard/rest/TESTACCOUNT/events/my_action_with_label?customerSite=TESTSITE&label=' . rawurlencode($action_label) . '&type=OTHER', $requests[0]['uri']);
    $this
      ->assertEqual('http://api.example.com/dashboard/rest/TESTACCOUNT/events/my_action_without_label?customerSite=TESTSITE&label=' . $new_action_name . '&type=OTHER', $requests[1]['uri']);
    DummyALProfilesHttpClient::clearLoggedRequests();

    // Now delete the actions.
    visitor_actions_delete_action($action_name);

    // Check that the DELETE request has been made to the API.
    $requests = DummyALProfilesHttpClient::getLoggedRequests();
    $this
      ->assertEqual('http://api.example.com/dashboard/rest/TESTACCOUNT/events/my_action_with_label?customerSite=TESTSITE', $requests[0]['uri']);
    $this
      ->assertEqual('delete', $requests[0]['type']);
  }
  function testFieldMappings() {
    $this
      ->configureALProfiles();
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->createUserProfileField('test_user_field_1');
    $this
      ->createUserProfileField('test_user_field_2');
    $this
      ->resetAll();
    $edit = array(
      'acquia_lift_profiles_field_mappings[content_section]' => 'user_profile_context__test_user_field_1',
      'acquia_lift_profiles_field_mappings[content_keywords]' => 'user_profile_context__test_user_field_2',
    );
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift_profiles', $edit, t('Save'));
    $this
      ->drupalGet('');
    $settings = $this
      ->drupalGetSettings();
    $expected = array(
      'field' => array(
        'content_section' => 'user_profile_context__test_user_field_1',
        'content_keywords' => 'user_profile_context__test_user_field_2',
      ),
    );
    $this
      ->assertEqual($expected, $settings['acquia_lift_profiles']['mappings']);
    $this
      ->assertEqual('session', $settings['personalize']['cacheExpiration']['visitor_context:user_profile_context:test_user_field_1']);
    $this
      ->assertEqual('session', $settings['personalize']['cacheExpiration']['visitor_context:user_profile_context:test_user_field_2']);

    // Confirm that the context value is available in the settings
    $this
      ->drupalLogout();
    $regular_user = $this
      ->drupalCreateUser(array(
      'access content',
    ));
    $pass_raw = $regular_user->pass_raw;
    unset($regular_user->pass_raw);
    $edit = array(
      'field_test_user_field_1' => array(
        'und' => array(
          array(
            'value' => 'ohai',
          ),
        ),
      ),
    );
    user_save($regular_user, $edit);
    $this
      ->resetAll();
    $regular_user->pass_raw = $pass_raw;
    $this
      ->drupalLogin($regular_user);
    $this
      ->drupalGet('');
    $settings = $this
      ->drupalGetSettings();
    $expected = array(
      'test_user_field_1' => 'ohai',
    );
    $this
      ->assertEqual($expected, $settings['personalize_user_profile_context']);
  }
  function testUDFMappings() {
    $this
      ->configureALProfiles();
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->createUserProfileField('test_user_field_1');
    $this
      ->createUserProfileField('test_user_field_2');
    $this
      ->resetAll();
    $edit = array(
      'acquia_lift_profiles_udf_mappings[person][person_udf1]' => 'user_profile_context__test_user_field_1',
      'acquia_lift_profiles_udf_mappings[touch][touch_udf20]' => 'user_profile_context__test_user_field_2',
    );
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift_profiles', $edit, t('Save'));
    $this
      ->drupalGet('');
    $settings = $this
      ->drupalGetSettings();
    $expected = array(
      'person' => array(
        'person_udf1' => 'user_profile_context__test_user_field_1',
      ),
      'touch' => array(
        'touch_udf20' => 'user_profile_context__test_user_field_2',
      ),
    );
    $this
      ->assertEqual($expected, $settings['acquia_lift_profiles']['mappings']);
    $this
      ->assertEqual('session', $settings['personalize']['cacheExpiration']['visitor_context:user_profile_context:test_user_field_1']);
    $this
      ->assertEqual('session', $settings['personalize']['cacheExpiration']['visitor_context:user_profile_context:test_user_field_2']);

    // Confirm that the context value is available in the settings
    $this
      ->drupalLogout();
    $regular_user = $this
      ->drupalCreateUser(array(
      'access content',
    ));
    $pass_raw = $regular_user->pass_raw;
    unset($regular_user->pass_raw);
    $edit = array(
      'field_test_user_field_1' => array(
        'und' => array(
          array(
            'value' => 'ohai',
          ),
        ),
      ),
    );
    user_save($regular_user, $edit);
    $this
      ->resetAll();
    $regular_user->pass_raw = $pass_raw;
    $this
      ->drupalLogin($regular_user);
    $this
      ->drupalGet('');
    $settings = $this
      ->drupalGetSettings();
    $expected = array(
      'test_user_field_1' => 'ohai',
    );
    $this
      ->assertEqual($expected, $settings['personalize_user_profile_context']);
  }
  function testLiftEventValuesConfig() {
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->createVisitorActions();

    // Set some engagement score global values.
    $edit = array(
      'acquia_lift_profiles_lift_event_values[scroll_to_bottom][global_value]' => 123,
      'acquia_lift_profiles_lift_event_values[acquia_lift_profiles_form_click][engagement_score]' => 456,
      'acquia_lift_profiles_lift_event_values[acquia_lift_profiles_form_hover][global_value]' => 789,
    );
    $this
      ->drupalPost('admin/config/content/personalize/lift_event_values', $edit, t('Save configuration'));

    // Assert no error message, and the new values are correctly set on the form.
    $this
      ->assertNoText('must be a positive integer.');
    $this
      ->assertFieldByName('acquia_lift_profiles_lift_event_values[scroll_to_bottom][engagement_score]', 1);
    $this
      ->assertFieldByName('acquia_lift_profiles_lift_event_values[scroll_to_bottom][global_value]', 123);
    $this
      ->assertFieldByName('acquia_lift_profiles_lift_event_values[acquia_lift_profiles_form_click][engagement_score]', 456);
    $this
      ->assertFieldByName('acquia_lift_profiles_lift_event_values[acquia_lift_profiles_form_click][global_value]', 1);
    $this
      ->assertFieldByName('acquia_lift_profiles_lift_event_values[acquia_lift_profiles_form_hover][engagement_score]', 1);
    $this
      ->assertFieldByName('acquia_lift_profiles_lift_event_values[acquia_lift_profiles_form_hover][global_value]', 789);

    // Assert system actions don't have "Edit" links, and custom actions do.
    $this
      ->assertNoLinkByHref('admin/structure/acquia_lift/visitor_action/scroll_to_bottom/edit');
    $this
      ->assertLinkByHref('admin/structure/acquia_lift/visitor_action/acquia_lift_profiles_form_click/edit');
    $this
      ->assertLinkByHref('admin/structure/acquia_lift/visitor_action/acquia_lift_profiles_form_hover/edit');

    // Assert the values are set in the DB.
    $lift_event_values = variable_get('acquia_lift_profiles_lift_event_values', array());
    $this
      ->assertEqual($lift_event_values['scroll_to_bottom']['engagement_score'], 1);
    $this
      ->assertEqual($lift_event_values['scroll_to_bottom']['global_value'], 123);
    $this
      ->assertEqual($lift_event_values['acquia_lift_profiles_form_click']['engagement_score'], 456);
    $this
      ->assertEqual($lift_event_values['acquia_lift_profiles_form_click']['global_value'], 1);
    $this
      ->assertEqual($lift_event_values['acquia_lift_profiles_form_hover']['engagement_score'], 1);
    $this
      ->assertEqual($lift_event_values['acquia_lift_profiles_form_hover']['global_value'], 789);

    // Attempt to set an unacceptable value.
    $edit = array(
      'acquia_lift_profiles_lift_event_values[scroll_to_bottom][engagement_score]' => -1,
    );
    $this
      ->drupalPost('admin/config/content/personalize/lift_event_values', $edit, t('Save configuration'));

    // Assert the error message, as well as the values were unchanged.
    $this
      ->assertText('must be a positive integer.');
    $lift_event_values = variable_get('acquia_lift_profiles_lift_event_values', array());
    $this
      ->assertEqual($lift_event_values['scroll_to_bottom']['global_value'], 123);

    // Assert the engagement score and global value settings are now on the page.
    $this
      ->drupalGet('node');
    $this
      ->assertEqual($this->drupalSettings['acquia_lift_profiles']['engagement_scores']['scroll_to_bottom'], 1);
    $this
      ->assertEqual($this->drupalSettings['acquia_lift_profiles']['global_values']['scroll_to_bottom'], 123);
    $this
      ->assertEqual($this->drupalSettings['acquia_lift_profiles']['engagement_scores']['acquia_lift_profiles_form_click'], 456);
    $this
      ->assertEqual($this->drupalSettings['acquia_lift_profiles']['global_values']['acquia_lift_profiles_form_click'], 1);

    // Because the action does not apply to the "node" page, we should not see its settings.
    $this
      ->assertFalse(isset($this->drupalSettings['acquia_lift_profiles']['engagement_scores']['acquia_lift_profiles_form_hover']));
    $this
      ->assertFalse(isset($this->drupalSettings['acquia_lift_profiles']['global_values']['acquia_lift_profiles_form_hover']));
  }

  /**
   * Helper function to configure acquia_lift_profiles settings.
   */
  protected function configureALProfiles() {
    $settings = array(
      'acquia_lift_profiles_js_path' => 'acquia_lift_profiles.example.com/path/to.js',
      'acquia_lift_profiles_account_name' => 'MYALPROFILESACCOUNT',
      'acquia_lift_profiles_site_name' => 'MYALPROFILESSITE',
      'acquia_lift_profiles_api_url' => 'api.example.com',
      'acquia_lift_profiles_access_key' => 'abc123',
      'acquia_lift_profiles_secret_key' => 'xyz987',
    );
    foreach ($settings as $setting => $value) {
      variable_set($setting, $value);
    }
  }

  /**
   * Creates a user profile field which can be used for targeting.
   *
   * @return array
   *   An associative array representing the field.
   */
  protected function createUserProfileField($field_name = NULL) {
    $field_name = empty($field_name) ? $this
      ->randomName() : $field_name;
    $field = array(
      'field_name' => 'field_' . drupal_strtolower($field_name),
      'type' => 'text',
      'cardinality' => 1,
    );
    field_create_field($field);
    $fieldInstance = array(
      'field_name' => $field['field_name'],
      'entity_type' => 'user',
      'bundle' => 'user',
      'settings' => array(
        'user_register_form' => FALSE,
      ),
    );
    field_create_instance($fieldInstance);
    return $field;
  }

  /**
   * Helper to grab the nid from the url so that we don't have to make assumptions
   * about the nid of the node we just created.
   */
  protected function getNidFromCurrentUrl() {
    $url = $this
      ->getUrl();
    $matches = array();
    if (preg_match('/node\\/(\\d+)/', $url, $matches)) {
      return $matches[1];
    }
    return NULL;
  }

  /**
   * Create a list of visitor actions as test fixtures.
   */
  protected function createVisitorActions() {
    $actions = array(
      'acquia_lift_profiles_form_click' => array(
        'machine_name' => 'acquia_lift_profiles_form_click',
        'plugin' => 'link',
        'label' => t('clicks the click-test link'),
        'client_side' => TRUE,
        'pages' => 'node',
        'identifier' => '.click-test',
        'data' => array(),
        'event' => 'click',
      ),
      'acquia_lift_profiles_form_hover' => array(
        'machine_name' => 'acquia_lift_profiles_form_hover',
        'plugin' => 'link',
        'label' => t('hovers over the hover-test link'),
        'client_side' => TRUE,
        'pages' => 'node/1',
        'identifier' => '.hover-test',
        'data' => array(),
        'event' => 'mouseenter',
      ),
    );
    foreach ($actions as $action) {
      visitor_actions_save_action($action);
    }
  }

  /**
   * Helper function to assert that the Acquia Lift Web Admin link is set to a
   * specific href.
   *
   * This can't be tested via the UI because there isn't a way to activate the
   * Acquia Lift menu, but we can all the menu functions to verify that the href
   * is updated as expected.
   *
   * @param $check_href
   */
  protected function assertAcquiaLiftWebAdminLink($check_href) {

    // Make sure we get a new copy of the data each time we assert.
    drupal_static_reset('menu_tree_all_data');
    drupal_static_reset('_menu_build_tree');
    $menu = menu_tree_all_data('acquia-lift-controls');
    foreach ($menu as $link) {
      if ($link['link']['link_path'] === 'http://lift.acquia.com') {
        $this
          ->assertEqual($link['link']['href'], $check_href);
        return;
      }
    }
    $this
      ->assertEqual('Link not found', $check_href);
  }

}

Classes

Namesort descending Description
ALProfilesWebTest Tests Acquia Lift Profiles functionality.