public function registerUser(array $data, array $selectedCollections = null, $providerId = null)
 {
     $provider = null;
     if ($providerId !== null) {
         $provider = $this->oauthProviderCollection->get($providerId);
     }
     $inscriptions = $this->registrationManager->getRegistrationSummary();
     $authorizedCollections = $this->getAuthorizedCollections($selectedCollections, $inscriptions);
     if (!isset($data['login'])) {
         $data['login'] = $data['email'];
     }
     $user = $this->userManipulator->createUser($data['login'], $data['password'], $data['email'], false);
     if (isset($data['geonameid'])) {
         $this->userManipulator->setGeonameId($user, $data['geonameid']);
     }
     foreach (self::$userPropertySetterMap as $property => $method) {
         if (isset($data[$property])) {
             call_user_func(array($user, $method), $data[$property]);
         }
     }
     $this->entityManager->persist($user);
     $this->entityManager->flush($user);
     if (null !== $provider) {
         $this->attachProviderToUser($provider, $user);
         $this->entityManager->flush();
     }
     $this->applyAclsToUser($authorizedCollections, $user);
     $this->createCollectionAccessDemands($user, $authorizedCollections);
     $user->setMailLocked(true);
     return $user;
 }
 public function testInvalidGeonamedId()
 {
     $manager = $this->getMockBuilder('Alchemy\\Phrasea\\Model\\Manager\\UserManager')->disableOriginalConstructor()->getMock();
     $geoname = $this->getMockBuilder('Alchemy\\Geonames\\Geoname')->disableOriginalConstructor()->getMock();
     $geoname->expects($this->once())->method('get')->with($this->equalTo('country'))->will($this->returnValue(['code' => 'fr']));
     $geonamesConnector = $this->getMockBuilder('Alchemy\\Geonames\\Connector')->disableOriginalConstructor()->getMock();
     $geonamesConnector->expects($this->once())->method('geoname')->with($this->equalTo(-1))->will($this->returnValue($geoname));
     $passwordInterface = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
     $user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
     $manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks'], self::$DI['app']['random.low']);
     $this->setExpectedException('Alchemy\\Phrasea\\Exception\\InvalidArgumentException', 'Invalid geonameid -1.');
     $manipulator->setGeonameId($user, -1);
 }