diff --git a/composer.json b/composer.json index 9caff30..343ffd1 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,7 @@ "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0", "phpunit/phpunit": "^9.6", + "symfony/browser-kit": "^7.4", "symfony/phpunit-bridge": "^7.4" }, "scripts": { diff --git a/src/bundle/Controller/UserRegisterController.php b/src/bundle/Controller/UserRegisterController.php index 5ce6f7b..986043d 100644 --- a/src/bundle/Controller/UserRegisterController.php +++ b/src/bundle/Controller/UserRegisterController.php @@ -85,6 +85,7 @@ public function registerFromInvitationAction(Request $request): Response|FormVie [ 'languageCode' => $language, 'mainLanguageCode' => $language, + 'struct' => $data, 'intent' => 'invitation', ] ); diff --git a/tests/integration/Controller/UserRegisterControllerTest.php b/tests/integration/Controller/UserRegisterControllerTest.php new file mode 100644 index 0000000..4391be7 --- /dev/null +++ b/tests/integration/Controller/UserRegisterControllerTest.php @@ -0,0 +1,60 @@ +set(UserDispatcher::class, new UserDispatcher()); + + // InvitationService::isValid() compares against the SiteAccess the request resolves to + // which is the default one, not what SiteAccessServiceInterface::getCurrent() returns here + $siteAccess = self::getContainer()->getParameter('ibexa.site_access.default'); + self::assertIsString($siteAccess); + + $invitation = self::getInvitationService()->createInvitation( + new InvitationCreateStruct(self::INVITEE_EMAIL, $siteAccess) + ); + + $kernel = self::$kernel; + self::assertNotNull($kernel); + + $client = new KernelBrowser($kernel); + $client->request('GET', '/from-invite/register/' . $invitation->getHash()); + + self::assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode()); + } + + protected function tearDown(): void + { + // Database is imported once per run and there is no per-test rollback, so without this the + // invitation survives into InvitationServiceTest, which asserts absolute findInvitations() + // counts and fails + $connection = self::getDoctrineConnection(); + $connection->executeStatement( + 'DELETE FROM ibexa_user_invitation_assignment WHERE invitation_id IN ' + . '(SELECT id FROM ibexa_user_invitation WHERE email = :email)', + ['email' => self::INVITEE_EMAIL] + ); + $connection->delete('ibexa_user_invitation', ['email' => self::INVITEE_EMAIL]); + } +} diff --git a/tests/integration/IbexaTestKernel.php b/tests/integration/IbexaTestKernel.php index d328e52..2403fc6 100644 --- a/tests/integration/IbexaTestKernel.php +++ b/tests/integration/IbexaTestKernel.php @@ -63,6 +63,14 @@ public function registerContainerConfiguration(LoaderInterface $loader): void self::createSyntheticService($container); + $container->loadFromExtension('ibexa', [ + 'system' => [ + 'default' => [ + 'languages' => ['eng-GB'], + ], + ], + ]); + $container->loadFromExtension('framework', [ 'router' => [ 'resource' => __DIR__ . '/Resources/routing.yaml',