/** * This method tests the privileges required to see a given link * * @param string $propertyValue the value of the property for finding page * @param string $role the role to test against * @param bool $result expected result * @param string $propertyName if given method will try to find the given page * by this property instead of by label * * @dataProvider getAccessSampleData * * @return void */ public function testNavigationAccess($propertyValue, $role, $result, $propertyName = 'label') { $acl = $this->getNavigationAcl(); if (!$acl) { $this->markTestSkipped('You must override the getAcl method in order to use this test'); } $page = $this->_navigation->findBy($propertyName, $propertyValue); $this->assertNotNull($page, sprintf("A page with %s set to %s should exists in navigation", ucfirst($propertyName), $propertyValue)); $menu = new Zend_View_Helper_Navigation_Menu(); $menu->setRole($role)->setAcl($acl); $this->assertSame($result, $menu->accept($page), "Page with label {$page->label} is not accepted for role " . ($role instanceof Zend_Acl_Role_Interface ? $role->getRoleId() : $role)); }
/** * 判断菜单权限,如果某页面存在至少一个子页面,则显示。 * * @see Zend_View_Helper_Navigation_HelperAbstract::accept() * @param Zend_Navigation_Page $page * @param boolean $recursive * @return boolean */ public function accept(Zend_Navigation_Page $page, $recursive = false) { if (parent::accept($page, $recursive)) { return true; } else { if ($page->isVisible() && $page->hasChildren()) { foreach (new RecursiveIteratorIterator($page, 1) as $childPage) { if ($this->getUseAcl() && $this->_acceptAcl($childPage)) { return true; } } } } return false; }
/** * Overrides the parent function * @param Zend_Navigation_Page $page page to check * @param bool $recursive [optional] if true, page will not * be accepted if it is the * descendant of a page that is not * accepted. Default is true. * @return bool whether page should be accepted */ public function accept(Zend_Navigation_Page $page, $recursive = true) { if ($this->_AclCheckFunction != NULL && is_callable($this->_AclCheckFunction)) { return call_user_func($this->_AclCheckFunction, $page); } else { return parent::accept($page, $recursive); } }