You are here

function ALProfilesWebTest::testFieldMappings in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift_profiles/tests/acquia_lift_profiles.test \ALProfilesWebTest::testFieldMappings()

File

acquia_lift_profiles/tests/acquia_lift_profiles.test, line 332
Tests for Acquia Lift Profiles module.

Class

ALProfilesWebTest
Tests Acquia Lift Profiles functionality.

Code

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']);
}