feat: local user registration
This commit is contained in:
1 parent
8bb7f08074
commit
161029ec7c
29 files changed
+1549
-601
No files matched your search
@@ -11,15 +11,23 @@ use App\Entity\User;
|
||||
use App\Model\NewsletterSubscriptionRequestResult;
|
||||
use App\Service\BookingEditDataLoader;
|
||||
use App\Service\NewsletterManager;
|
||||
use App\Service\ProfileCompletenessChecker;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidatorFactory;
|
||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\EmailValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class PersonalDataControllerTest extends TestCase
|
||||
{
|
||||
@@ -149,8 +157,55 @@ class PersonalDataControllerTest extends TestCase
|
||||
], $controller->flashes);
|
||||
}
|
||||
|
||||
private function createController(): TestablePersonalDataController
|
||||
public function testIndexRecomputesProfileCompletionAfterSavingPersonalData(): void
|
||||
{
|
||||
$personalData = $this->createCompletePersonalData();
|
||||
$controller = $this->createController(true, true, $this->validator());
|
||||
|
||||
$controller->apiClient
|
||||
->expects(self::once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', null, null)
|
||||
->willReturn($personalData);
|
||||
$controller->apiClient
|
||||
->expects(self::once())
|
||||
->method('updatePersonalData')
|
||||
->with('[email protected]', $personalData)
|
||||
->willReturn($personalData);
|
||||
$controller->newsletterManager
|
||||
->expects(self::once())
|
||||
->method('hasConfirmedOptIn')
|
||||
->with('[email protected]')
|
||||
->willReturn(false);
|
||||
$controller->newsletterManager
|
||||
->expects(self::once())
|
||||
->method('hasPendingConfirmation')
|
||||
->with('[email protected]')
|
||||
->willReturn(false);
|
||||
$controller->dataLoader
|
||||
->expects(self::once())
|
||||
->method('invalidateUserBookingCaches')
|
||||
->with($controller->user);
|
||||
$controller->entityManager
|
||||
->expects(self::once())
|
||||
->method('flush');
|
||||
|
||||
$request = Request::create('/personal-data', 'POST');
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertSame(302, $response->getStatusCode());
|
||||
self::assertTrue($controller->user->isProfileComplete());
|
||||
self::assertSame([
|
||||
['success', 'Deine persönlichen Daten wurden aktualisiert'],
|
||||
], $controller->flashes);
|
||||
}
|
||||
|
||||
private function createController(
|
||||
bool $submitted = false,
|
||||
bool $valid = false,
|
||||
?ValidatorInterface $validator = null,
|
||||
): TestablePersonalDataController {
|
||||
$user = new User('[email protected]');
|
||||
$user->setPassword('secret');
|
||||
|
||||
@@ -162,12 +217,17 @@ class PersonalDataControllerTest extends TestCase
|
||||
->willReturnSelf();
|
||||
$form
|
||||
->method('isSubmitted')
|
||||
->willReturn(false);
|
||||
->willReturn($submitted);
|
||||
$form
|
||||
->method('isValid')
|
||||
->willReturn($valid);
|
||||
|
||||
$validator ??= $this->createMock(ValidatorInterface::class);
|
||||
|
||||
return new TestablePersonalDataController(
|
||||
$apiClient,
|
||||
$this->createMock(BookingEditDataLoader::class),
|
||||
$this->createMock(ProfileCompletenessChecker::class),
|
||||
$validator,
|
||||
$this->createMock(EntityManagerInterface::class),
|
||||
$this->createMock(NewsletterManager::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
@@ -184,6 +244,41 @@ class PersonalDataControllerTest extends TestCase
|
||||
|
||||
return $personalData;
|
||||
}
|
||||
|
||||
private function createCompletePersonalData(): PersonalData
|
||||
{
|
||||
$personalData = new PersonalData();
|
||||
$personalData->firstName = 'Mia';
|
||||
$personalData->name = 'Muster';
|
||||
$personalData->gender = 'W';
|
||||
$personalData->nationality = 'DE';
|
||||
$personalData->dateOfBirth = new \DateTimeImmutable('1990-05-15');
|
||||
$personalData->address->street = 'Main Street 1';
|
||||
$personalData->address->postCode = '10115';
|
||||
$personalData->address->city = 'Berlin';
|
||||
$personalData->address->country = 'DE';
|
||||
$personalData->communication->email = '[email protected]';
|
||||
$personalData->communication->mobile = '0123456789';
|
||||
|
||||
return $personalData;
|
||||
}
|
||||
|
||||
private function validator(): ValidatorInterface
|
||||
{
|
||||
return Validation::createValidatorBuilder()
|
||||
->enableAttributeMapping()
|
||||
->setConstraintValidatorFactory(new class extends ConstraintValidatorFactory {
|
||||
public function getInstance(Constraint $constraint): ConstraintValidatorInterface
|
||||
{
|
||||
if (true === ($constraint instanceof Email)) {
|
||||
return new EmailValidator(Email::VALIDATION_MODE_HTML5);
|
||||
}
|
||||
|
||||
return parent::getInstance($constraint);
|
||||
}
|
||||
})
|
||||
->getValidator();
|
||||
}
|
||||
}
|
||||
|
||||
final class TestablePersonalDataController extends PersonalDataController
|
||||
@@ -202,18 +297,18 @@ final class TestablePersonalDataController extends PersonalDataController
|
||||
|
||||
public function __construct(
|
||||
public readonly ApiClient $apiClient,
|
||||
BookingEditDataLoader $dataLoader,
|
||||
ProfileCompletenessChecker $completenessChecker,
|
||||
EntityManagerInterface $entityManager,
|
||||
public readonly BookingEditDataLoader $dataLoader,
|
||||
public readonly ValidatorInterface $validator,
|
||||
public readonly EntityManagerInterface $entityManager,
|
||||
public readonly NewsletterManager $newsletterManager,
|
||||
LoggerInterface $logger,
|
||||
private readonly User $user,
|
||||
public readonly User $user,
|
||||
private readonly FormInterface $form,
|
||||
) {
|
||||
parent::__construct(
|
||||
$apiClient,
|
||||
$dataLoader,
|
||||
$completenessChecker,
|
||||
$validator,
|
||||
$entityManager,
|
||||
$newsletterManager,
|
||||
$logger,
|
||||
|
||||
Reference in new issue
Block a user