/** * testPopulate * * @covers \RcmUser\Acl\Entity\AclRole::populate * * @return void */ public function testPopulate() { $aclRole = new AclRole(); $parentAclRole = new AclRole(); $parentAclRole->setRoleId('ppp'); $aclRoleA = ['roleId' => 'arrayrolea', 'parentRoleId' => 'ppp', 'description' => 'arrayRoleA', 'parentRole' => $parentAclRole]; $aclRoleB = new AclRole(); $parentAclRoleB = new AclRole(); $parentAclRoleB->setRoleId('pppb'); $aclRoleB->setRoleId('roleb'); $aclRoleB->setParentRoleId('pppb'); $aclRoleB->setDescription('roleb'); $aclRoleB->setParentRole($parentAclRoleB); $aclRoleC = 'wrong format'; $aclRole->populate($aclRoleA); $this->assertTrue($aclRole->getRoleId() === 'arrayrolea', 'Setter or getter failed.'); $aclRole->populate($aclRoleB); $this->assertTrue($aclRole->getRoleId() === 'roleb', 'Setter or getter failed.'); try { $aclRole->populate($aclRoleC); } catch (RcmUserException $e) { $this->assertInstanceOf('\\RcmUser\\Exception\\RcmUserException', $e); return; } $this->fail("Expected exception not thrown"); }
/** * populate * * @param array|AclRole $data data to populate with * * @return void * @throws RcmUserException */ public function populate($data = []) { if ($data instanceof AclRole) { $this->setRoleId($data->getRoleId()); $this->setDescription($data->getDescription()); $this->setParentRoleId($data->getParentRoleId()); $parentRole = $data->getParentRole(); if (!empty($parentRole)) { $this->setParentRole($parentRole); } return; } if (is_array($data)) { if (isset($data['roleId'])) { $this->setRoleId($data['roleId']); } if (isset($data['description'])) { $this->setDescription($data['description']); } if (isset($data['parentRoleId'])) { $this->setParentRoleId($data['parentRoleId']); } if (isset($data['parentRole'])) { $this->setParentRoleId($data['parentRole']); } return; } throw new RcmUserException('Role data could not be populated, data format not supported'); }
/** * createNamespaceId * * @param AclRole $role acl role * @param array $aclRoles array of roles * * @return string */ public function createNamespaceId(AclRole $role, $aclRoles) { $parentRoleId = $role->getParentRoleId(); $ns = $role->getRoleId(); if (!empty($parentRoleId)) { $parent = $aclRoles[$parentRoleId]; $newns = $this->createNamespaceId($parent, $aclRoles, $ns); $ns = $newns . '.' . $ns; } return $ns; }
/** * createRoleNamespaceId * * @param AclRole $aclRole aclRole * @param array $aclRoles aclRoles * @param string $nsChar nsChar * * @return string */ public function createRoleNamespaceId(AclRole $aclRole, $aclRoles, $nsChar = '.') { $parentId = $aclRole->getParentRoleId(); $ns = $aclRole->getRoleId(); if (!empty($parentId)) { $parent = $aclRoles[$parentId]; $newns = $this->createRoleNamespaceId($parent, $aclRoles, $nsChar); $ns = $newns . $nsChar . $ns; } return $ns; }