/** * @param array $itemData * @param int $level * * @return Item */ private function makeConfigItem(array $itemData, $level) { $item = new Item($itemData, $level); if (array_key_exists('children', $itemData)) { $children = $this->makeConfigLevel($itemData['children'], $level + 1); $item->setChildren($children); } return $item; }
public function testRenderMenuItemWithChildren() { $renderer = $this->getMockBuilder('\\Menu\\HtmlRenderer')->getMock(); $renderer->expects(static::exactly(2))->method('renderMenuItem')->willReturn('Item'); $renderer->expects(static::exactly(2))->method('wrapMenuItem')->will(static::returnCallback(function ($data) { return '<b>' . $data . '</b>'; })); $renderer->expects(static::once())->method('wrapMenuLevel')->will(static::returnCallback(function ($data) { return '<p>' . $data . '</p>'; })); $menuGenerator = new MenuGenerator($renderer); $item = new Item(['title' => 'Test title', 'url' => 'Test url'], 0); $children = new ItemCollection(1); $children[] = new Item(['title' => 'Test title 2', 'url' => 'Test url 2'], 1); $item->setChildren($children); $result = $this->invokeMethod($menuGenerator, 'renderMenuItem', [$item]); static::assertEquals('<b>Item<p><b>Item</b></p></b>', $result); }