Created
September 4, 2018 19:46
-
-
Save jkuchar/b488bcbb6e6e349ffec2c648e95fbddd to your computer and use it in GitHub Desktop.
Ukázka scénářových testů
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. prepare invitation | |
$identityProvider->becomeAdmin(); | |
$invitation = $accounts->prepareInvitation(EmailAddress::of('double-usage@example.com'), 7); | |
// 2. check invitation code (OK) | |
$identityProvider->becomeGuest(); | |
$tempIdentity = $accounts->authenticateWithTemporaryToken( | |
$invitation->getTemporaryAuthenticationToken() | |
); | |
$identityProvider->become($tempIdentity); | |
// this is considered as goal of token achieved (same as finish registration) | |
$accounts->finishRegistration( | |
$tempIdentity->getId(), | |
Name::from('', '', '', '', ''), | |
Gender::MALE(), | |
PhoneNumber::reconstitute('+420 123 456 789'), | |
'password', | |
'finished in tests' | |
); | |
// 3. check invitation code (already used) | |
$identityProvider->becomeGuest(); | |
Assert::exception(function() use ($accounts, $invitation) { | |
$accounts->authenticateWithTemporaryToken( | |
$invitation->getTemporaryAuthenticationToken() | |
); | |
}, TemporaryAuthTokenHasBeenAlreadyUsed:: class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. prepare invitation | |
$identityProvider->becomeAdmin(); // someone who has right to prepareInvitation | |
$invitation = $accounts->prepareInvitation(EmailAddress::reconstitute('successful-registration@example.com'), 7); | |
// 2. unauthorized user clicks link | |
$identityProvider->becomeGuest(); | |
$identity = $accounts->authenticateWithTemporaryToken( | |
$invitation->getTemporaryAuthenticationToken() | |
); | |
Assert::true(equals($identity->getId(), $invitation->getAccountId())); | |
// 3. User finishes registration | |
$identityProvider->become($identity); | |
$name = Name::from('', 'Jan', '', 'Kuchař', ''); | |
Assert::false($accounts->isFullyRegistered($identity->getId())); | |
$accounts->finishRegistration( | |
$invitation->getAccountId(), | |
$name, | |
Gender::MALE(), | |
PhoneNumber::reconstitute('+420123456789'), | |
'password', | |
'finished in tests' | |
); | |
Assert::true($accounts->isFullyRegistered($identity->getId())); | |
// 4. Login into finished account | |
$identityProvider->becomeGuest(); | |
$identityProvider->become( | |
$accounts->authenticateWithCredentials( | |
EmailAddress::reconstitute('successful-registration@example.com'), | |
'password' | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment