/**
  * create
  *
  * @param mixed|AclRule $data data
  *
  * @return mixed|JsonModel
  */
 public function create($data)
 {
     // ACCESS CHECK
     if (!$this->isAllowed(RcmUserAclResourceProvider::RESOURCE_ID_ACL, 'create')) {
         return $this->getNotAllowedResponse();
     }
     $aclDataService = $this->getServiceLocator()->get('RcmUser\\Acl\\AclDataService');
     try {
         $aclRole = new AclRole();
         $aclRole->populate($data);
         $result = $aclDataService->createRole($aclRole);
     } catch (\Exception $e) {
         return $this->getExceptionResponse($e);
     }
     return $this->getJsonResponse($result);
 }
Beispiel #2
0
 /**
  * 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");
 }