You are here

answers_userpoints.test in Answers 7.4

File

answers_userpoints/answers_userpoints.test
View source
<?php

/**
 * @file
 * Tests for answers_userpoints.module.
 */

/**
 * Tests the functionality of the answers_userpoints module admin settings.
 */
class AnswersUserPointsTestCase extends DrupalWebTestCase {

  /**
   * User who asks the question.
   *
   * @var User
   */
  protected $questionUser;

  /**
   * User who answers the question.
   *
   * @var User
   */
  protected $answerUser;

  /**
   * Test getInfo.
   */
  public static function getInfo() {
    return array(
      'name' => 'Answers Userpoints',
      'description' => 'Test Userpoint Answers settings',
      'group' => 'Answers',
    );
  }

  /**
   * Enable modules and create users with specific permissions.
   */
  public function setUp() {
    parent::setUp('answers_userpoints');
    $permissions = array(
      'create answers_question content',
      'create answers_answer content',
    );
    $this->questionUser = $this
      ->drupalCreateUser($permissions);
    $this->answerUser = $this
      ->drupalCreateUser($permissions);
    @userpoints_get_current_points($this->answerUser->uid);
    @userpoints_get_current_points($this->questionUser->uid);
  }

  /**
   * Test Best Answer points for own answer.
   */
  public function testOwnBestAnswer() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "4096 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->assertLink('Best', 0, 'Best Answer link exists');
    $this
      ->clickLink('Best', 0);
    $this
      ->assertEqual(0, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = 2');
    $this
      ->clickLink('Unbest', 0);
    $this
      ->assertEqual(0, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = 0');
  }

  /**
   * Test best answer for other's answer.
   */
  public function testBestAnswer() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->answerUser);
    $this
      ->drupalGet('node/1');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/1');
    $this
      ->assertLink('Best', 0, 'Best Answer link exists');
    $this
      ->clickLink('Best', 0);
    $this
      ->assertEqual(2, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->assertEqual(15, userpoints_get_current_points($this->answerUser->uid), 'Answer author\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
    $this
      ->clickLink('Unbest', 0);
    $this
      ->assertEqual(0, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->assertEqual(0, userpoints_get_current_points($this->answerUser->uid), 'Answer author\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
  }

  /**
   * Tests UpVoting a Question.
   */
  public function testUpVoteQuestion() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->answerUser);
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('1', 0, 'UpVote Question');
    $this
      ->assertEqual(5, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->clickLink('1', 0, 'Cancel UpVote Question');
    $this
      ->assertEqual(0, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
  }

  /**
   * Tests DownVoting a Question.
   */
  public function testDownVoteQuestion() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->answerUser);
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('-1', 0, 'DownVote Question');
    $this
      ->assertEqual(-2, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->assertEqual(0, userpoints_get_current_points($this->answerUser->uid), 'Voter\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
    $this
      ->clickLink('-1', 0, 'Cancel DownVote Question');
    $this
      ->assertEqual(0, userpoints_get_current_points($this->questionUser->uid), 'Question author\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->assertEqual(0, userpoints_get_current_points($this->answerUser->uid), 'Voter\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
  }

  /**
   * Test DownVoting an Answer.
   */
  public function testDownVoteAnswer() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->answerUser);
    $this
      ->drupalGet('node/1');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('-1', 0, 'DownVote Answer');
    $this
      ->assertEqual(-1, userpoints_get_current_points($this->questionUser->uid), 'voter\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->assertEqual(-2, userpoints_get_current_points($this->answerUser->uid), 'Answer author\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
    $this
      ->clickLink('-1', 0, 'Cancel DownVote Answer');
    $this
      ->assertEqual(0, userpoints_get_current_points($this->questionUser->uid), 'voter\'s points = ' . userpoints_get_current_points($this->questionUser->uid));
    $this
      ->assertEqual(0, userpoints_get_current_points($this->answerUser->uid), 'Answer author\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
  }

  /**
   * Tests UpVoting an Answer.
   */
  public function testUpVoteAnswer() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->answerUser);
    $this
      ->drupalGet('node/1');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->questionUser);
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('1', 0, 'UpVote Answer');
    $this
      ->assertEqual(10, userpoints_get_current_points($this->answerUser->uid), 'Answer author\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
    $this
      ->clickLink('1', 0, 'Cancel UpVote Answer');
    $this
      ->assertEqual(0, userpoints_get_current_points($this->answerUser->uid), 'Answer author\'s points = ' . userpoints_get_current_points($this->answerUser->uid));
  }

  /**
   * Confirm that the "Points" awarded can be updated correctly.
   */
  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);
    }
  }

  /**
   * Test !Points translation.
   */
  public function testAnserConfigUserPointTranslation() {
    variable_set(USERPOINTS_TRANS_UCPOINTS, 'TranslatedPoints');
    $this
      ->refreshVariables();
    $big_user = $this
      ->drupalCreateUser(array(
      'administer content types',
    ));
    $this
      ->drupalLogin($big_user);
    $this
      ->drupalGet('admin/config/content/answers');
    $this
      ->assertText(t('!Points settings', userpoints_translation()));
    $this
      ->assertText('TranslatedPoints settings');
  }

  /**
   * Test Enable/Disable rules toggle.
   */
  public function testEnableDisableRules() {
    $big_user = $this
      ->drupalCreateUser(array(
      'administer content types',
    ));
    $this
      ->drupalLogin($big_user);
    $this
      ->drupalGet('admin/config/content/answers');
    $settings = array(
      'rules_voteup_question' => 1,
      'rules_votedown_question' => 1,
      'rules_votedown_question_cost' => 0,
      'rules_voteup_answer' => 1,
      'rules_votedown_answer' => 1,
      'rules_votedown_answer_cost' => 1,
      'rules_best_answer' => 1,
      'rules_best_answer_user' => 1,
      'rules_own_best_answer' => 0,
    );
    $this
      ->drupalPost('admin/config/content/answers', $settings, 'Save configuration');
    $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':
            $this
              ->assertTrue($rule->active, 'UpVote Question rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_question'], 'custom rules_voteup_question =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_voteup_question_cancel':
            $this
              ->assertTrue($rule->active, 'UpVote Question cancel rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_question'] * -1, 'custom rules_voteup_question_cancel =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_votedown_question':
            $this
              ->assertTrue($rule->active, 'DownVote Question author rule enabled.');
            if ($action->settings['operation'] == 'removePoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_question'] * -1, 'custom rules_votedown_question author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'rules_votedown_question_cancel':
            $this
              ->assertTrue($rule->active, 'DownVote Question author cancel rule enabled.');
            if ($action->settings['operation'] == 'deletePoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_question'], 'custom rules_votedown_question_cancel author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'answers_userpoints_votedown_question_voter':
            $this
              ->assertFalse($rule->active, 'DownVote Question voter rule disabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], 0, 'custom answers_userpoints_votedown_question_voter user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_votedown_question_voter_cancel':
            $this
              ->assertFalse($rule->active, 'Cancel DownVote Question voter rule disabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], 0, 'custom answers_userpoints_votedown_question_voter_cancel user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_voteup_answer':
            $this
              ->assertTrue($rule->active, 'UpVote Answer rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_answer'], 'custom rules_voteup_answer = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_voteup_answer_cancel':
            $this
              ->assertTrue($rule->active, 'UpVote Answer cancel rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_answer'] * -1, 'custom rules_voteup_answer_cancel = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_votedown_answer':
            $this
              ->assertTrue($rule->active, 'DownVote Answer rule enabled.');
            if ($action->settings['operation'] == 'deletePoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'] * -1, 'custom rules_votedown_answer author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'answers_userpoints_votedown_answer_cancel':
            $this
              ->assertTrue($rule->active, 'DownVote Answer cancel rule enabled.');
            if ($action->settings['operation'] == 'addPoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'], 'custom answers_userpoints_votedown_answer_cancel author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'answers_userpoints_votedown_answer_voter':
            $this
              ->assertTrue($rule->active, 'DownVote Answer voter rule enabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'] * -1, 'custom rules_votedown_answer author =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_votedown_answer_voter_cancel':
            $this
              ->assertTrue($rule->active, 'DownVote Answer voter cancel rule enabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'], 'custom answers_userpoints_votedown_answer_cancel voter =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_flag_answers_own_best_answer':
            $this
              ->assertFalse($rule->active, 'Own best answer rule disabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], 0, '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
              ->assertFalse($rule->active, 'Cancel Own best answer rule disabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], 0, 'custom answers_userpoints_unflag_answers_own_best_answer user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_flag_answers_best_answer_flagger':
            $this
              ->assertTrue($rule->active, 'Own best answer rule enabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], 1, 'custom answers_userpoints_flag_answers_own_best_answer user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_unflag_answers_best_answer_flagger':
            $this
              ->assertTrue($rule->active, 'Cancel Own best answer rule enabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], -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);
    }
    $settings = array(
      'rules_voteup_question' => 1,
      'rules_votedown_question' => 1,
      'rules_votedown_question_cost' => 0,
      'rules_voteup_answer' => 1,
      'rules_votedown_answer' => 1,
      'rules_votedown_answer_cost' => 1,
      'rules_best_answer' => 1,
      'rules_best_answer_user' => 1,
      'rules_own_best_answer' => 0,
    );
    $this
      ->drupalPost('admin/config/content/answers', $settings, 'Save configuration');
    $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':
            $this
              ->assertTrue($rule->active, 'UpVote Question rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_question'], 'custom rules_voteup_question =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_voteup_question_cancel':
            $this
              ->assertTrue($rule->active, 'UpVote Question cancel rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_question'] * -1, 'custom rules_voteup_question_cancel =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_votedown_question':
            $this
              ->assertTrue($rule->active, 'DownVote Question author rule enabled.');
            if ($action->settings['operation'] == 'removePoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_question'] * -1, 'custom rules_votedown_question author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'rules_votedown_question_cancel':
            $this
              ->assertTrue($rule->active, 'DownVote Question author cancel rule enabled.');
            if ($action->settings['operation'] == 'deletePoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_question'], 'custom rules_votedown_question_cancel author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'answers_userpoints_votedown_question_voter':
            $this
              ->assertFalse($rule->active, 'DownVote Question voter rule disabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], 0, 'custom answers_userpoints_votedown_question_voter user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_votedown_question_voter_cancel':
            $this
              ->assertFalse($rule->active, 'Cancel DownVote Question voter rule disabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], 0, 'custom answers_userpoints_votedown_question_voter_cancel user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_voteup_answer':
            $this
              ->assertTrue($rule->active, 'UpVote Answer rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_answer'], 'custom rules_voteup_answer = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_voteup_answer_cancel':
            $this
              ->assertTrue($rule->active, 'UpVote Answer cancel rule enabled.');
            if ($action->settings['operation'] == 'addPoints' && $action->settings['user:select'] == 'node:author') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_voteup_answer'] * -1, 'custom rules_voteup_answer_cancel = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'rules_votedown_answer':
            $this
              ->assertTrue($rule->active, 'DownVote Answer rule enabled.');
            if ($action->settings['operation'] == 'deletePoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'] * -1, 'custom rules_votedown_answer author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'answers_userpoints_votedown_answer_cancel':
            $this
              ->assertTrue($rule->active, 'DownVote Answer cancel rule disabled.');
            if ($action->settings['operation'] == 'addPoints') {
              if ($action->settings['user:select'] == 'node:author') {
                $this
                  ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'], 'custom answers_userpoints_votedown_answer_cancel author =  ' . $action->settings['points']);
                $rules[$key] = TRUE;
              }
            }
            break;
          case 'answers_userpoints_votedown_answer_voter':
            $this
              ->assertTrue($rule->active, 'DownVote Answer voter rule enabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'] * -1, 'custom rules_votedown_answer author =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_votedown_answer_voter_cancel':
            $this
              ->assertTrue($rule->active, 'DownVote Answer voter cancel rule enabled.');
            if ($action->settings['user:select'] == 'vote:user') {
              $this
                ->assertEqual($action->settings['points'], $settings['rules_votedown_answer'], 'custom answers_userpoints_votedown_answer_cancel voter =  ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_flag_answers_own_best_answer':
            $this
              ->assertFalse($rule->active, 'Own best answer rule disabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], 0, '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
              ->assertFalse($rule->active, 'Cancel Own best answer rule disabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], 0, 'custom answers_userpoints_unflag_answers_own_best_answer user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_flag_answers_best_answer_flagger':
            $this
              ->assertTrue($rule->active, 'Own best answer rule enabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], 1, 'custom answers_userpoints_flag_answers_own_best_answer user = ' . $action->settings['points']);
              $rules[$key] = TRUE;
            }
            break;
          case 'answers_userpoints_unflag_answers_best_answer_flagger':
            $this
              ->assertTrue($rule->active, 'Cancel Own best answer rule enabled.');
            if ($action->settings['user:select'] == 'flagging-user') {
              $this
                ->assertEqual($action->settings['points'], -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);
    }
  }

}

Classes

Namesort descending Description
AnswersUserPointsTestCase Tests the functionality of the answers_userpoints module admin settings.