/** * This method tests the structure of navigation container * * @param string $propertyValue the value of the property for finding page * @param int $childPages if given as a number method will test that the * page has exactly $childPages sons * @param string $parentLabel if given method will test for presence of a * parent page with this label * @param string $propertyName if given method will try to find the given page * by this property instead of by label * * @dataProvider getStructureSampleData * * @return void */ public function testNavigationStructure($propertyValue, $childPages = false, $parentLabel = null, $propertyName = 'label') { $page = $this->_navigation->findOneBy($propertyName, $propertyValue); $this->assertNotNull($page, sprintf("A page with %s set to %s should exists in navigation", ucfirst($propertyName), $propertyValue)); if (is_numeric($childPages)) { $this->assertEquals($childPages, count($page->getPages()), "Page '{$page->label}' should have {$childPages} child pages"); } if ($parentLabel) { $this->assertInstanceOf('Zend_Navigation_Page', $page->getParent(), "Parent page should be a page instance"); $this->assertEquals($parentLabel, $page->getParent()->label, "'{$page->label}' should be son of '{$parentLabel}'"); } }
protected function _initNavigation() { $this->bootstrap('layout'); $this->bootstrap('acl'); $layout = $this->getResource('layout'); $view = $layout->getView(); $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml'); $navigation = new Zend_Navigation($config); $additionalNavigation = Zend_Registry::get('config')->navigation; $menu = $additionalNavigation->monitoring; $subMenu = $menu->enableDisable; $target = ''; if ($subMenu->target) { $target = $subMenu->target; } $navigation->addPage(array('label' => $subMenu->label, 'uri' => $subMenu->uri, 'target' => $target)); $menuPage = $navigation->findOneBy('label', 'Monitoring'); $subMenuPage = $navigation->findOneBy('label', $subMenu->label); $subMenuPage->setParent($menuPage); $pluginAdminConsolePages = array(); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaAdminConsolePages'); foreach ($pluginInstances as $pluginInstance) { foreach ($pluginInstance->getAdminConsolePages() as $pluginAdminConsolePage) { $pluginAdminConsolePages[] = $pluginAdminConsolePage; } } foreach ($pluginAdminConsolePages as $pluginAdminConsolePage) { if (!$pluginAdminConsolePage instanceof KalturaAdminConsolePlugin) { continue; } if (!$pluginAdminConsolePage->accessCheck(Kaltura_AclHelper::getCurrentPermissions())) { continue; } $navigation->addPage(array('label' => $pluginAdminConsolePage->getNavigationActionLabel(), 'controller' => 'plugin', 'action' => get_class($pluginAdminConsolePage))); $subMenuPage = $navigation->findOneBy('label', $pluginAdminConsolePage->getNavigationActionLabel()); $menuPage = null; if ($pluginAdminConsolePage->getNavigationRootLabel()) { $menuPage = $navigation->findOneBy('label', $pluginAdminConsolePage->getNavigationRootLabel()); if (!$menuPage) { $navigation->addPage(array('label' => $pluginAdminConsolePage->getNavigationRootLabel(), 'controller' => 'plugin', 'action' => get_class($pluginAdminConsolePage))); $menuPage = $navigation->findOneBy('label', $pluginAdminConsolePage->getNavigationRootLabel()); } } if ($menuPage) { $subMenuPage->setParent($menuPage); } } $this->checkAclForNavigation($navigation); $view->navigation($navigation); }
public function testRemovePageRecursively() { $container = new Zend_Navigation(array(array('route' => 'foo', 'pages' => array(array('route' => 'bar', 'pages' => array(array('route' => 'baz'))))))); $container->removePage($container->findOneBy('route', 'baz'), true); $this->assertNull($container->findOneBy('route', 'baz')); $container->removePage($container->findOneBy('route', 'bar'), true); $this->assertNull($container->findOneBy('route', 'bar')); }
protected function _initNavigation() { $this->bootstrap('log'); $this->bootstrap('layout'); $this->bootstrap('acl'); $this->bootstrap('session'); $this->bootstrap('plugins'); $layout = $this->getResource('layout'); $view = $layout->getView(); $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml'); $navigation = new Zend_Navigation($config); $baseSettings = $this->getConfig()->settings; if (isset($baseSettings->pluginInterface)) { $pluginInterface = $baseSettings->pluginInterface; $pluginPages = array(); $pluginInstances = KalturaPluginManager::getPluginInstances($pluginInterface); foreach ($pluginInstances as $pluginInstance) { /* @var $pluginInstance KalturaPlugin */ foreach ($pluginInstance->getApplicationPages() as $pluginPage) { $pluginPages[] = $pluginPage; } } foreach ($pluginPages as $pluginPage) { if (!$pluginPage instanceof KalturaApplicationPlugin) { KalturaLog::err("Class [" . get_class($pluginPage) . "] is not instance of KalturaApplicationPlugin"); continue; } $resource = get_class($pluginPage); $acl = Zend_Registry::get('acl'); $acl->addResource(new Zend_Acl_Resource($resource)); if (!$pluginPage->accessCheck(Infra_AclHelper::getCurrentPermissions())) { $acl->deny(Infra_AclHelper::getCurrentRole(), $resource); KalturaLog::err("Class [" . get_class($pluginPage) . "] requires permissions [" . print_r($pluginPage->getRequiredPermissions(), true) . "]"); continue; } if (!$pluginPage->isLoginRequired()) { Infra_AuthPlugin::addToWhitelist('plugin/' . $pluginPage->getNavigationActionName()); } $acl->allow(Infra_AclHelper::getCurrentRole(), $resource); $menuPage = null; if ($pluginPage->getNavigationRootLabel()) { $menuPage = $navigation->findOneBy('label', $pluginPage->getNavigationRootLabel()); if (!$menuPage) { $navigation->addPage(array('label' => $pluginPage->getNavigationRootLabel(), 'controller' => 'plugin', 'action' => get_class($pluginPage))); $menuPage = $navigation->findOneBy('label', $pluginPage->getNavigationRootLabel()); } } $subMenuPage = null; if ($pluginPage->getNavigationActionLabel()) { $subMenuPage = $navigation->findOneBy('label', $pluginPage->getNavigationActionLabel()); if (!$subMenuPage) { $navigation->addPage(array('label' => $pluginPage->getNavigationActionLabel(), 'controller' => 'plugin', 'action' => get_class($pluginPage))); } $subMenuPage = $navigation->findOneBy('label', $pluginPage->getNavigationActionLabel()); } if ($menuPage && $subMenuPage) { $subMenuPage->setParent($menuPage); } } } $this->checkAclForNavigation($navigation); $view->navigation($navigation); }