当前位置: 首页>>代码示例>>PHP>>正文


PHP User::setUsername方法代码示例

本文整理汇总了PHP中Oro\Bundle\UserBundle\Entity\User::setUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setUsername方法的具体用法?PHP User::setUsername怎么用?PHP User::setUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Oro\Bundle\UserBundle\Entity\User的用法示例。


在下文中一共展示了User::setUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var UserManager $userManager */
     $userManager = $this->container->get('oro_user.manager');
     $role = $manager->getRepository('OroUserBundle:Role')->findOneByRole('ROLE_ADMINISTRATOR');
     $group = $manager->getRepository('OroUserBundle:Group')->findOneByName('Administrators');
     $unit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneByName('Main');
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $user = new User();
     $user->setUsername('owner_User');
     $user->addGroup($group);
     $user->addRole($role);
     $user->addBusinessUnit($unit);
     $user->setFirstname('Test Owner  FirstName');
     $user->setLastname('Test Owner LastName');
     $user->setEmail('owner@example.com');
     $user->setOwner($unit);
     $user->addGroup($group);
     $user->setPlainPassword('test password');
     $user->setSalt(md5(mt_rand(1, 222)));
     $user->setOrganization($organization);
     $userManager->updateUser($user);
     $this->setReference('owner_user', $user);
     $manager->flush();
 }
开发者ID:antrampa,项目名称:crm,代码行数:28,代码来源:LoadOwnerUser.php

示例2: testBuildView

 public function testBuildView()
 {
     $firstUser = new User();
     $firstUser->setUsername('1');
     $secondUser = new User();
     $secondUser->setUsername('2');
     $firstCalendar = new Calendar();
     $firstCalendar->setOwner($firstUser);
     $secondCalendar = new Calendar();
     $secondCalendar->setOwner($secondUser);
     $firstEvent = new CalendarEvent();
     $firstEvent->setCalendar($firstCalendar);
     $secondEvent = new CalendarEvent();
     $secondEvent->setCalendar($secondCalendar);
     $formData = [$firstEvent, $secondEvent];
     $transformedData = [$firstUser, $secondUser];
     $form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $form->expects($this->once())->method('getData')->will($this->returnValue($formData));
     $this->transformer->expects($this->once())->method('transform')->with($formData)->will($this->returnValue($transformedData));
     $converter = $this->getMock('Oro\\Bundle\\FormBundle\\Autocomplete\\ConverterInterface');
     $converter->expects($this->any())->method('convertItem')->will($this->returnCallback([$this, 'convertEvent']));
     $formView = new FormView();
     $expectedSelectedData = json_encode([$this->convertEvent($firstUser), $this->convertEvent($secondUser)]);
     $this->type->buildView($formView, $form, ['converter' => $converter]);
     $this->assertArrayHasKey('attr', $formView->vars);
     $this->assertEquals(['data-selected-data' => $expectedSelectedData], $formView->vars['attr']);
 }
开发者ID:Maksold,项目名称:platform,代码行数:27,代码来源:CalendarEventInviteesTypeTest.php

示例3: updateUser

 /**
  * @param User  $user
  * @param array $options
  * @throws InvalidArgumentException
  */
 protected function updateUser(User $user, $options)
 {
     if (!empty($options['user-role'])) {
         $role = $this->getEntityManager()->getRepository('OroUserBundle:Role')->findOneBy(array('role' => $options['user-role']));
         if (!$role) {
             throw new InvalidArgumentException('Invalid Role');
         }
         $user->addRole($role);
     }
     if (!empty($options['user-business-unit'])) {
         $businessUnit = $this->getEntityManager()->getRepository('OroOrganizationBundle:BusinessUnit')->findOneBy(array('name' => $options['user-business-unit']));
         if (!$businessUnit) {
             throw new InvalidArgumentException('Invalid Business Unit');
         }
         $user->setOwner($businessUnit)->addBusinessUnit($businessUnit);
     }
     if (!empty($options['user-name'])) {
         $user->setUsername($options['user-name']);
     }
     if (!empty($options['user-password'])) {
         $user->setPlainPassword($options['user-password']);
     }
     $properties = ['email', 'firstname', 'lastname'];
     foreach ($properties as $property) {
         if (!empty($options['user-' . $property])) {
             $user->{'set' . str_replace('-', '', $property)}($options['user-' . $property]);
         }
     }
     $this->getUserManager()->updateUser($user);
 }
开发者ID:xamin123,项目名称:platform,代码行数:35,代码来源:CreateUserCommand.php

示例4: testGetActivityOwners

 public function testGetActivityOwners()
 {
     $organization = new Organization();
     $organization->setName('Org');
     $user = new User();
     $user->setUsername('test');
     $emailUser = new EmailUser();
     $emailUser->setOrganization($organization);
     $emailUser->setOwner($user);
     $owners = [$emailUser];
     $emailMock = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailUser')->setMethods(['getFromEmailAddress', 'hasOwner', 'getOwner', 'getOrganization', 'getActivityTargetEntities'])->disableOriginalConstructor()->getMock();
     $emailMock->expects($this->once())->method('getFromEmailAddress')->willReturn($emailMock);
     $emailMock->expects($this->once())->method('getOwner')->willReturn($emailMock);
     $emailMock->expects($this->exactly(2))->method('getOrganization')->willReturn($organization);
     $emailMock->expects($this->exactly(1))->method('getActivityTargetEntities')->willReturn([]);
     $activityListMock = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\ActivityList')->disableOriginalConstructor()->getMock();
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineRegistryLink->expects($this->once())->method('getService')->willReturn($em);
     $em->expects($this->once())->method('getRepository')->willReturn($repository);
     $repository->expects($this->once())->method('findBy')->willReturn($owners);
     $activityOwnerArray = $this->emailActivityListProvider->getActivityOwners($emailMock, $activityListMock);
     $this->assertCount(1, $activityOwnerArray);
     $owner = $activityOwnerArray[0];
     $this->assertEquals($organization->getName(), $owner->getOrganization()->getName());
     $this->assertEquals($user->getUsername(), $owner->getUser()->getUsername());
 }
开发者ID:antrampa,项目名称:platform,代码行数:27,代码来源:EmailActivityListProviderTest.php

示例5: testToStringUsername

 public function testToStringUsername()
 {
     $obj = new Calendar();
     $owner = new User();
     $owner->setUsername('testUsername');
     $obj->setOwner($owner);
     $this->assertEquals($owner->getUsername(), (string) $obj);
 }
开发者ID:Maksold,项目名称:platform,代码行数:8,代码来源:CalendarTest.php

示例6: testUsername

 public function testUsername()
 {
     $user = new User();
     $name = 'Tony';
     $this->assertNull($user->getUsername());
     $user->setUsername($name);
     $this->assertEquals($name, $user->getUsername());
     $this->assertEquals($name, $user);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:9,代码来源:UserTest.php

示例7: testSetUsername

 public function testSetUsername()
 {
     $user = new User();
     $user->setUsername('testuser');
     $this->loggableManager->setUsername($user);
     $this->setExpectedException('InvalidArgumentException', 'Username must be a string, or object should have method: getUsername');
     $wrongUser = new \stdClass();
     $this->loggableManager->setUsername($wrongUser);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:9,代码来源:LoggableManagerTest.php

示例8: fillEntityData

 /**
  * @param string $key
  * @param User   $entity
  */
 public function fillEntityData($key, $entity)
 {
     $businessUnitRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit');
     switch ($key) {
         case 'John Doo':
             $entity->setUsername('admin')->setLoginCount(101)->setId(1)->setPlainPassword('admin_password')->setFirstname('John')->setMiddleName('Awesome')->setLastname('Doe')->setEmail('admin@example.com')->setNamePrefix('Mr.')->setNameSuffix('Jr.')->setBirthday(new \DateTime('2013-02-01'))->setCreatedAt(new \DateTime())->setUpdatedAt(new \DateTime())->setEnabled(true)->setOwner($businessUnitRepo->getEntity('Main'))->addGroup(new Group('Administrators'))->addBusinessUnit($businessUnitRepo->getEntity('Main'));
             return;
     }
     parent::fillEntityData($key, $entity);
 }
开发者ID:Maksold,项目名称:platform,代码行数:14,代码来源:UserFixture.php

示例9: updateUser

 /**
  * @param User  $user
  * @param array $options
  * @throws InvalidArgumentException
  */
 protected function updateUser(User $user, $options)
 {
     if (!empty($options['user-name'])) {
         $user->setUsername($options['user-name']);
     }
     if (!empty($options['user-password'])) {
         $user->setPlainPassword($options['user-password']);
     }
     $this->setRole($user, $options)->setBusinessUnit($user, $options)->setOrganizations($user, $options)->setProperties($user, $options);
     $this->getUserManager()->updateUser($user);
 }
开发者ID:Maksold,项目名称:platform,代码行数:16,代码来源:CreateUserCommand.php

示例10: denormalizeShort

 /**
  * Short mode denormalization
  *
  * @param mixed $data
  * @param string $class
  * @param mixed $format
  * @param array $context
  * @return User
  */
 protected function denormalizeShort($data, $class, $format = null, array $context = array())
 {
     $result = new User();
     if (!empty($data['username'])) {
         $result->setUsername($data['username']);
     }
     if (!empty($data['fullName'])) {
         list($firstName, $lastName) = explode(' ', $data['fullName'], 2);
         $result->setFirstName($firstName);
         $result->setLastName($lastName);
     }
     return $result;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:22,代码来源:UserNormalizer.php

示例11: createUser

 /**
  * @param string $firstName
  * @param string $lastName
  *
  * @return User
  */
 protected function createUser($firstName, $lastName)
 {
     $user = new User();
     $user->setOrganization($this->organization);
     $user->setFirstName($firstName);
     $user->setLastName($lastName);
     $user->setUsername(strtolower($firstName . '.' . $lastName));
     $user->setPassword(strtolower($firstName . '.' . $lastName));
     $user->setEmail(strtolower($firstName . '_' . $lastName . '@example.com'));
     $user->addEmail($this->email);
     $this->em->persist($user);
     return $user;
 }
开发者ID:Maksold,项目名称:platform,代码行数:19,代码来源:LoadEmailSuggestionData.php

示例12: testGetVariableValues

 public function testGetVariableValues()
 {
     $organization = new Organization();
     $organization->setName('TestOrg');
     $user = new User();
     $user->setUsername('test');
     $user->setFirstName('FirstName');
     $user->setLastName('LastName');
     $this->securityFacade->expects($this->once())->method('getOrganization')->will($this->returnValue($organization));
     $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($user));
     $this->nameFormatter->expects($this->once())->method('format')->with($this->identicalTo($user))->will($this->returnValue('FullName'));
     $result = $this->provider->getVariableValues();
     $this->assertEquals(['userName' => 'test', 'userFirstName' => 'FirstName', 'userLastName' => 'LastName', 'userFullName' => 'FullName', 'organizationName' => 'TestOrg'], $result);
 }
开发者ID:xamin123,项目名称:platform,代码行数:14,代码来源:LoggedUserVariablesProviderTest.php

示例13: testTransform

 public function testTransform()
 {
     $this->assertNull($this->transformer->transform(null));
     $firstUser = new User();
     $firstUser->setUsername('1');
     $secondUser = new User();
     $secondUser->setUsername('2');
     $firstCalendar = new Calendar();
     $firstCalendar->setOwner($firstUser);
     $secondCalendar = new Calendar();
     $secondCalendar->setOwner($secondUser);
     $firstEvent = new CalendarEvent();
     $firstEvent->setCalendar($firstCalendar);
     $secondEvent = new CalendarEvent();
     $secondEvent->setCalendar($secondCalendar);
     $this->assertEquals([$firstUser, $secondUser], $this->transformer->transform([$firstEvent, $secondEvent])->toArray());
 }
开发者ID:Maksold,项目名称:platform,代码行数:17,代码来源:EventsToUsersTransformerTest.php

示例14: testUpdateUser

 public function testUpdateUser()
 {
     $password = 'password';
     $encodedPassword = 'encodedPassword';
     $email = 'test@test.com';
     $user = new User();
     $user->setUsername($email)->setEmail($email)->setPlainPassword($password);
     $encoder = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface');
     $encoder->expects($this->once())->method('encodePassword')->with($user->getPlainPassword(), $user->getSalt())->will($this->returnValue($encodedPassword));
     $this->ef->expects($this->once())->method('getEncoder')->with($user)->will($this->returnValue($encoder));
     $this->om->expects($this->once())->method('persist')->with($this->equalTo($user));
     $this->om->expects($this->once())->method('flush');
     $this->metadata->expects($this->once())->method('getAssociationTargetClass')->willReturn('Symfony\\Component\\Security\\Core\\Role\\RoleInterface');
     $repository = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\Repository\\UserApiRepository')->disableOriginalConstructor()->getMock();
     $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
     $repository->expects($this->once())->method('findOneBy')->with($this->equalTo(['role' => User::ROLE_DEFAULT]))->will($this->returnValue(new Role(User::ROLE_DEFAULT)));
     $this->userManager->updateUser($user);
     $this->assertEquals($email, $user->getEmail());
     $this->assertEquals($encodedPassword, $user->getPassword());
 }
开发者ID:Maksold,项目名称:platform,代码行数:20,代码来源:UserManagerTest.php

示例15: getOroUsersCollection

 /**
  * @param int $size
  * @param string $specificData
  * @return array
  */
 protected function getOroUsersCollection($size = 2, $specificData = '')
 {
     $result = array();
     for ($i = 0; $i < $size; $i++) {
         $user = new OroUser();
         $user->setUsername("username_{$i}");
         $user->setFirstName("First {$specificData}");
         $user->setLastName("Last {$specificData}");
         $user->setEmail("some@host{$i}.com");
         $result[] = $user;
     }
     return $result;
 }
开发者ID:northdakota,项目名称:diamantedesk-application,代码行数:18,代码来源:DiamanteUserSearchHandlerTest.php


注:本文中的Oro\Bundle\UserBundle\Entity\User::setUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。