setUsername() public method

Set username
public setUsername ( string $username ) : Newscoop\Entity\User
$username string
return Newscoop\Entity\User
 public function setUp()
 {
     parent::setUp('Newscoop\\Entity\\User', 'Newscoop\\Entity\\Acl\\Role');
     $this->service = new DoctrineAuthService($this->em);
     $this->user = new User();
     $this->user->setEmail(self::EMAIL);
     $this->user->setUsername(self::USERNAME);
     $this->user->setPassword(self::PASSWORD);
     $this->em->persist($this->user);
     $this->em->flush();
 }
Example #2
0
 public function setUp()
 {
     parent::setUp('Newscoop\\Entity\\User', 'Newscoop\\Entity\\Acl\\Role', 'Newscoop\\Entity\\UserAttribute');
     $this->auth = $this->getMockBuilder('Zend_Auth')->disableOriginalConstructor()->getMock();
     $this->repository = $this->em->getRepository('Newscoop\\Entity\\User');
     $this->service = new UserService($this->em, $this->auth);
     $this->user = new User();
     $this->user->setEmail('*****@*****.**');
     $this->user->setUsername('test');
     $this->user->setFirstName('Foo');
     $this->user->setLastName('Bar');
 }
Example #3
0
 public function testGetEditors()
 {
     $blogRole = new Group();
     $blogRole->setName('blogger');
     $author1 = new Author('tic1', 'toc');
     $author2 = new Author('tic2', 'toc');
     $this->em->persist($blogRole);
     $this->em->persist($author1);
     $this->em->persist($author2);
     $this->em->flush();
     $user = new User();
     $user->setUsername('user')->setEmail('*****@*****.**')->setActive(true);
     $admin = new User();
     $admin->setUsername('admin')->setEmail('*****@*****.**')->setActive(true)->setAdmin(true);
     $editor = new User();
     $editor->setUsername('editor')->setEmail('*****@*****.**')->setActive(true)->setAdmin(true)->setAuthor($author1);
     $blogger = new User();
     $blogger->setUsername('blogger')->setEmail('*****@*****.**')->setActive(true)->setAdmin(true)->setAuthor($author2)->addUserType($blogRole);
     $this->em->persist($user);
     $this->em->persist($admin);
     $this->em->persist($editor);
     $this->em->persist($blogger);
     $this->em->flush();
     $service = new ListUserService(array('blog' => array('role' => $blogRole->getId())), $this->em);
     $editors = $service->findEditors();
     $this->assertEquals(1, count($editors));
     $this->assertEquals($editor->getId(), $editors[0]->getId());
     $this->assertEquals(1, $service->getEditorsCount());
 }
Example #4
0
 public function testPending()
 {
     $user = new User('email');
     $this->assertTrue($user->isPending());
     $user->setActive();
     $this->assertTrue($user->isPending());
     $user->setUsername('uname');
     $this->assertFalse($user->isPending());
 }
 public function testFindWithLimit()
 {
     for ($i = 0; $i < 50; $i++) {
         $user = new User();
         $user->setEmail(uniqid("email_{$i}", true));
         $user->setUsername(uniqid("username_{$i}", true));
         $this->em->persist($user);
     }
     $this->em->flush();
     $this->assertEquals(25, count($this->service->find('email_')));
 }
 public function its_lockUnlockArticle_should_lock_article($request, $article, $query, $number, $language, $user, $token, $security)
 {
     $query->getOneOrNullResult()->willReturn($article);
     $request->getMethod()->willReturn('POST');
     $article->isLocked()->willReturn(false);
     $user = new User('*****@*****.**');
     $user->setUsername('doe');
     $security->getToken()->willReturn($token);
     $token->getUser()->willReturn($user);
     $article->setLockUser($user)->willReturn(null);
     $article->setLockTime(Argument::type('\\DateTime'))->willReturn(null);
     $response = $this->lockUnlockArticle($request, $number, $language);
     $response->shouldBeAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response');
     $response->getStatusCode()->shouldReturn(200);
 }
 public function testSave()
 {
     $user = new User();
     $user->setUsername('testname');
     $user->setEmail('email');
     $this->em->persist($user);
     $this->em->flush();
     $event = new CommunityTickerEvent();
     $this->repository->save($event, array('event' => 'test.event', 'user' => 1, 'params' => array('param1' => 'value1')));
     $this->em->flush();
     $this->em->clear();
     $this->assertEquals(1, $event->getId());
     $this->assertEquals('test.event', $event->getEvent());
     $this->assertEquals($user, $event->getUser());
     $this->assertEquals(array('param1' => 'value1'), $event->getParams());
 }
 public function setUsername($username)
 {
     $this->__load();
     return parent::setUsername($username);
 }
Example #9
0
 /**
  * Create new activated user
  *
  * @param string  $email
  * @param string  $password
  * @param string  $firstName
  * @param string  $lastName
  * @param integer $publication
  */
 public function createUser($email, $password, $username, $firstName = null, $lastName = null, $publication = 0, $public = true, $userTypes = array(), $isAdmin = false)
 {
     $users = $this->findBy(array('email' => $email));
     if (!empty($users)) {
         throw new \Newscoop\Exception\ResourcesConflictException("User with this email already exists");
     }
     $user = new User($email);
     $user->setPassword($password);
     $user->setUsername($username);
     $user->setPublic($public);
     $user->setActive();
     $user->setFirstName($firstName);
     $user->setLastName($lastName);
     $user->setPublication($publication);
     $user->setAdmin($isAdmin);
     foreach ($userTypes as $type) {
         $user->addUserType($this->em->getReference('Newscoop\\Entity\\User\\Group', $type));
     }
     $this->em->persist($user);
     $this->em->flush();
     return $user;
 }
Example #10
0
 public function testGenerateUsername()
 {
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setUsername('Foo Bar');
     $this->em->persist($user);
     $this->em->flush();
     $this->assertEquals('Foos Bar', $this->service->generateUsername('Foos', 'Bar'));
     $this->assertEquals('Foo Bar1', $this->service->generateUsername('Foo', 'Bar'));
     $this->assertEquals('', $this->service->generateUsername(' ', ' '));
     $this->assertEquals('Foo', $this->service->generateUsername('Foo', ''));
     $this->assertEquals('Bar', $this->service->generateUsername('', 'Bar'));
     $this->assertEquals('', $this->service->generateUsername('!@#$%^&*()+-={}[]\\|;\':"ยง-?/.>,<', ''));
     $this->assertEquals('_', $this->service->generateUsername('_', ''));
     $this->assertEquals('Foo Bar Jr', $this->service->generateUsername('Foo  Bar ', ' Jr '));
 }
Example #11
0
 /**
  * Generate username
  *
  * @param string $firstName
  * @param string $lastName
  * @return string
  */
 public function generateUsername($firstName, $lastName)
 {
     if (empty($firstName) && empty($lastName)) {
         return '';
     }
     $user = new User();
     $user->setUsername(trim($firstName) . ' ' . trim($lastName));
     $username = $user->getUsername();
     for ($i = '';; $i++) {
         $conflict = $this->getRepository()->findOneBy(array('username' => "{$username}{$i}"));
         if (empty($conflict)) {
             return "{$username}{$i}";
         }
     }
 }