public function testGettingAccessibleGroupsWhithErroredUser() { $this->context->expects($this->exactly(3))->method('isGranted')->will($this->returnValue(false)); $this->groupRepo->expects($this->never())->method('getChildren'); $this->user->expects($this->once())->method('getGroup')->will($this->returnValue(null)); $this->setExpectedException('\\RuntimeException', 'Security error! This user should not have empty group access. This can lead to security breach.'); $this->assertEmpty($this->resolver->getAccessibleGroups()); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $choices = []; if ($this->context->isGranted(User::ROLE_SUPER_ADMIN)) { $choices = $this->repository->findAll(); } else { $groups = $this->groupResolver->getAccessibleGroupsId(); $choices = $this->repository->findByGroups($groups); } $resolver->setDefaults(array('label' => 'game.selectMachine', 'class' => 'DPMachineBundle:Machine', 'choices' => $choices)); }