summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-01-27 02:14:42 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-01-27 02:14:42 +0000
commitf5a4f24b5e02c82f67d90116356f83a542f5b99f (patch)
tree76f5072081e857b321c6161e44d318c347a60770
parent2e8ca690ff471b1d6604226e8153f401b1827204 (diff)
downloadbrdo-f5a4f24b5e02c82f67d90116356f83a542f5b99f.tar.gz
brdo-f5a4f24b5e02c82f67d90116356f83a542f5b99f.tar.bz2
#364407 by catch: Fix drupal_render() sorting (with tests).
-rw-r--r--includes/common.inc11
-rw-r--r--modules/simpletest/tests/common.test36
2 files changed, 41 insertions, 6 deletions
diff --git a/includes/common.inc b/includes/common.inc
index dd7e58c35..3e5d0c383 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3289,12 +3289,10 @@ function drupal_render(&$elements) {
}
}
- // Sort the elements by weight, if there are any children, and they have not
- // been sorted elsewhere already, for example by a database query. Pre-sorted
- // elements should have $elements['#sorted'] set to TRUE to avoid unnecessary
- // calls to uasort().
- $children = !isset($elements['#children']) ? element_children($elements) : FALSE;
- if (empty($elements['#sorted']) && $children) {
+ // Sort the elements by weight if they have not been sorted elsewhere already,
+ // for example by a database query. Pre-sorted elements should have
+ // $elements['#sorted'] set to TRUE to avoid unnecessary calls to uasort().
+ if (empty($elements['#sorted'])) {
uasort($elements, 'element_sort');
$elements['#sorted'] = TRUE;
}
@@ -3302,6 +3300,7 @@ function drupal_render(&$elements) {
$content = '';
$elements += array('#title' => NULL, '#description' => NULL);
if (!isset($elements['#children'])) {
+ $children = element_children($elements);
// Render all the children that use a theme function.
if (isset($elements['#theme']) && empty($elements['#theme_used'])) {
$elements['#theme_used'] = TRUE;
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 78dc9f769..5f039660f 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -481,6 +481,42 @@ class JavaScriptTestCase extends DrupalWebTestCase {
}
/**
+ * Tests for drupal_render().
+ */
+class DrupalRenderUnitTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Drupal render'),
+ 'description' => t('Performs unit tests on drupal_render().'),
+ 'group' => t('System'),
+ );
+ }
+
+ /**
+ * Test sorting by weight.
+ */
+ function testDrupalRenderSorting() {
+ $first = $this->randomName();
+ $second = $this->randomName();
+ // Build an array with '#weight' set for each element.
+ $elements = array(
+ 'second' => array(
+ '#weight' => 10,
+ '#markup' => $second,
+ ),
+ 'first' => array(
+ '#weight' => 0,
+ '#markup' => $first,
+ ),
+ );
+ $output = drupal_render($elements);
+ // The lowest weight element should appear last in $output.
+ $this->assertTrue(strpos($output, $second) > strpos($output, $first), t('Elements were sorted correctly by weight'));
+ }
+}
+
+
+/**
* Tests Drupal error and exception handlers.
*/
class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {