コード例 #1
0
 /**
  * Test add and remove activity owner from ActivityList
  */
 public function testAddRemoveActivityOwner()
 {
     $activity = new ActivityList();
     $activity->setId(1);
     $organization = new Organization();
     $user1 = new User();
     $user1->setId(1);
     $user1->setFirstName('TestUserName1');
     $entity1 = new ActivityOwner();
     $entity1->setActivity($activity);
     $entity1->setUser($user1);
     $entity1->setOrganization($organization);
     $activity->addActivityOwner($entity1);
     $user2 = new User();
     $user1->setId(2);
     $user2->setFirstName('TestUserName2');
     $entity2 = new ActivityOwner();
     $entity2->setActivity($activity);
     $entity2->setUser($user2);
     $entity2->setOrganization($organization);
     $activity->addActivityOwner($entity2);
     $this->assertTrue($activity->getActivityOwners()->contains($entity1));
     $this->assertTrue($activity->getActivityOwners()->contains($entity2));
     $activity->removeActivityOwner($entity1);
     $activity->removeActivityOwner($entity2);
     $this->assertFalse($activity->getActivityOwners()->contains($entity1));
     $this->assertFalse($activity->getActivityOwners()->contains($entity2));
 }
コード例 #2
0
 /**
  * @test
  */
 public function userFullNameRetrieves()
 {
     $firstname = 'First';
     $lastname = 'Last';
     $user = new User();
     $user->setFirstName($firstname);
     $user->setLastName($lastname);
     $worklog = new Worklog(new TimeSpent(50), new \DateTime('now'), new Task(), $user, 'DUMMY_DESCRIPTION');
     $this->assertEquals(sprintf('%s %s', $firstname, $lastname), $worklog->getUserFullName());
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
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;
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 /**
  * @param object $entity
  * @param bool   $mockUser
  * @param bool   $detachedUser
  * @param bool   $reloadUser
  *
  * @dataProvider prePersistAndPreUpdateDataProvider
  */
 public function testPreUpdate($entity, $mockUser = false, $detachedUser = null, $reloadUser = null)
 {
     $oldDate = new \DateTime('2012-12-12 12:12:12');
     $oldUser = new User();
     $oldUser->setFirstName('oldUser');
     if ($entity instanceof ActivityList) {
         $entity->setUpdatedAt($oldDate);
         $entity->setEditor($oldUser);
     }
     $initialEntity = clone $entity;
     $newUser = null;
     if ($mockUser) {
         $newUser = new User();
         $newUser->setFirstName('newUser');
     }
     $this->mockSecurityContext($newUser);
     $unitOfWork = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->setMethods(['propertyChanged', 'getEntityState'])->disableOriginalConstructor()->getMock();
     $entityManager = $this->getEntityManagerMock($reloadUser, $newUser);
     $entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
     if ($entity instanceof ActivityList) {
         $callIndex = 0;
         if (null !== $detachedUser) {
             $unitOfWork->expects($this->at($callIndex++))->method('getEntityState')->with($newUser)->will($this->returnValue($detachedUser ? UnitOfWork::STATE_DETACHED : UnitOfWork::STATE_MANAGED));
         }
         $unitOfWork->expects($this->at($callIndex++))->method('propertyChanged')->with($entity, 'updatedAt', $oldDate, $this->isInstanceOf('\\DateTime'));
         $unitOfWork->expects($this->at($callIndex++))->method('propertyChanged')->with($entity, 'editor', $oldUser, $newUser);
     } else {
         $unitOfWork->expects($this->never())->method($this->anything());
     }
     $changeSet = [];
     $args = new PreUpdateEventArgs($entity, $entityManager, $changeSet);
     $this->listener->preUpdate($args);
     if (!$entity instanceof ActivityList) {
         $this->assertEquals($initialEntity, $entity);
         return;
     }
     $this->assertInstanceOf('\\DateTime', $entity->getUpdatedAt());
     if ($mockUser) {
         $this->assertEquals($newUser, $entity->getEditor());
     } else {
         $this->assertNull($entity->getEditor());
     }
 }
コード例 #7
0
 /**
  * @param object $entity
  * @param bool   $mockUser
  * @param bool   $detachedUser
  * @param bool   $reloadUser
  *
  * @dataProvider prePersistAndPreUpdateDataProvider
  */
 public function testPreUpdate($entity, $mockUser = false, $detachedUser = null, $reloadUser = null)
 {
     $oldUser = new User();
     $oldUser->setFirstName('oldUser');
     if ($entity instanceof Comment) {
         $entity->setUpdatedBy($oldUser);
     }
     $initialEntity = clone $entity;
     $newUser = null;
     if ($mockUser) {
         $newUser = new User();
         $newUser->setFirstName('newUser');
     }
     $this->mockSecurityContext($newUser);
     $unitOfWork = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->setMethods(['propertyChanged', 'getEntityState'])->disableOriginalConstructor()->getMock();
     $entityManager = $this->getEntityManagerMock($reloadUser, $newUser);
     $entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
     if ($entity instanceof Comment) {
         $callIndex = 0;
         if (null !== $detachedUser) {
             $unitOfWork->expects($this->once(++$callIndex))->method('getEntityState')->with($newUser)->will($this->returnValue($detachedUser ? UnitOfWork::STATE_DETACHED : UnitOfWork::STATE_MANAGED));
         }
         $unitOfWork->expects($this->once(++$callIndex))->method('propertyChanged')->with($entity, 'updatedBy', $oldUser, $newUser);
     } else {
         $unitOfWork->expects($this->never())->method($this->anything());
     }
     $changeSet = array();
     $args = new PreUpdateEventArgs($entity, $entityManager, $changeSet);
     $this->subscriber->preUpdate($args);
     if (!$entity instanceof Comment) {
         $this->assertEquals($initialEntity, $entity);
         return;
     }
     if ($mockUser) {
         $this->assertEquals($newUser, $entity->getUpdatedBy());
     } else {
         $this->assertNull($entity->getUpdatedBy());
     }
 }
コード例 #8
0
 /**
  * @param string $accountName
  * @param string $userFirstName
  * @param string $userLastName
  * @param bool $isOrder
  * @return Order|Quote
  */
 protected function createMainEntity($accountName, $userFirstName, $userLastName, $isOrder = false)
 {
     $accountUser = $this->createAccountUser($accountName);
     $owner = new User();
     $owner->setFirstName($userFirstName . ' owner')->setLastName($userLastName . ' owner')->setSalt(null);
     $organization = new Organization();
     $organization->setName($userFirstName . ' ' . $userLastName . ' org');
     $entity = $isOrder ? new Order() : new Quote();
     $entity->setAccount($accountUser->getAccount())->setAccountUser($accountUser)->setOwner($owner)->setOrganization($organization);
     return $entity;
 }
コード例 #9
0
 public function testNames()
 {
     $user = new User();
     $first = 'James';
     $last = 'Bond';
     $user->setFirstName($first);
     $user->setLastName($last);
 }
コード例 #10
0
ファイル: ActivityListTest.php プロジェクト: Maksold/platform
 public function testActivityOwner()
 {
     $user = new User();
     $user->setFirstName('First Name');
     $organization = new Organization();
     $organization->setName('Organization One');
     $activityOwner = new ActivityOwner();
     $activityOwner->setUser($user);
     $activityOwner->setOrganization($organization);
     $activityList = new ActivityList();
     $activityList->addActivityOwner($activityOwner);
     $this->assertCount(1, $activityList->getActivityOwners());
     $firstOwner = $activityList->getActivityOwners()->first();
     $this->assertEquals('First Name', $firstOwner->getUser()->getFirstName());
     $this->assertEquals('Organization One', $firstOwner->getOrganization()->getName());
 }
 /**
  * @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;
 }