diff options
Diffstat (limited to 'modules/poll/poll.test')
-rw-r--r-- | modules/poll/poll.test | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/modules/poll/poll.test b/modules/poll/poll.test index d7648a6ba..f5c93b288 100644 --- a/modules/poll/poll.test +++ b/modules/poll/poll.test @@ -24,8 +24,9 @@ class PollTestCase extends DrupalWebTestCase { function pollCreate($title, $choices, $preview = TRUE) { $this->assertTrue(TRUE, 'Create a poll'); + $admin_user = $this->drupalCreateUser(array('create poll content', 'administer nodes')); $web_user = $this->drupalCreateUser(array('create poll content', 'access content', 'edit own poll content')); - $this->drupalLogin($web_user); + $this->drupalLogin($admin_user); // Get the form first to initialize the state of the internal browser. $this->drupalGet('node/add/poll'); @@ -33,6 +34,18 @@ class PollTestCase extends DrupalWebTestCase { // Prepare a form with two choices. list($edit, $index) = $this->_pollGenerateEdit($title, $choices); + // Verify that the vote count element only allows non-negative integers. + $edit['choice[new:1][chvotes]'] = -1; + $edit['choice[new:0][chvotes]'] = $this->randomString(7); + $this->drupalPost(NULL, $edit, t('Save')); + $this->assertText(t('Negative values are not allowed.')); + $this->assertText(t('Vote count for new choice must be an integer.')); + + // Repeat steps for initializing the state of the internal browser. + $this->drupalLogin($web_user); + $this->drupalGet('node/add/poll'); + list($edit, $index) = $this->_pollGenerateEdit($title, $choices); + // Re-submit the form until all choices are filled in. if (count($choices) > 2) { while ($index < count($choices)) { @@ -88,10 +101,6 @@ class PollTestCase extends DrupalWebTestCase { } foreach ($new_choices as $k => $text) { $edit['choice[new:' . $k . '][chtext]'] = $text; - // To test poll choice weights, every new choice is sorted in front of - // existing choices. Existing/already submitted choices should keep their - // weight. - $edit['choice[new:' . $k . '][weight]'] = (- $index - $k); } return array($edit, count($already_submitted_choices) + count($new_choices)); } @@ -122,11 +131,11 @@ class PollTestCase extends DrupalWebTestCase { */ function assertPollChoiceOrder(array $choices, $index = 0, $preview = FALSE) { $expected = array(); + $weight = 0; foreach ($choices as $id => $label) { if ($id < $index) { - // The expected weight of each choice is exactly the negated id. - // @see PollTestCase::_pollGenerateEdit() - $weight = -$id; + // The expected weight of each choice is higher than the previous one. + $weight++; // Directly assert the weight form element value for this choice. $this->assertFieldByName('choice[chid:' . $id . '][weight]', $weight, t('Found choice @id with weight @weight.', array( '@id' => $id, @@ -205,11 +214,12 @@ class PollCreateTestCase extends PollTestCase { $new_option = $this->randomName(); + $vote_count = '2000'; $node->choice[] = array( 'chid' => '', 'chtext' => $new_option, - 'chvotes' => 0, - 'weight' => 0, + 'chvotes' => (int) $vote_count, + 'weight' => 1000, ); node_save($node); @@ -217,6 +227,12 @@ class PollCreateTestCase extends PollTestCase { $this->drupalGet('poll'); $this->clickLink($title); $this->assertText($new_option, 'New option found.'); + + $option = $this->xpath('//div[@id="node-1"]//div[@class="poll"]//div[@class="text"]'); + $this->assertEqual(end($option), $new_option, 'Last item is equal to new option.'); + + $votes = $this->xpath('//div[@id="node-1"]//div[@class="poll"]//div[@class="percent"]'); + $this->assertTrue(strpos(end($votes), $vote_count) > 0, t("Votes saved.")); } function testPollClose() { |