Exemplo n.º 1
0
 public function testGetPlugin()
 {
     $this->assertFalse($this->chain->hasPlugins());
     /* @var $plugin_first \PHPUnit_Framework_MockObject_MockObject|PluginInterface */
     $plugin_first = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Plugin\\PluginInterface');
     $plugin_first->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('foo first'));
     $plugin_first->expects($this->once())->method('getTitle')->will($this->returnValue('bar first'));
     $this->chain->addPlugin($plugin_first);
     /* @var $plugin_second \PHPUnit_Framework_MockObject_MockObject|PluginInterface */
     $plugin_second = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Plugin\\PluginInterface');
     $plugin_second->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('foo second'));
     $plugin_second->expects($this->once())->method('getTitle')->will($this->returnValue('bar second'));
     $this->chain->addPlugin($plugin_second);
     $this->assertTrue($this->chain->hasPlugins());
     $this->assertEquals(['foo first', 'foo second'], $this->chain->getNames());
     $this->assertEquals(['foo first' => 'bar first', 'foo second' => 'bar second'], $this->chain->getTitles());
     $this->assertEquals(['foo first' => $plugin_first, 'foo second' => $plugin_second], $this->chain->getPlugins());
     $this->assertEquals($plugin_first, $this->chain->getPlugin('foo first'));
     $this->assertEquals($plugin_second, $this->chain->getPlugin('foo second'));
     $this->assertNull($this->chain->getPlugin('baz'));
 }
Exemplo n.º 2
0
 /**
  * @param Chain $chain
  * @param ItemInterface $root
  * @param string $label
  * @param string|null $title
  * @param string|null $class
  */
 private function addPluginItems(Chain $chain, ItemInterface $root, $label, $title = '', $class = '')
 {
     if ($chain->hasPlugins()) {
         $group = $root->addChild($label);
         if ($title) {
             $group->setAttribute('title', $this->translator->trans($title));
         }
         if ($class) {
             $group->setLabelAttribute('class', $class);
         }
         // add child items
         foreach ($chain->getPlugins() as $plugin) {
             if ($plugin instanceof PluginInMenuInterface) {
                 $plugin->buildMenu($group);
             }
         }
     }
 }