summaryrefslogtreecommitdiff
path: root/modules/poll/poll.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/poll/poll.test')
-rw-r--r--modules/poll/poll.test89
1 files changed, 89 insertions, 0 deletions
diff --git a/modules/poll/poll.test b/modules/poll/poll.test
index e4a7db848..35d5ed49e 100644
--- a/modules/poll/poll.test
+++ b/modules/poll/poll.test
@@ -457,3 +457,92 @@ class PollVoteCheckHostname extends PollTestCase {
$this->assertTrue(empty($elements), t("%user is not able to vote again.", array('%user' => $this->web_user1->name)));
}
}
+
+/**
+ * Test poll token replacement in strings.
+ */
+class PollTokenReplaceTestCase extends PollTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Poll token replacement',
+ 'description' => 'Generates text using placeholders for dummy content to check poll token replacement.',
+ 'group' => 'Poll',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('poll');
+ }
+
+ /**
+ * Creates a poll, then tests the tokens generated from it.
+ */
+ function testPollTokenReplacement() {
+ global $language;
+
+ // Craete a poll with three choices.
+ $title = $this->randomName();
+ $choices = $this->_generateChoices(3);
+ $poll_nid = $this->pollCreate($title, $choices, FALSE);
+ $this->drupalLogout();
+
+ // Create four users and have each of them vote.
+ $vote_user1 = $this->drupalCreateUser(array('vote on polls', 'access content'));
+ $this->drupalLogin($vote_user1);
+ $edit = array(
+ 'choice' => '1',
+ );
+ $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
+ $this->drupalLogout();
+
+ $vote_user2 = $this->drupalCreateUser(array('vote on polls', 'access content'));
+ $this->drupalLogin($vote_user2);
+ $edit = array(
+ 'choice' => '1',
+ );
+ $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
+ $this->drupalLogout();
+
+ $vote_user3 = $this->drupalCreateUser(array('vote on polls', 'access content'));
+ $this->drupalLogin($vote_user3);
+ $edit = array(
+ 'choice' => '2',
+ );
+ $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
+ $this->drupalLogout();
+
+ $vote_user4 = $this->drupalCreateUser(array('vote on polls', 'access content'));
+ $this->drupalLogin($vote_user4);
+ $edit = array(
+ 'choice' => '3',
+ );
+ $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
+ $this->drupalLogout();
+
+ $poll = node_load($poll_nid, NULL, TRUE);
+
+ // Generate and test sanitized tokens.
+ $tests = array();
+ $tests['[node:poll-votes]'] = 4;
+ $tests['[node:poll-winner]'] = filter_xss($poll->choice[1]['chtext']);
+ $tests['[node:poll-winner-votes]'] = 2;
+ $tests['[node:poll-winner-percent]'] = 50;
+ $tests['[node:poll-duration]'] = format_interval($poll->runtime, 1, $language->language);
+
+ // Test to make sure that we generated something for each token.
+ $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('node' => $poll), array('language' => $language));
+ $this->assertFalse(strcmp($output, $expected), t('Sanitized poll token %token replaced.', array('%token' => $input)));
+ }
+
+ // Generate and test unsanitized tokens.
+ $tests['[node:poll-winner]'] = $poll->choice[1]['chtext'];
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('node' => $poll), array('language' => $language, 'sanitize' => FALSE));
+ $this->assertFalse(strcmp($output, $expected), t('Unsanitized poll token %token replaced.', array('%token' => $input)));
+ }
+ }
+}