예제 #1
0
 /**
  * {@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('*****@*****.**');
     $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();
 }
 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']);
 }
예제 #3
0
 /**
  * @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);
 }
 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());
 }
예제 #5
0
 public function testToStringUsername()
 {
     $obj = new Calendar();
     $owner = new User();
     $owner->setUsername('testUsername');
     $obj->setOwner($owner);
     $this->assertEquals($owner->getUsername(), (string) $obj);
 }
예제 #6
0
 public function testUsername()
 {
     $user = new User();
     $name = 'Tony';
     $this->assertNull($user->getUsername());
     $user->setUsername($name);
     $this->assertEquals($name, $user->getUsername());
     $this->assertEquals($name, $user);
 }
 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);
 }
예제 #8
0
 /**
  * @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('*****@*****.**')->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);
 }
예제 #9
0
 /**
  * @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);
 }
 /**
  * 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;
 }
예제 #11
0
 /**
  * @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;
 }
 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);
 }
 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());
 }
예제 #14
0
 public function testUpdateUser()
 {
     $password = '******';
     $encodedPassword = '******';
     $email = '*****@*****.**';
     $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());
 }
 /**
  * @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;
 }
예제 #16
0
 public function findOneBy(array $criteria, array $orderBy = null)
 {
     $user = new User();
     $user->setUsername('testUser');
     return $user;
 }
예제 #17
0
 public function testPostSetDataReplaceOwnerAssignNotGranted()
 {
     $data = new Tag();
     $ownerName = 'user';
     $owner = new User();
     $owner->setUsername($ownerName);
     $this->prepareEntityManager($data);
     $ownerForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $ownerForm->expects($this->once())->method('getData')->will($this->returnValue($owner));
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $form->expects($this->once())->method('getParent')->will($this->returnValue(false));
     $form->expects($this->once())->method('has')->with($this->fieldName)->will($this->returnValue(true));
     $form->expects($this->once())->method('get')->with($this->fieldName)->will($this->returnValue($ownerForm));
     $form->expects($this->once())->method('remove')->with($this->fieldName);
     $form->expects($this->once())->method('add')->with($this->fieldName, 'text', array('disabled' => true, 'data' => $ownerName, 'mapped' => false, 'required' => false, 'label' => $this->fieldLabel));
     $isAssignGranted = false;
     $this->subscriber = new OwnerFormSubscriber($this->managerRegistry, $this->fieldName, $this->fieldLabel, $isAssignGranted, $this->defaultOwner);
     $event = new FormEvent($form, $data);
     $this->subscriber->postSetData($event);
 }
예제 #18
0
 public function provider()
 {
     $user = new User();
     $user->setUsername('username');
     return [['name', 'test'], ['type', GridView::TYPE_PRIVATE], ['gridName', 'grid'], ['filtersData', ['k' => 'v']], ['sortersData', ['k' => 'v']], ['owner', $user]];
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage User test_user is not in organization test_organization
  */
 public function testUserNotInOrganization()
 {
     $username = '******';
     $user = new User();
     $user->setUsername($username);
     $organizationName = 'test_organization';
     $organization = new Organization();
     $organization->setName($organizationName);
     $organization->setEnabled(true);
     $event = $this->getEvent();
     /** @var \PHPUnit_Framework_MockObject_MockObject  $input */
     $input = $event->getInput();
     $input->expects($this->at(0))->method('getParameterOption')->with('--' . ConsoleContextListener::OPTION_USER)->will($this->returnValue($username));
     $input->expects($this->at(1))->method('getParameterOption')->with('--' . ConsoleContextListener::OPTION_ORGANIZATION)->will($this->returnValue($organizationName));
     $this->userManager->expects($this->once())->method('findUserByUsernameOrEmail')->with($username)->will($this->returnValue($user));
     $this->organizationRepository->expects($this->once())->method('findOneBy')->with(['name' => $organizationName])->will($this->returnValue($organization));
     $this->listener->onConsoleCommand($event);
 }