Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Controller/UserRegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function registerFromInvitationAction(Request $request): Response|FormVie
[
'languageCode' => $language,
'mainLanguageCode' => $language,
'struct' => $data,
'intent' => 'invitation',
]
);
Expand Down
60 changes: 60 additions & 0 deletions tests/integration/Controller/UserRegisterControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\User\Controller;

use Ibexa\ContentForms\Form\ActionDispatcher\UserDispatcher;
use Ibexa\Contracts\User\Invitation\InvitationCreateStruct;
use Ibexa\Tests\Integration\User\IbexaKernelTestCase;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\HttpFoundation\Response;

/**
* @covers \Ibexa\Bundle\User\Controller\UserRegisterController::registerFromInvitationAction
*/
final class UserRegisterControllerTest extends IbexaKernelTestCase
{
private const string INVITEE_EMAIL = 'invitee@ibexa.co';

public function testRegisterFromInvitationRespondsWithOk(): void
{
self::setAdministratorUser();
self::getContainer()->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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there API that can be used instead of a vanilla SQL query?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@konradoboza No, there is no removal API — see https://github.com/ibexa/user/blob/5.0/src/lib/Invitation/Persistence/DoctrineGateway.php, so rows are in fact never deleted from the invitation tables at all: accepted, expired and stale invitations all stay forever.
I could add a deleteInvitation() to Persistence\Handler + DoctrineGateway but @bnowak suggested adding DAMA to this package separately, so the need for that api call would be short-lived. What do you prefer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest I leave the code as is, and that I makes a follow-up PR with DAMA

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that.

'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]);
}
}
8 changes: 8 additions & 0 deletions tests/integration/IbexaTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading