1.20.x theme.test | ThemeFunctionsTestCase::testItemList() |
Tests theme_item_list().
File
- modules/
simpletest/ tests/ theme.test, line 257 - Tests for the theme API.
Class
- ThemeFunctionsTestCase
- Tests for common theme functions.
Code
function testItemList() {
// Verify that empty variables produce no output.
$variables = array();
$expected = '';
$this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback generates no output.');
$variables = array();
$variables['title'] = 'Some title';
$expected = '';
$this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback with title generates no output.');
// Verify nested item lists.
$variables = array();
$variables['title'] = 'Some title';
$variables['attributes'] = array(
'id' => 'parentlist',
);
$variables['items'] = array(
'a',
array(
'data' => 'b',
'children' => array(
'c',
// Nested children may use additional attributes.
array(
'data' => 'd',
'class' => array('dee'),
),
// Any string key is treated as child list attribute.
'id' => 'childlist',
),
// Any other keys are treated as item attributes.
'id' => 'bee',
),
array(
'data' => 'e',
'id' => 'E',
),
);
$inner = '<div class="item-list"><ul id="childlist">';
$inner .= '<li class="odd first">c</li>';
$inner .= '<li class="dee even last">d</li>';
$inner .= '</ul></div>';
$expected = '<div class="item-list">';
$expected .= '<h3>Some title</h3>';
$expected .= '<ul id="parentlist">';
$expected .= '<li class="odd first">a</li>';
$expected .= '<li id="bee" class="even">b' . $inner . '</li>';
$expected .= '<li id="E" class="odd last">e</li>';
$expected .= '</ul></div>';
$this->assertThemeOutput('item_list', $variables, $expected);
}