/**
  * test findUserByEmployeeNameUsingLike method
  */
 public function testDeleteUsersByIds()
 {
     $newEmployee = new Employee();
     $newEmployee->setDateOfBirth(new \DateTime('1990-02-01'));
     $newEmployee->setJoiningDate(new \DateTime('2009-03-01'));
     $newEmployee->setNumberOfChildren(0);
     $newEmployee->setEmployeeName('employee');
     $newEmployee->setWorkingHours(8);
     $newEmployee->setBankAccountNumber('00000000-11468115');
     $newEmployee->setBankName('OTP');
     // Create a new user.
     $newUser = new User();
     $newUser->setUsername('test1');
     $newUser->setEmail('*****@*****.**');
     $newUser->setEmployee($newEmployee);
     $newUser->setSalt('');
     $newUser->setPassword('test1');
     $newUser->setIsActive(1);
     $newUser->setLdapEnabled(0);
     $newUser->setIsFirstLogin(0);
     // Save the new user into the local test database.
     $this->em->persist($newUser);
     $this->em->flush();
     // Get the saved user.
     $testUser = $this->em->getRepository("OpitOpitHrmUserBundle:User")->findOneByUsername('test1');
     $user = $this->em->getRepository("OpitOpitHrmUserBundle:User")->deleteUsersByIds($testUser->getId());
     $this->assertNotNull($user, 'testDeleteUsersByIds: The given result is null.');
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 public function doLoad(ObjectManager $manager)
 {
     $factory = $this->container->get('security.encoder_factory');
     $aclManager = $this->container->get('opit.security.acl.manager');
     $users = array();
     $managers = array();
     $user = new User();
     $encoder = $factory->getEncoder($user);
     $testAdmin = new User();
     $testAdmin->setUsername('admin');
     $testAdmin->setEmployee($this->createEmployee());
     $password = $encoder->encodePassword('admin', '');
     $testAdmin->setPassword($password);
     $testAdmin->setEmail('*****@*****.**');
     $testAdmin->setIsActive(1);
     if ('test' === $this->getCurrentEnvironment()) {
         $testAdmin->setIsFirstLogin(0);
     } else {
         $testAdmin->setIsFirstLogin(1);
     }
     $testAdmin->setLdapEnabled(0);
     $testAdmin->addGroup($this->getReference('admin-group'));
     $manager->persist($testAdmin);
     $testSystemAdmin = new User();
     $testSystemAdmin->setUsername('systemadmin');
     $testSystemAdmin->setEmployee($this->createEmployee());
     $password = $encoder->encodePassword('systemadmin', '');
     $testSystemAdmin->setPassword($password);
     $testSystemAdmin->setEmail('*****@*****.**');
     $testSystemAdmin->setIsActive(1);
     if ('test' === $this->getCurrentEnvironment()) {
         $testSystemAdmin->setIsFirstLogin(0);
     } else {
         $testSystemAdmin->setIsFirstLogin(1);
     }
     $testSystemAdmin->setLdapEnabled(0);
     $testSystemAdmin->addGroup($this->getReference('system-admin-group'));
     $manager->persist($testSystemAdmin);
     if (in_array($this->getCurrentEnvironment(), array('dev', 'test'))) {
         for ($i = 0; $i < 10; $i++) {
             $testEmployee = $this->createEmployee();
             $username = substr($testEmployee->getEmployeeName(), strpos($testEmployee->getEmployeeName(), ' ') + 1);
             $testUser = new User();
             $testUser->setUsername(strtolower($username));
             $testUser->setEmployee($testEmployee);
             $password = $encoder->encodePassword(strtolower($username), '');
             $testUser->setPassword($password);
             $testUser->setLdapEnabled(0);
             $testUser->setEmail(strtolower($username) . '@mail.local');
             $testUser->setIsActive(1);
             $testUser->setIsFirstLogin(1);
             $testUser->addGroup($this->getReference('user-group'));
             $users[] = $testUser;
             $manager->persist($testUser);
         }
         $this->addReference('testUser-user', $testUser);
         $testTeamManager = new User();
         $testTeamManager->setUsername('teamManager');
         $testTeamManager->setEmployee($this->createEmployee());
         $password = $encoder->encodePassword('teamManager', '');
         $testTeamManager->setPassword($password);
         $testTeamManager->setEmail('*****@*****.**');
         $testTeamManager->setIsActive(1);
         $testTeamManager->setIsFirstLogin(1);
         $testTeamManager->addGroup($this->getReference('team-manager-group'));
         $testTeamManager->addGroup($this->getReference('user-group'));
         $testTeamManager->setLdapEnabled(0);
         $managers[] = $testTeamManager;
         $manager->persist($testTeamManager);
         $testGeneralManager = new User();
         $testGeneralManager->setUsername('generalManager');
         $testGeneralManager->setEmployee($this->createEmployee());
         $password = $encoder->encodePassword('generalManager', '');
         $testGeneralManager->setPassword($password);
         $testGeneralManager->setEmail('*****@*****.**');
         $testGeneralManager->setIsActive(1);
         $testGeneralManager->setIsFirstLogin(1);
         $testGeneralManager->addGroup($this->getReference('general-manager-group'));
         $testGeneralManager->addGroup($this->getReference('user-group'));
         $testGeneralManager->setLdapEnabled(0);
         $managers[] = $testGeneralManager;
         $manager->persist($testGeneralManager);
         $user = new User();
         $user->setUsername('user');
         $user->setEmployee($this->createEmployee());
         $password = $encoder->encodePassword('user', '');
         $user->setPassword($password);
         $user->setEmail('*****@*****.**');
         $user->setIsActive(1);
         $user->setIsFirstLogin(1);
         $user->addGroup($this->getReference('user-group'));
         $user->setLdapEnabled(0);
         $users[] = $user;
         $manager->persist($user);
         $this->addReference('admin', $testAdmin);
         $this->addReference('user', $user);
         $this->addReference('generalManager', $testGeneralManager);
     }
     $manager->flush();
     $aclManager->grant($testSystemAdmin, $this->getReference('system-admin-group'));
     $aclManager->grant($testAdmin, $this->getReference('admin-group'));
     foreach ($users as $user) {
         $aclManager->grant($user, $this->getReference('system-admin-group'));
     }
     foreach ($managers as $manager) {
         $aclManager->grant($manager, $this->getReference('admin-group'));
     }
 }