public function AnswersUserPointsTestCase::testEnableDisableRules in Answers 7.4
Test Enable/Disable rules toggle.
File
- answers_userpoints/
answers_userpoints.test, line 498 - Tests for answers_userpoints.module.
Class
- AnswersUserPointsTestCase
- Tests the functionality of the answers_userpoints module admin settings.
Code
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);
}
}