Index: modules/aggregator/aggregator.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.test,v
retrieving revision 1.39
diff -u -p -r1.39 aggregator.test
--- modules/aggregator/aggregator.test	24 Mar 2010 08:51:42 -0000	1.39
+++ modules/aggregator/aggregator.test	23 Jul 2010 15:34:20 -0000
@@ -541,11 +541,11 @@ class ImportOPMLTestCase extends Aggrega
       ->execute();
 
     $this->drupalGet('admin/config/services/aggregator/add/opml');
-    $this->assertText('A single OPML document may contain a collection of many feeds.', t('Looking for help text.'));
-    $this->assertFieldByName('files[upload]', '', t('Looking for file upload field.'));
-    $this->assertFieldByName('remote', '', t('Looking for remote URL field.'));
-    $this->assertFieldByName('refresh', '', t('Looking for refresh field.'));
-    $this->assertFieldByName("category[$cid]", $cid, t('Looking for category field.'));
+    $this->assertText('A single OPML document may contain a collection of many feeds.', t('Found OPML help text.'));
+    $this->assertField('files[upload]', t('Found file upload field.'));
+    $this->assertField('remote', t('Found Remote URL field.'));
+    $this->assertField('refresh', '', t('Found Refresh field.'));
+    $this->assertFieldByName("category[$cid]", $cid, t('Found category field.'));
   }
 
   /**
Index: modules/block/block.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.test,v
retrieving revision 1.54
diff -u -p -r1.54 block.test
--- modules/block/block.test	8 Jul 2010 03:41:27 -0000	1.54
+++ modules/block/block.test	23 Jul 2010 15:31:58 -0000
@@ -254,7 +254,7 @@ class BlockTestCase extends DrupalWebTes
       ':region-class' => 'region region-' . str_replace('_', '-', $region),
       ':block-id' => 'block-' . $block['module'] . '-' . $block['delta'],
     ));
-    $this->assertFieldByXPath($xpath, FALSE, t('Custom block found in %region_name region.', array('%region_name' => $region)));
+    $this->assertFieldByXPath($xpath, NULL, t('Custom block found in %region_name region.', array('%region_name' => $region)));
   }
 
   /**
Index: modules/field/modules/text/text.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.test,v
retrieving revision 1.24
diff -u -p -r1.24 text.test
--- modules/field/modules/text/text.test	28 Jun 2010 20:58:42 -0000	1.24
+++ modules/field/modules/text/text.test	23 Jul 2010 15:31:58 -0000
@@ -211,8 +211,8 @@ class TextFieldTestCase extends DrupalWe
     // Display edition form.
     // We should now have a 'text format' selector.
     $this->drupalGet('test-entity/' . $id . '/edit');
-    $this->assertFieldByName("{$this->field_name}[$langcode][0][value]", '', t('Widget is displayed'));
-    $this->assertFieldByName("{$this->field_name}[$langcode][0][format]", '', t('Format selector is displayed'));
+    $this->assertFieldByName("{$this->field_name}[$langcode][0][value]", NULL, t('Widget is displayed'));
+    $this->assertFieldByName("{$this->field_name}[$langcode][0][format]", NULL, t('Format selector is displayed'));
 
     // Edit and change the text format to the new one that was created.
     $edit = array(
Index: modules/locale/locale.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.test,v
retrieving revision 1.73
diff -u -p -r1.73 locale.test
--- modules/locale/locale.test	26 Jun 2010 19:55:47 -0000	1.73
+++ modules/locale/locale.test	23 Jul 2010 15:31:58 -0000
@@ -1575,12 +1575,12 @@ class LocaleContentFunctionalTest extend
     $this->drupalLogin($web_user);
     $this->drupalGet('node/add/article');
     // Verify language select list is not present.
-    $this->assertNoFieldByName('language', '', t('Language select not present on add article form.'));
+    $this->assertNoFieldByName('language', NULL, t('Language select not present on add article form.'));
 
     // Verify language selection appears on add "Basic page" form.
     $this->drupalGet('node/add/page');
     // Verify language select list is present.
-    $this->assertFieldByName('language', '', t('Language select present on add Basic page form.'));
+    $this->assertFieldByName('language', NULL, t('Language select present on add Basic page form.'));
     // Ensure enabled language appears.
     $this->assertText($name, t('Enabled language present.'));
     // Ensure disabled language doesn't appear.
Index: modules/poll/poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v
retrieving revision 1.353
diff -u -p -r1.353 poll.module
--- modules/poll/poll.module	19 Jul 2010 22:03:48 -0000	1.353
+++ modules/poll/poll.module	23 Jul 2010 15:31:58 -0000
@@ -294,6 +294,7 @@ 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);
     $form['choice_wrapper']['choice'][$key] = _poll_choice_form($key, NULL, '', 0, $weight, $choice_count);
@@ -383,6 +384,7 @@ function poll_more_choices_submit($form,
 function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight = 0, $size = 10) {
   $form = array(
     '#tree' => TRUE,
+    '#weight' => $weight,
   );
 
   // We'll manually set the #parents property of these fields so that
@@ -433,8 +435,8 @@ function poll_choice_js($form, $form_sta
 /**
  * Renumber fields and create a teaser when a poll node is submitted.
  */
-function poll_node_form_submit(&$form, &$form_state) {
-  // Renumber fields
+function poll_node_form_submit($form, &$form_state) {
+  // Renumber fields.
   $form_state['values']['choice'] = array_values($form_state['values']['choice']);
   $form_state['values']['teaser'] = poll_teaser((object) $form_state['values']);
 }
@@ -821,14 +823,14 @@ function theme_poll_choices($variables) 
 
   drupal_add_tabledrag('poll-choice-table', 'order', 'sibling', 'poll-weight');
 
+  $is_admin= user_access('administer nodes');
   $delta = 0;
   $rows = array();
-  $headers = array(
-    '',
-    t('Choice'),
-    t('Vote count'),
-    t('Weight'),
-  );
+  $headers = array('', t('Choice'));
+  if ($is_admin) {
+    $headers[] = t('Vote count');
+  }
+  $headers[] = t('Weight');
 
   foreach (element_children($form) as $key) {
     $delta++;
@@ -840,11 +842,13 @@ function theme_poll_choices($variables) 
       'data' => array(
         array('class' => array('choice-flag')),
         drupal_render($form[$key]['chtext']),
-        drupal_render($form[$key]['chvotes']),
-        drupal_render($form[$key]['weight']),
       ),
       'class' => array('draggable'),
     );
+    if ($is_admin) {
+      $row['data'][] = drupal_render($form[$key]['chvotes']);
+    }
+    $row['data'][] = drupal_render($form[$key]['weight']);
 
     // Add any additional classes set on the row.
     if (!empty($form[$key]['#attributes']['class'])) {
Index: modules/poll/poll.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.test,v
retrieving revision 1.35
diff -u -p -r1.35 poll.test
--- modules/poll/poll.test	23 Jun 2010 19:15:07 -0000	1.35
+++ modules/poll/poll.test	23 Jul 2010 15:31:58 -0000
@@ -11,36 +11,41 @@ class PollTestCase extends DrupalWebTest
   /**
    * Creates a poll.
    *
-   * @param string $title The title of the poll.
-   * @param array $choices Choices.
-   * @param boolean $test_preview Whether to test if the preview is working or not.
-   * @return integer The nid of the created poll, or FALSE on error.
+   * @param string $title
+   *   The title of the poll.
+   * @param array $choices
+   *   A list of choice labels.
+   * @param boolean $preview
+   *   (optional) Whether to test if the preview is working or not. Defaults to
+   *   TRUE.
+   *
+   * @return
+   *   The node id of the created poll, or FALSE on error.
    */
-  function pollCreate($title, $choices, $test_preview = TRUE) {
+  function pollCreate($title, $choices, $preview = TRUE) {
     $this->assertTrue(TRUE, 'Create a poll');
 
     $web_user = $this->drupalCreateUser(array('create poll content', 'access content', 'edit own poll content'));
     $this->drupalLogin($web_user);
 
-    // Get the form first to initialize the state of the internal browser
+    // Get the form first to initialize the state of the internal browser.
     $this->drupalGet('node/add/poll');
 
-    // Prepare a form with two choices
+    // Prepare a form with two choices.
     list($edit, $index) = $this->_pollGenerateEdit($title, $choices);
 
+    // Re-submit the form until all choices are filled in.
     if (count($choices) > 2) {
-      // Re-submit the form while the choices are all in
       while ($index < count($choices)) {
         $this->drupalPost(NULL, $edit, t('More choices'));
+        $this->assertPollChoiceOrder($choices, $index);
         list($edit, $index) = $this->_pollGenerateEdit($title, $choices, $index);
       }
     }
 
-    if ($test_preview) {
+    if ($preview) {
       $this->drupalPost(NULL, $edit, t('Preview'));
-      foreach ($choices as $k => $choice_text) {
-        $this->assertRaw($choice_text, t('Choice @choice found was in preview.', array('@choice' => $k)));
-      }
+      $this->assertPollChoiceOrder($choices, $index, TRUE);
       list($edit, $index) = $this->_pollGenerateEdit($title, $choices, $index);
     }
 
@@ -52,20 +57,42 @@ class PollTestCase extends DrupalWebTest
     return isset($node->nid) ? $node->nid : FALSE;
   }
 
-  function _pollGenerateEdit($title, $choices, $index = 0) {
-    $max_new_choices = $index == 0 ? 2 : 5;
+  /**
+   * Generates POST values for the poll node form, specifically poll choices.
+   *
+   * @param $title
+   *   The title for the poll node.
+   * @param $choices
+   *   An array containing poll choices, as generated by
+   *   PollTestCase::_generateChoices().
+   * @param $index
+   *   (optional) The amount/number of already submitted poll choices. Defaults
+   *   to 0.
+   *
+   * @return
+   *   An indexed array containing:
+   *   - The generated POST values, suitable for
+   *     DrupalWebTestCase::drupalPost().
+   *   - The number of poll choices contained in 'edit', for potential re-usage
+   *     in subsequent invocations of this function.
+   */
+  function _pollGenerateEdit($title, array $choices, $index = 0) {
+    $max_new_choices = ($index == 0 ? 2 : 5);
     $already_submitted_choices = array_slice($choices, 0, $index);
     $new_choices = array_values(array_slice($choices, $index, $max_new_choices));
 
-    $langcode = LANGUAGE_NONE;
     $edit = array(
-      "title" => $title
+      'title' => $title,
     );
     foreach ($already_submitted_choices as $k => $text) {
       $edit['choice[chid:' . $k . '][chtext]'] = $text;
     }
     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));
   }
@@ -78,6 +105,64 @@ class PollTestCase extends DrupalWebTest
     return $choices;
   }
 
+  /**
+   * Assert correct poll choice order in the node form after submission.
+   *
+   * Verifies both the order in the DOM and in the 'weight' form elements.
+   *
+   * @param $choices
+   *   An array containing poll choices, as generated by
+   *   PollTestCase::_generateChoices().
+   * @param $index
+   *   (optional) The amount/number of already submitted poll choices. Defaults
+   *   to 0.
+   * @param $preview
+   *   (optional) Whether to also check the poll preview.
+   *
+   * @see PollTestCase::_pollGenerateEdit()
+   */
+  function assertPollChoiceOrder(array $choices, $index = 0, $preview = FALSE) {
+    $expected = array();
+    foreach ($choices as $id => $label) {
+      if ($id < $index) {
+        // The expected weight of each choice is exactly the negated id.
+        // @see PollTestCase::_pollGenerateEdit()
+        $weight = (- $id);
+        // 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,
+          '@weight' => $weight,
+        )));
+        // Append to our (to be reversed) stack of labels.
+        $expected[$weight] = $label;
+      }
+    }
+    ksort($expected);
+
+    // Verify DOM order of poll choices (i.e., #weight of form elements).
+    $elements = $this->xpath('//input[starts-with(@name, :prefix) and contains(@name, :suffix)]', array(
+      ':prefix' => 'choice[chid:',
+      ':suffix' => '][chtext]',
+    ));
+    $expected_order = $expected;
+    foreach ($elements as $element) {
+      $next_label = array_shift($expected_order);
+      $this->assertEqual((string) $element['value'], $next_label);
+    }
+
+    // If requested, also verify DOM order in preview.
+    if ($preview) {
+      $elements = $this->xpath('//div[contains(@class, "node-teaser")]/descendant::div[@class="text"]');
+      $expected_order = $expected;
+      foreach ($elements as $element) {
+        $next_label = array_shift($expected_order);
+        $this->assertEqual((string) $element, $next_label, t('Found choice @label in preview.', array(
+          '@label' => $next_label,
+        )));
+      }
+    }
+  }
+
   function pollUpdate($nid, $title, $edit) {
     // Edit the poll node.
     $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
@@ -332,7 +417,6 @@ class PollJSAddChoice extends DrupalWebT
     $web_user = $this->drupalCreateUser(array('create poll content', 'access content'));
     $this->drupalLogin($web_user);
     $this->drupalGet('node/add/poll');
-    $langcode = LANGUAGE_NONE;
     $edit = array(
       "title" => $this->randomName(),
       'choice[new:0][chtext]' => $this->randomName(),
@@ -597,33 +681,33 @@ class PollExpirationTestCase extends Pol
     $title = $this->randomName();
     $choices = $this->_generateChoices(2);
     $poll_nid = $this->pollCreate($title, $choices, FALSE);
-    $this->assertTrue($poll_nid, t('Poll for auto-expire test created.'), t('Poll'));
+    $this->assertTrue($poll_nid, t('Poll for auto-expire test created.'));
 
     // Visit the poll edit page and verify that by default, expiration
     // is set to unlimited.
     $this->drupalGet("node/$poll_nid/edit");
-    $this->assertField('runtime', t('Poll expiration setting found.'), t('Poll'));
+    $this->assertField('runtime', t('Poll expiration setting found.'));
     $elements = $this->xpath('//select[@id="edit-runtime"]/option[@selected="selected"]');
-    $this->assertTrue(isset($elements[0]['value']) && $elements[0]['value'] == 0, t('Poll expiration set to unlimited.'), t('Poll'));
+    $this->assertTrue(isset($elements[0]['value']) && $elements[0]['value'] == 0, t('Poll expiration set to unlimited.'));
 
     // Set the expiration to one week.
     $edit = array();
     $poll_expiration = 604800; // One week.
     $edit['runtime'] = $poll_expiration;
     $this->drupalPost(NULL, $edit, t('Save'));
-    $this->assertRaw(t('Poll %title has been updated.', array('%title' => $title)), t('Poll expiration settings saved.'), t('Poll'));
+    $this->assertRaw(t('Poll %title has been updated.', array('%title' => $title)), t('Poll expiration settings saved.'));
 
     // Make sure that the changed expiration settings is kept.
     $this->drupalGet("node/$poll_nid/edit");
     $elements = $this->xpath('//select[@id="edit-runtime"]/option[@selected="selected"]');
-    $this->assertTrue(isset($elements[0]['value']) && $elements[0]['value'] == $poll_expiration, t('Poll expiration set to unlimited.'), t('Poll'));
+    $this->assertTrue(isset($elements[0]['value']) && $elements[0]['value'] == $poll_expiration, t('Poll expiration set to unlimited.'));
 
     // Force a cron run. Since the expiration date has not yet been reached,
     // the poll should remain active.
     drupal_cron_run();
     $this->drupalGet("node/$poll_nid/edit");
     $elements = $this->xpath('//input[@id="edit-active-1"]');
-    $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Poll is still active.'), t('Poll'));
+    $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Poll is still active.'));
 
     // Test expiration. Since REQUEST_TIME is a constant and we don't
     // want to keep SimpleTest waiting until the moment of expiration arrives,
@@ -638,6 +722,6 @@ class PollExpirationTestCase extends Pol
     drupal_cron_run();
     $this->drupalGet("node/$poll_nid/edit");
     $elements = $this->xpath('//input[@id="edit-active-0"]');
-    $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Poll has expired.'), t('Poll'));
+    $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Poll has expired.'));
   }
-}
\ No newline at end of file
+}
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.225
diff -u -p -r1.225 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	19 Jul 2010 21:54:46 -0000	1.225
+++ modules/simpletest/drupal_web_test_case.php	23 Jul 2010 15:31:58 -0000
@@ -2636,20 +2636,21 @@ class DrupalWebTestCase extends DrupalTe
    * @param $xpath
    *   XPath used to find the field.
    * @param $value
-   *   Value of the field to assert.
+   *   (optional) Value of the field to assert.
    * @param $message
-   *   Message to display.
+   *   (optional) Message to display.
    * @param $group
-   *   The group this message belongs to.
+   *   (optional) The group this message belongs to.
+   *
    * @return
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertFieldByXPath($xpath, $value, $message = '', $group = 'Other') {
+  protected function assertFieldByXPath($xpath, $value = NULL, $message = '', $group = 'Other') {
     $fields = $this->xpath($xpath);
 
     // If value specified then check array for match.
     $found = TRUE;
-    if ($value) {
+    if (isset($value)) {
       $found = FALSE;
       if ($fields) {
         foreach ($fields as $field) {
@@ -2708,20 +2709,21 @@ class DrupalWebTestCase extends DrupalTe
    * @param $xpath
    *   XPath used to find the field.
    * @param $value
-   *   Value of the field to assert.
+   *   (optional) Value of the field to assert.
    * @param $message
-   *   Message to display.
+   *   (optional) Message to display.
    * @param $group
-   *   The group this message belongs to.
+   *   (optional) The group this message belongs to.
+   *
    * @return
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertNoFieldByXPath($xpath, $value, $message = '', $group = 'Other') {
+  protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '', $group = 'Other') {
     $fields = $this->xpath($xpath);
 
     // If value specified then check array for match.
     $found = TRUE;
-    if ($value) {
+    if (isset($value)) {
       $found = FALSE;
       if ($fields) {
         foreach ($fields as $field) {
@@ -2883,7 +2885,7 @@ class DrupalWebTestCase extends DrupalTe
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertField($field, $message = '', $group = 'Other') {
-    return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), '', $message, $group);
+    return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message, $group);
   }
 
   /**
@@ -2899,7 +2901,7 @@ class DrupalWebTestCase extends DrupalTe
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertNoField($field, $message = '', $group = 'Other') {
-    return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), '', $message, $group);
+    return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message, $group);
   }
 
   /**
