/** * @covers Kunstmaan\AdminBundle\Entity\User::hasRole */ public function testHasRole() { $this->object->addRole('ROLE_CUSTOM'); $this->assertTrue($this->object->hasRole('ROLE_CUSTOM')); $this->object->removeRole('ROLE_CUSTOM'); $this->assertFalse($this->object->hasRole('ROLE_CUSTOM')); }
/** * Create a user * * @param ObjectManager $manager The object manager * @param string $username The username * @param string $password The plain password * @param string $email The email of the user * @param string $locale The locale (language) of the user * @param array $roles The roles the user has * @param array $groups The groups the user belongs to * @param bool $enabled Enable login for the user * @param bool $changed Disable password changed for the user * * @return User */ private function createUser(ObjectManager $manager, $username, $password, $email, $locale, array $roles = array(), array $groups = array(), $enabled = false, $changed = false) { $user = new User(); $user->setUsername($username); $user->setPlainPassword($password); $user->setRoles($roles); $user->setEmail($email); $user->setEnabled($enabled); $user->setAdminLocale($locale); $user->setPasswordChanged($changed); foreach ($groups as $group) { $user->addGroup($group); } $manager->persist($user); return $user; }