You are here

public function AcquiaLiftWebTestConfig::testConfigForm in Acquia Lift Connector 7

File

tests/acquia_lift.test, line 393
Integration tests for Acquia Lift module.

Class

AcquiaLiftWebTestConfig

Code

public function testConfigForm() {
  $this
    ->drupalLogin($this->adminUser);

  // Try entering an invalid owner code.
  $edit = array(
    'acquia_lift_account_info[owner_code]' => 'some invalid string',
    'acquia_lift_account_info[api_key]' => $this->liftAPIKey,
    'acquia_lift_account_info[admin_key]' => $this->liftAdminKey,
    'acquia_lift_account_info[api_url]' => $this->liftAPIUrl,
  );
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertText('You must enter a valid owner code');

  // Now try with a valid code.
  $edit['acquia_lift_account_info[owner_code]'] = $this->liftAOwnerCode;
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertNoText('You must enter a valid owner code');
  $account_info = variable_get('acquia_lift_account_info', array());
  $this
    ->assertEqual($account_info['owner_code'], $this->liftAOwnerCode);
  $this
    ->assertEqual($account_info['api_key'], $this->liftAPIKey);
  $this
    ->assertEqual($account_info['admin_key'], $this->liftAdminKey);
  $this
    ->assertEqual($account_info['api_url'], 'some.valid.url');

  // Try entering an invalid API url.
  $edit['acquia_lift_account_info[api_url]'] = 'some\\invalid\\url';
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertText('You must enter a valid URL');

  // Try a valid URL with no scheme.
  $edit['acquia_lift_account_info[api_url]'] = 'some.valid.url';
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertNoText('You must enter a valid URL');

  // Try a valid URL with scheme.
  $edit['acquia_lift_account_info[api_url]'] = 'https://some.valid.url';
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertNoText('You must enter a valid URL');
  $this
    ->resetAll();
  $account_info = variable_get('acquia_lift_account_info', array());

  // The scheme should have been stripped out before saving.
  $this
    ->assertEqual($account_info['api_url'], 'some.valid.url');

  // Submit bogus confidence measures.
  $bad_measures = array(
    'abcd' => t('Confidence measure must be a number.'),
    145 => t('Confidence measure must be a value between 0 and 100.'),
    -45 => t('Confidence measure must be a value between 0 and 100.'),
  );
  foreach ($bad_measures as $measure => $message) {
    $edit['acquia_lift_confidence_measure'] = $measure;
    $this
      ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
      ->getButton('config'));
    $this
      ->assertText($message);
    $this
      ->assertNoText(t('A minimum confidence measure of 80% is recommended to ensure proper evaluation of test results.'));
    $this
      ->assertNoText(t('The configuration options have been saved.'));
  }

  // Submit a low confidence measure and test warning.
  $edit['acquia_lift_confidence_measure'] = '10';
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertText(t('A minimum confidence measure of 95% is recommended to ensure proper evaluation of test results.'));
  $this
    ->assertText(t('The configuration options have been saved.'));

  // Submit a valid measure and confirm it is saved without warning.
  $edit['acquia_lift_confidence_measure'] = '95';
  $this
    ->drupalPost('admin/config/content/personalize/acquia_lift', $edit, $this
    ->getButton('config'));
  $this
    ->assertNoText(t('A minimum confidence measure of 95% is recommended to ensure proper evaluation of test results.'));
  $this
    ->assertText(t('The configuration options have been saved.'));
}