public function setUp()
 {
     parent::setUp();
     $this->persistedUsernamePasswordProvider = new PersistedUsernamePasswordProvider('myTestProvider');
     $this->accountFactory = new Security\AccountFactory();
     $this->accountRepository = new Security\AccountRepository();
     $this->authenticationToken = $this->getAccessibleMock(Security\Authentication\Token\UsernamePassword::class, array('dummy'));
     $account = $this->accountFactory->createAccountWithPassword('username', 'password', array(), 'myTestProvider');
     $this->accountRepository->add($account);
     $this->persistenceManager->persistAll();
 }
Example #2
0
 /**
  * @dataProvider personsDataProvider
  * @test
  */
 public function personsAndAccountPersistingAndRetrievingWorksCorrectly($firstName, $middleName, $lastName, $emailAddress)
 {
     $person = new Person();
     $person->setName(new PersonName('', $firstName, $middleName, $lastName));
     $electronicAddress = new ElectronicAddress();
     $electronicAddress->setType(ElectronicAddress::TYPE_EMAIL);
     $electronicAddress->setIdentifier($emailAddress);
     $person->setPrimaryElectronicAddress($electronicAddress);
     $account = $this->accountFactory->createAccountWithPassword($emailAddress, $this->persistenceManager->getIdentifierByObject($person));
     $this->accountRepository->add($account);
     $person->addAccount($account);
     $this->partyRepository->add($person);
     $this->persistenceManager->persistAll();
     $this->assertEquals(1, $this->partyRepository->countAll());
     $this->persistenceManager->clearState();
     $foundPerson = $this->partyRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($person));
     $this->assertEquals($foundPerson->getName()->getFullName(), $person->getName()->getFullName());
     $this->assertEquals($foundPerson->getName()->getFullName(), $firstName . ' ' . $middleName . ' ' . $lastName);
     $this->assertEquals($foundPerson->getPrimaryElectronicAddress()->getIdentifier(), $emailAddress);
 }
 /**
  * Adds a user whose User object has been created elsewhere
  *
  * This method basically "creates" a user like createUser() would, except that it does not create the User
  * object itself. If you need to create the User object elsewhere, for example in your ActionController, make sure
  * to call this method for registering the new user instead of adding it to the PartyRepository manually.
  *
  * This method also creates a new user workspace for the given user if no such workspace exist.
  *
  * @param string $username The username of the user to be created.
  * @param string $password Password of the user to be created
  * @param User $user The pre-built user object to start with
  * @param array $roleIdentifiers A list of role identifiers to assign
  * @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider"
  * @return User The same user object
  * @api
  */
 public function addUser($username, $password, User $user, array $roleIdentifiers = null, $authenticationProviderName = null)
 {
     if ($roleIdentifiers === null) {
         $roleIdentifiers = array('Neos.Neos:Editor');
     }
     $roleIdentifiers = $this->normalizeRoleIdentifiers($roleIdentifiers);
     $account = $this->accountFactory->createAccountWithPassword($username, $password, $roleIdentifiers, $authenticationProviderName ?: $this->defaultAuthenticationProviderName);
     $this->partyService->assignAccountToParty($account, $user);
     $this->partyRepository->add($user);
     $this->accountRepository->add($account);
     $this->createPersonalWorkspace($user, $account);
     $this->emitUserCreated($user);
     return $user;
 }
 /**
  * @test
  */
 public function createAccountWithPasswordCreatesANewAccountWithTheGivenIdentifierPasswordRolesAndProviderName()
 {
     $factory = new AccountFactory();
     $actualAccount = $factory->createAccountWithPassword('username', 'password', ['Neos.Flow:Administrator', 'Neos.Flow:Customer'], 'OtherProvider');
     $this->assertEquals('username', $actualAccount->getAccountIdentifier());
     $this->assertEquals('OtherProvider', $actualAccount->getAuthenticationProviderName());
     $this->assertTrue($actualAccount->hasRole($this->policyService->getRole('Neos.Flow:Administrator')));
     $this->assertTrue($actualAccount->hasRole($this->policyService->getRole('Neos.Flow:Customer')));
 }