Ejemplo n.º 1
0
 /**
  * Create a group
  *
  * @param ObjectManager $manager The object manager
  * @param string        $name    The name of the group
  * @param array         $roles   The roles connected to this group
  *
  * @return Group
  */
 private function createGroup(ObjectManager $manager, $name, array $roles = array())
 {
     $group = new Group($name);
     foreach ($roles as $role) {
         $group->addRole($role);
     }
     $manager->persist($group);
     return $group;
 }
 /**
  * Executes the current command
  *
  * @param InputInterface  $input  The input
  * @param OutputInterface $output The output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* @var EntityManager $em */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $groupName = $input->getArgument('group');
     $roleNames = $input->getOption('role');
     $group = new Group($groupName);
     if (!empty($roleNames)) {
         // Roles were provided, so attach them to the group
         $roleNames = explode(',', strtoupper($roleNames));
         foreach ($roleNames as $roleName) {
             if ('ROLE_' != substr($roleName, 0, 5)) {
                 $roleName = 'ROLE_' . $roleName;
             }
             /* @var Role $role */
             $role = $em->getRepository('KunstmaanAdminBundle:Role')->findOneBy(array('role' => $roleName));
             $group->addRole($role);
         }
     }
     $em->persist($group);
     $em->flush();
     $output->writeln(sprintf('Created group <comment>%s</comment>', $groupName));
 }
 /**
  * @covers Kunstmaan\AdminBundle\Entity\Group::__construct
  * @covers Kunstmaan\AdminBundle\Entity\Group::getName
  * @covers Kunstmaan\AdminBundle\Entity\Group::setName
  */
 public function testConstructorAndGetSetName()
 {
     $object = new Group('testgroup');
     $this->assertEquals('testgroup', $object->getName());
     $object->setName('group2');
     $this->assertEquals('group2', $object->getName());
 }
Ejemplo n.º 4
0
 public function testValidateGroupWithRole()
 {
     $group = new Group('test');
     $group->addRole(new Role('role'));
     $validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
     $violations = $validator->validate($group);
     $this->assertCount(0, $violations);
 }