You are here

public function AnswersUserPointsTestCase::testAdminConfig in Answers 7.4

Confirm that the "Points" awarded can be updated correctly.

File

answers_userpoints/answers_userpoints.test, line 233
Tests for answers_userpoints.module.

Class

AnswersUserPointsTestCase
Tests the functionality of the answers_userpoints module admin settings.

Code

public function testAdminConfig() {
  $big_user = $this
    ->drupalCreateUser(array(
    'administer content types',
  ));
  $this
    ->drupalLogin($big_user);
  $this
    ->drupalGet('admin/config/content/answers');
  $this
    ->assertResponse(200);
  $this
    ->assertNoDuplicateIds('There are no duplicate IDs');
  $this
    ->assertFieldByName('rules_voteup_question', '5', 'The Voteup-question default points.');
  $this
    ->assertFieldByName('rules_votedown_question', '2', 'The Votedown-question cost default points.');
  $this
    ->assertFieldByName('rules_votedown_question_cost', '0', 'The Votedown-question cost default points.');
  $this
    ->assertFieldByName('rules_voteup_answer', '10', 'The Voteup-answer default points.');
  $this
    ->assertFieldByName('rules_votedown_answer', '2', 'The Votedown-answer cost default points.');
  $this
    ->assertFieldByName('rules_votedown_answer_cost', '1', 'The Votedown-answer cost default points.');
  $this
    ->assertFieldByName('rules_best_answer', '15', 'The Best Answer default points.');
  $this
    ->assertFieldByName('rules_best_answer_user', '2', 'The Best Answer questioner default points.');
  $this
    ->assertFieldByName('rules_own_best_answer', '0', 'The Best Answer own default points.');
  $edit = array(
    'rules_voteup_question' => '50',
    'rules_votedown_question' => '20',
    'rules_votedown_question_cost' => '10',
    'rules_voteup_answer' => '100',
    'rules_votedown_answer' => '25',
    'rules_votedown_answer_cost' => '15',
    'rules_best_answer' => '150',
    'rules_best_answer_user' => '30',
    'rules_own_best_answer' => '2',
  );
  $this
    ->drupalPost('admin/config/content/answers', $edit, 'Save configuration');
  $this
    ->assertFieldByName('rules_voteup_question', $edit['rules_voteup_question'], 'The Voteup-question custom points.');
  $this
    ->assertFieldByName('rules_votedown_question', $edit['rules_votedown_question'], 'The Votedown-question cost custom points.');
  $this
    ->assertFieldByName('rules_votedown_question_cost', $edit['rules_votedown_question_cost'], 'The Votedown-question cost default points.');
  $this
    ->assertFieldByName('rules_voteup_answer', $edit['rules_voteup_answer'], 'The Voteup-answer custom points.');
  $this
    ->assertFieldByName('rules_votedown_answer', $edit['rules_votedown_answer'], 'The Votedown-answer cost custom points.');
  $this
    ->assertFieldByName('rules_votedown_answer_cost', $edit['rules_votedown_answer_cost'], 'The Votedown-answer cost custom points.');
  $this
    ->assertFieldByName('rules_best_answer', $edit['rules_best_answer'], 'The Best Answer custom points.');
  $this
    ->assertFieldByName('rules_best_answer_user', $edit['rules_best_answer_user'], 'The Best Answer questioner custom points.');
  $this
    ->assertFieldByName('rules_own_best_answer', $edit['rules_own_best_answer'], 'The Best Answer own custom points.');
  $rules = array(
    'rules_voteup_question' => FALSE,
    'rules_voteup_question_cancel' => FALSE,
    'rules_votedown_question' => FALSE,
    'rules_votedown_question_cancel' => FALSE,
    'answers_userpoints_votedown_question_voter' => FALSE,
    'answers_userpoints_votedown_question_voter_cancel' => FALSE,
    'rules_voteup_answer' => FALSE,
    'rules_voteup_answer_cancel' => FALSE,
    'rules_votedown_answer' => FALSE,
    'answers_userpoints_votedown_answer_cancel' => FALSE,
    'answers_userpoints_votedown_answer_voter' => FALSE,
    'answers_userpoints_votedown_answer_voter_cancel' => FALSE,
    'answers_userpoints_flag_answers_best_answer_flagger' => FALSE,
    'answers_userpoints_unflag_answers_best_answer_flagger' => FALSE,
    'answers_userpoints_flag_answers_own_best_answer' => FALSE,
    'answers_userpoints_unflag_answers_own_best_answer' => FALSE,
  );

  // Reset internal cache.
  entity_load('rules_config', array(), array(), TRUE);
  foreach ($rules as $key => $value) {
    $rule = rules_config_load($key);
    foreach ($rule
      ->actions() as $action) {
      switch ($key) {
        case 'rules_voteup_question':
          if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_voteup_question'], 'custom rules_voteup_question =  ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'rules_voteup_question_cancel':
          if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_voteup_question'] * -1, 'custom rules_voteup_question_cancel =  ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'rules_votedown_question':
          if ($action->settings['operation'] == 'removePoints') {
            if ($action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $edit['rules_votedown_question'] * -1, 'custom rules_votedown_question author =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
          }
          break;
        case 'rules_votedown_question_cancel':
          if ($action->settings['operation'] == 'deletePoints') {
            if ($action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $edit['rules_votedown_question'], 'custom rules_votedown_question_cancel author =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
          }
          break;
        case 'answers_userpoints_votedown_question_voter':
          if ($action->settings['user:select'] == 'vote:user') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_votedown_question_cost'] * -1, 'custom rules_votedown_question voter =  ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'answers_userpoints_votedown_question_voter_cancel':
          if ($action->settings['user:select'] == 'vote:user') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_votedown_question_cost'], 'custom rules_votedown_question_cancel voter =  ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'rules_voteup_answer':
          if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_voteup_answer'], 'custom rules_voteup_answer = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'rules_voteup_answer_cancel':
          if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_voteup_answer'] * -1, 'custom rules_voteup_answer_cancel = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'rules_votedown_answer':
          if ($action->settings['operation'] == 'deletePoints') {
            if ($action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $edit['rules_votedown_answer'] * -1, 'custom rules_votedown_answer author =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
          }
          break;
        case 'answers_userpoints_votedown_answer_cancel':
          if ($action->settings['operation'] == 'addPoints') {
            if ($action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $edit['rules_votedown_answer'], 'custom answers_userpoints_votedown_answer_cancel author =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
          }
          break;
        case 'answers_userpoints_votedown_answer_voter':
          if ($action->settings['operation'] == 'deletePoints') {
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], $edit['rules_votedown_answer_cost'] * -1, 'custom rules_votedown_answer voter =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
          }
          break;
        case 'answers_userpoints_votedown_answer_voter_cancel':
          if ($action->settings['operation'] == 'addPoints') {
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], $edit['rules_votedown_answer_cost'], 'custom answers_userpoints_votedown_answer_cancel voter =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
          }
          break;
        case 'rules_flag_answers_best_answer':
          if ($action->settings['user:select'] == 'flagged-node:author') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_best_answer'], 'custom rules_flag_answers_best_answer author = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'rules_unflag_answers_best_answer':
          if ($action->settings['user:select'] == 'flagged-node:author') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_best_answer'] * -1, 'custom rules_unflag_answers_best_answer author = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'answers_userpoints_flag_answers_best_answer_flagger':
          $this
            ->assertTrue($rule->active, 'Flagger Best Answer rule enabled.');
          if ($action->settings['user:select'] == 'flagging-user') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_best_answer_user'], 'custom answers_userpoints_flag_answers_best_answer_flagger user = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'answers_userpoints_unflag_answers_best_answer_flagger':
          $this
            ->assertTrue($rule->active, 'Cancel flagger Best Answer rule enabled.');
          if ($action->settings['user:select'] == 'flagging-user') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_best_answer_user'] * -1, 'custom answers_userpoints_unflag_answers_best_answer_flagger user = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'answers_userpoints_flag_answers_own_best_answer':
          $this
            ->assertTrue($rule->active, 'Cancel Own best answer rule enabled.');
          if ($action->settings['user:select'] == 'flagging-user') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_own_best_answer'], 'custom answers_userpoints_flag_answers_own_best_answer user = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
        case 'answers_userpoints_unflag_answers_own_best_answer':
          $this
            ->assertTrue($rule->active, 'Cancel Own best answer rule enabled.');
          if ($action->settings['user:select'] == 'flagging-user') {
            $this
              ->assertEqual($action->settings['points'], $edit['rules_own_best_answer'] * -1, 'custom answers_userpoints_unflag_answers_own_best_answer user = ' . $action->settings['points']);
            $rules[$key] = TRUE;
          }
          break;
      }
    }
  }
  foreach ($rules as $key => $value) {
    $this
      ->assertTrue($value, $key);
  }
}