Issue #1274212 by amateescu, c31ck | vitalsouto: Fixed Incorrect order of choices in the Poll.

8.0.x
catch 2012-01-07 17:42:09 +09:00
parent 82d39d625c
commit ca17fa3817
2 changed files with 5 additions and 8 deletions

View File

@ -288,9 +288,10 @@ function poll_form($node, &$form_state) {
// Add initial or additional choices.
$existing_delta = $delta;
$weight++;
for ($delta; $delta < $choice_count; $delta++) {
$key = 'new:' . ($delta - $existing_delta);
// Increase the weight of each new choice.
$weight++;
$form['choice_wrapper']['choice'][$key] = _poll_choice_form($key, NULL, '', 0, $weight, $choice_count);
}

View File

@ -101,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));
}
@ -135,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,