matcher = new Matcher(); $this->renderer = $this->createRenderer($this->matcher); } abstract protected function createRenderer(MatcherInterface $matcher); protected function tearDown() { parent::tearDown(); $this->renderer = null; } public function testRenderEmptyRoot() { $menu = new MenuItem('test', new MenuFactory()); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderRootWithAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->setChildrenAttributes(array('class' => 'test_class')); $menu->addChild('c1'); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderEncodedAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->setChildrenAttributes(array('title' => 'encode " me >')); $menu->addChild('c1'); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLink() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('uri' => '/about')); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLinkWithAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('uri' => '/about', 'linkAttributes' => array('title' => 'About page'))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLinkWithEmptyAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array( 'uri' => '/about', 'linkAttributes' => array('title' => '', 'rel' => null, 'target' => false) )); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLinkWithSpecialAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('uri' => '/about', 'linkAttributes' => array('title' => true))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderChildrenWithAttributes() { $menu = new MenuItem('test', new MenuFactory()); $about = $menu->addChild('About'); $about->addChild('Us'); $about->setChildrenAttribute('title', 'About page'); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderChildrenWithEmptyAttributes() { $menu = new MenuItem('test', new MenuFactory()); $about = $menu->addChild('About'); $about->addChild('Us'); $about->setChildrenAttribute('title', ''); $about->setChildrenAttribute('rel', null); $about->setChildrenAttribute('target', false); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderChildrenWithSpecialAttributes() { $menu = new MenuItem('test', new MenuFactory()); $about = $menu->addChild('About'); $about->addChild('Us'); $about->setChildrenAttribute('title', true); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLabelWithAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('labelAttributes' => array('title' => 'About page'))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLabelWithEmptyAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('labelAttributes' => array('title' => '', 'rel' => null, 'target' => false))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderLabelWithSpecialAttributes() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('labelAttributes' => array('title' => true))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderWeirdLink() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('uri' => 'http://en.wikipedia.org/wiki/%22Weird_Al%22_Yankovic?v1=1&v2=2')); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderEscapedLabel() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('label' => 'Encode " me')); $menu->addChild('Safe', array('label' => 'Encode " me again', 'extras' => array('safe_label' => true))); $menu->addChild('Escaped', array('label' => 'Encode " me too', 'extras' => array('safe_label' => false))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderSafeLabel() { $menu = new MenuItem('test', new MenuFactory()); $menu->addChild('About', array('label' => 'Encode " me')); $menu->addChild('Safe', array('label' => 'Encode " me again', 'extras' => array('safe_label' => true))); $menu->addChild('Escaped', array('label' => 'Encode " me too', 'extras' => array('safe_label' => false))); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu, array('allow_safe_labels' => true))); } public function testRenderWholeMenu() { $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu)); } public function testRenderWithClassAndTitle() { $this->pt2->setAttribute('class', 'parent2_class'); $this->pt2->setAttribute('title', 'parent2 title'); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu)); } public function testRenderWithCurrentItem() { $this->ch2->setCurrent(true); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu)); } public function testRenderWithCurrentItemAsLink() { $menu = new MenuItem('test', new MenuFactory()); $about = $menu->addChild('About', array('uri' => '/about')); $about->setCurrent(true); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu)); } public function testRenderWithCurrentItemNotAsLink() { $menu = new MenuItem('test', new MenuFactory()); $about = $menu->addChild('About', array('uri' => '/about')); $about->setCurrent(true); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($menu, array('currentAsLink' => false))); } public function testRenderSubMenuPortionWithClassAndTitle() { $this->pt2->setChildrenAttribute('class', 'parent2_class')->setChildrenAttribute('title', 'parent2 title'); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu['Parent 2'])); } public function testDoNotShowChildrenRendersNothing() { $this->menu->setDisplayChildren(false); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu)); } public function testDoNotShowChildChildrenRendersPartialMenu() { $this->menu['Parent 1']->setDisplayChildren(false); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu)); } public function testDoNotShowChildRendersPartialMenu() { $this->menu['Parent 1']->setDisplay(false); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu)); } public function testDepth0() { $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 0))); } public function testDepth1() { $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 1))); } public function testDepth2() { $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 2))); } public function testDepth2WithNotShowChildChildren() { $this->menu['Parent 1']->setDisplayChildren(false); $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 2))); } public function testEmptyUncompressed() { $rendered = ''; $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 0, 'compressed' => false))); } }