From bc65a2d6aa3cd4083b7553554ceb8eda29227c87 Mon Sep 17 00:00:00 2001 From: Danillo Nunes Date: Wed, 10 Oct 2012 21:59:05 -0300 Subject: [PATCH] Issue #1809836: theme_item_list() is broken when "items" variable is a associative array --- includes/theme.inc | 8 +++++--- modules/simpletest/tests/theme.test | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/includes/theme.inc b/includes/theme.inc index 1f8dfcf..777922f 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -2069,10 +2069,12 @@ function theme_item_list($variables) { if (!empty($items)) { $output .= "<$type" . drupal_attributes($attributes) . '>'; $num_items = count($items); - foreach ($items as $i => $item) { + $i = 0; + foreach ($items as $item) { $attributes = array(); $children = array(); $data = ''; + $i++; if (is_array($item)) { foreach ($item as $key => $value) { if ($key == 'data') { @@ -2093,10 +2095,10 @@ function theme_item_list($variables) { // Render nested list. $data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes)); } - if ($i == 0) { + if ($i == 1) { $attributes['class'][] = 'first'; } - if ($i == $num_items - 1) { + if ($i == $num_items) { $attributes['class'][] = 'last'; } $output .= '' . $data . "\n"; diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index 27a8e47..39a3d1d 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -230,9 +230,25 @@ class ThemeItemListUnitTest extends DrupalWebTestCase { } /** - * Test nested list rendering. + * Test item list rendering. */ - function testNestedList() { + function testItemList() { + $items = array('a', array('data' => 'b', 'children' => array('c' => 'c', 'd' => 'd', 'e' => 'e')), 'f'); + $expected = '
  • a
  • +
  • b
    • c
    • +
    • d
    • +
    • e
    • +
  • +
  • f
  • +
'; + $output = theme('item_list', array('items' => $items)); + $this->assertIdentical($expected, $output, 'Item list is rendered correctly.'); + } + + /** + * Test nested item list rendering. + */ + function testNestedItemList() { $items = array('a', array('data' => 'b', 'children' => array('c', 'd')), 'e'); $expected = '
  • a
  • b
    • c
    • @@ -241,7 +257,7 @@ class ThemeItemListUnitTest extends DrupalWebTestCase {
    • e
    '; $output = theme('item_list', array('items' => $items)); - $this->assertIdentical($expected, $output, 'Nested list is rendered correctly.'); + $this->assertIdentical($expected, $output, 'Nested item list is rendered correctly.'); } } -- 1.7.12.2