public function testProcessPrivileges() { $request = new Request(); $request->setMethod('POST'); $role = new AccountUserRole('TEST'); $roleSecurityIdentity = new RoleSecurityIdentity($role); $appendForm = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $appendForm->expects($this->once())->method('getData')->willReturn([]); $removeForm = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $removeForm->expects($this->once())->method('getData')->willReturn([]); $firstEntityPrivilege = $this->createPrivilege('entity', 'entity:FirstClass', 'VIEW'); $secondEntityPrivilege = $this->createPrivilege('entity', 'entity:SecondClass', 'VIEW'); $entityForm = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $entityForm->expects($this->once())->method('getData')->willReturn([$firstEntityPrivilege, $secondEntityPrivilege]); $actionPrivilege = $this->createPrivilege('action', 'action', 'random_action'); $actionForm = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $actionForm->expects($this->once())->method('getData')->willReturn([$actionPrivilege]); $form = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $form->expects($this->once())->method('submit')->with($request); $form->expects($this->once())->method('isValid')->willReturn(true); $form->expects($this->any())->method('get')->willReturnMap([['appendUsers', $appendForm], ['removeUsers', $removeForm], ['entity', $entityForm], ['action', $actionForm]]); $this->formFactory->expects($this->once())->method('create')->willReturn($form); $objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(get_class($role))->willReturn($objectManager); $expectedFirstEntityPrivilege = $this->createPrivilege('entity', 'entity:FirstClass', 'VIEW'); $expectedFirstEntityPrivilege->setGroup(AccountUser::SECURITY_GROUP); $expectedSecondEntityPrivilege = $this->createPrivilege('entity', 'entity:SecondClass', 'VIEW'); $expectedSecondEntityPrivilege->setGroup(AccountUser::SECURITY_GROUP); $expectedActionPrivilege = $this->createPrivilege('action', 'action', 'random_action'); $expectedActionPrivilege->setGroup(AccountUser::SECURITY_GROUP); $this->privilegeRepository->expects($this->once())->method('savePrivileges')->with($roleSecurityIdentity, new ArrayCollection([$expectedFirstEntityPrivilege, $expectedSecondEntityPrivilege, $expectedActionPrivilege])); $this->aclManager->expects($this->any())->method('getSid')->with($role)->willReturn($roleSecurityIdentity); $this->chainMetadataProvider->expects($this->once())->method('startProviderEmulation')->with(FrontendOwnershipMetadataProvider::ALIAS); $this->chainMetadataProvider->expects($this->once())->method('stopProviderEmulation'); $handler = new AccountUserRoleHandler($this->formFactory, $this->privilegeConfig); $handler->setManagerRegistry($this->managerRegistry); $handler->setAclPrivilegeRepository($this->privilegeRepository); $handler->setAclManager($this->aclManager); $handler->setChainMetadataProvider($this->chainMetadataProvider); $handler->setRequest($request); $handler->createForm($role); $handler->process($role); }