view = new Zend_View();
$this->helper = new Zend_View_Helper_HtmlList();
$this->helper->setView($this->view);
}
public function tearDown()
{
unset($this->helper);
}
public function testMakeUnorderedList()
{
$items = array('one', 'two', 'three');
$list = $this->helper->htmlList($items);
$this->assertContains('
', $list);
$this->assertContains('
', $list);
foreach ($items as $item) {
$this->assertContains('' . $item . '', $list);
}
}
public function testMakeOrderedList()
{
$items = array('one', 'two', 'three');
$list = $this->helper->htmlList($items, true);
$this->assertContains('', $list);
$this->assertContains('
', $list);
foreach ($items as $item) {
$this->assertContains('' . $item . '', $list);
}
}
public function testMakeUnorderedListWithAttribs()
{
$items = array('one', 'two', 'three');
$attribs = array('class' => 'selected', 'name' => 'list');
$list = $this->helper->htmlList($items, false, $attribs);
$this->assertContains('assertContains('class="selected"', $list);
$this->assertContains('name="list"', $list);
$this->assertContains('
', $list);
foreach ($items as $item) {
$this->assertContains('' . $item . '', $list);
}
}
public function testMakeOrderedListWithAttribs()
{
$items = array('one', 'two', 'three');
$attribs = array('class' => 'selected', 'name' => 'list');
$list = $this->helper->htmlList($items, true, $attribs);
$this->assertContains('assertContains('class="selected"', $list);
$this->assertContains('name="list"', $list);
$this->assertContains('
', $list);
foreach ($items as $item) {
$this->assertContains('' . $item . '', $list);
}
}
/*
* @group ZF-5018
*/
public function testMakeNestedUnorderedList()
{
$items = array('one', array('four', 'five', 'six'), 'two', 'three');
$list = $this->helper->htmlList($items);
$this->assertContains('' . Zend_View_Helper_HtmlList::EOL, $list);
$this->assertContains('
' . Zend_View_Helper_HtmlList::EOL, $list);
$this->assertContains('one' . Zend_View_Helper_HtmlList::EOL.'- four', $list);
$this->assertContains('
- six
' . Zend_View_Helper_HtmlList::EOL . '
' .
Zend_View_Helper_HtmlList::EOL . '' . Zend_View_Helper_HtmlList::EOL . 'two', $list);
}
/*
* @group ZF-5018
*/
public function testMakeNestedDeepUnorderedList()
{
$items = array('one', array('four', array('six', 'seven', 'eight'), 'five'), 'two', 'three');
$list = $this->helper->htmlList($items);
$this->assertContains('' . Zend_View_Helper_HtmlList::EOL, $list);
$this->assertContains('
' . Zend_View_Helper_HtmlList::EOL, $list);
$this->assertContains('one' . Zend_View_Helper_HtmlList::EOL . '- four', $list);
$this->assertContains('
- four
' . Zend_View_Helper_HtmlList::EOL . '- six', $list);
$this->assertContains('
- five
' . Zend_View_Helper_HtmlList::EOL . '
' .
Zend_View_Helper_HtmlList::EOL . ' ' . Zend_View_Helper_HtmlList::EOL . '- two', $list);
}
public function testListWithValuesToEscapeForZF2283()
{
$items = array('one test', 'second & third', 'And \'some\' "final" test');
$list = $this->helper->htmlList($items);
$this->assertContains('
', $list);
$this->assertContains('
', $list);
$this->assertContains('- one <small> test
', $list);
$this->assertContains('- second & third
', $list);
$this->assertContains('- And \'some\' "final" test
', $list);
}
public function testListEscapeSwitchedOffForZF2283()
{
$items = array('one small test');
$list = $this->helper->htmlList($items, false, false, false);
$this->assertContains('', $list);
$this->assertContains('
', $list);
$this->assertContains('- one small test
', $list);
}
/**
* @group ZF-2527
*/
public function testEscapeFlagHonoredForMultidimensionalLists()
{
$items = array('one', array('four', 'five', 'six'), 'two', 'three');
$list = $this->helper->htmlList($items, false, false, false);
foreach ($items[1] as $item) {
$this->assertContains($item, $list);
}
}
/**
* @group ZF-2527
* Added the s modifier to match newlines after @see ZF-5018
*/
public function testAttribsPassedIntoMultidimensionalLists()
{
$items = array('one', array('four', 'five', 'six'), 'two', 'three');
$list = $this->helper->htmlList($items, false, array('class' => 'foo'));
foreach ($items[1] as $item) {
$this->assertRegexp('#]*?class="foo"[^>]*>.*?(- ' . $item . ')#s', $list);
}
}
/**
* @group ZF-2870
*/
/*public function testEscapeFlagShouldBePassedRecursively()
{
$items = array(
'one',
array(
'four',
'five',
'six',
array(
'two',
'three',
),
),
);
$list = $this->helper->htmlList($items, false, false, false);
$this->assertContains('
', $list);
$this->assertContains('
', $list);
$this->markTestSkipped('Wrong array_walk_recursive behavior.');
array_walk_recursive($items, array($this, 'validateItems'), $list);
}*/
public function validateItems($value, $key, $userdata)
{
$this->assertContains(' - ' . $value, $userdata);
}
}
// Call Zend_View_Helper_HtmlListTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_HtmlListTest::main") {
Zend_View_Helper_HtmlListTest::main();
}