Ejemplo n.º 1
0
 /**
  * @covers System_Acl_Loader_Options::load
  * @covers System_Acl_Loader_Options::<protected>
  */
 public function testLoadRoles()
 {
     $this->object->setOptions($this->optionsHelper(System_Acl_Loader_Options::ROLES, array('test' => null, 'test1' => 'test')));
     $this->object->load();
     self::assertTrue($this->acl->hasRole('test'));
     self::assertTrue($this->acl->hasRole('test1'));
     self::assertTrue($this->acl->inheritsRole('test1', 'test', true));
 }
Ejemplo n.º 2
0
 /**
  * @covers System_Acl_Loader_Db::load
  * @covers System_Acl_Loader_Db::<protected>
  */
 public function testLoadRoles()
 {
     $this->createTableMocks('AclResource');
     $this->createTableMocks('AclRule');
     $this->createTableMocks('AclRole', array(array('name' => 'test', 'parent' => null), array('name' => 'test1', 'parent' => 'test')));
     $this->object->load();
     self::assertTrue($this->acl->hasRole('test'));
     self::assertTrue($this->acl->hasRole('test1'));
     self::assertTrue($this->acl->inheritsRole('test1', 'test', true));
 }
Ejemplo n.º 3
0
 /**
  * Ensures that the $onlyParents argument to inheritsRole() works
  *
  * @return void
  * @group  ZF-2502
  */
 public function testRoleInheritanceSupportsCheckingOnlyParents()
 {
     $this->_acl->addRole(new Role\GenericRole('grandparent'))
                ->addRole(new Role\GenericRole('parent'), 'grandparent')
                ->addRole(new Role\GenericRole('child'), 'parent');
     $this->assertFalse($this->_acl->inheritsRole('child', 'grandparent', true));
 }
Ejemplo n.º 4
0
 /**
  * Determines whether a page should be accepted when iterating using ACL
  * 
  * Validates that the role set in helper inherits or is the same as
  * the role(s) found in the page
  * 
  * @return bool
  */
 protected function _acceptAcl(Zym_Navigation_Page $page, $recursive = true)
 {
     // do not accept by default
     $accept = false;
     if (!($helperRole = $this->getRole())) {
         // don't accept if helper has no role
         return false;
     }
     if (!($pageRole = $page->getRole())) {
         // accept it if page has no role
         $accept = true;
     } else {
         // loop all roles
         foreach ($helperRole as $hRole) {
             foreach ($pageRole as $pRole) {
                 if ($hRole == $pRole || $this->_acl->inheritsRole($hRole, $pRole)) {
                     $accept = true;
                     break;
                 }
             }
             if ($accept) {
                 break;
             }
         }
     }
     // loop parent(s) recursively if page is accepted and recurisve is true
     if ($accept && $recursive) {
         $parent = $page->getParent();
         if ($parent instanceof Zym_Navigation_Page) {
             $accept = $this->_acceptAcl($parent, true);
         }
     }
     return $accept;
 }
Ejemplo n.º 5
0
 /**
  * Ensures that an exception is thrown when a non-existent Role is specified to each parameter of inherits()
  *
  * @return void
  */
 public function testRoleRegistryInheritsNonExistent()
 {
     $roleGuest = new Zend_Acl_Role('guest');
     $this->_acl->addRole($roleGuest);
     try {
         $this->_acl->inheritsRole('nonexistent', $roleGuest);
         $this->fail('Expected Zend_Acl_Role_Registry_Exception not thrown upon specifying a non-existent child Role');
     } catch (Zend_Acl_Role_Registry_Exception $e) {
         $this->assertContains('not found', $e->getMessage());
     }
     try {
         $this->_acl->inheritsRole($roleGuest, 'nonexistent');
         $this->fail('Expected Zend_Acl_Role_Registry_Exception not thrown upon specifying a non-existent parent Role');
     } catch (Zend_Acl_Role_Registry_Exception $e) {
         $this->assertContains('not found', $e->getMessage());
     }
 }
Ejemplo n.º 6
0
 public function getDefaultGroup()
 {
     $groups = $this->getActiveStaffGroups();
     $roles = $this->db->fetchPairs('SELECT ggp_role, ggp_id_group FROM gems__groups WHERE ggp_group_active=1 AND ggp_staff_members=1 ORDER BY ggp_name');
     $current = null;
     foreach (array_reverse($this->acl->getRoles()) as $roleId) {
         if (isset($roles[$roleId], $groups[$roles[$roleId]])) {
             if ($current) {
                 if ($this->acl->inheritsRole($current, $roleId)) {
                     $current = $roleId;
                 }
             } else {
                 $current = $roleId;
             }
         }
     }
     if (isset($roles[$current])) {
         return $roles[$current];
     }
 }