From 50ea51b1ad5d0c8f69c00e517408b67c04f9ae6f Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Fri, 7 Mar 2025 12:15:04 +0100 Subject: [PATCH 1/3] add preview confirmation workflow --- README.md | 6 ++-- UPGRADE.md | 6 ++++ config/install/translations/frontend.csv | 2 ++ config/pimcore/routing/registration.yaml | 4 +++ docs/60_RegistrationTypes.md | 31 ++++++++++++++++++- src/Controller/RegistrationController.php | 16 ++++++++++ src/DependencyInjection/Configuration.php | 1 + src/Mailer/Mailer.php | 6 +++- .../registration/confirm_preview.html.twig | 9 ++++++ 9 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 templates/registration/confirm_preview.html.twig diff --git a/README.md b/README.md index f04bf8ad..95a80fd2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Add frontend user authentication and document restriction to pimcore. | Release | Supported Pimcore Versions | Supported Symfony Versions | Release Date | Maintained | Branch | |---------|-----------------------------------|----------------------------|--------------|----------------|----------| -| **5.x** | `11.0` | `6.2` | 28.09.2023 | Feature Branch | master | +| **5.x** | `11.0` | `6.4` | 28.09.2023 | Feature Branch | master | | **4.x** | `10.5 - 10.6` | `5.4` | 22.11.2021 | Unsupported | 4.x | | **3.x** | `6.0` - `6.8` | `3.4`, `^4.4` | 21.07.2019 | Unsupported | 3.x | | **2.5** | `5.4`, `5.5`, `5.6`, `5.7`, `5.8` | `3.4` | 18.07.2019 | Unsupported | 2.5 | @@ -32,7 +32,7 @@ Please read the installation instructions before going deep with Members! ```json "require" : { - "dachcom-digital/members" : "~5.1.0" + "dachcom-digital/members" : "~5.2.0" } ``` @@ -167,6 +167,6 @@ Before updating, please [check our upgrade notes!](UPGRADE.md) ## License **DACHCOM.DIGITAL AG**, Löwenhofstrasse 15, 9424 Rheineck, Schweiz [dachcom.com](https://www.dachcom.com), dcdi@dachcom.ch -Copyright © 2024 DACHCOM.DIGITAL. All rights reserved. +Copyright © 2025 DACHCOM.DIGITAL. All rights reserved. For licensing details please visit [LICENSE.md](LICENSE.md) diff --git a/UPGRADE.md b/UPGRADE.md index 582001fe..90695227 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,11 @@ # Upgrade Notes +## 5.2.0 +- [NEW FEATURE] "Preview confirmation" workflow added to avoid registration confirmation by prefetching email processes. + Read more about it [here](./docs/60_RegistrationTypes.md#email-prefetching). + This also comes with a new template: `@Members/registration/confirm_preview.html.twig` and also two new translations ( + `members.registration.confirm_preview`, `members.registration.complete_confirmation`) + ## 5.1.0 - [LICENSE] Dual-License with GPL and Dachcom Commercial License (DCL) added diff --git a/config/install/translations/frontend.csv b/config/install/translations/frontend.csv index be8805fe..9fa77e64 100644 --- a/config/install/translations/frontend.csv +++ b/config/install/translations/frontend.csv @@ -16,6 +16,8 @@ "members.registration.confirmed","Glückwunsch %username%, Ihr Benutzerkonto ist jetzt bestätigt.","Congrats %username%, your account is now activated." "members.registration.already_confirmed_or_not_found","Dieses Benutzerkonto wurde bereits bestätigt oder existiert nicht.","This user account has already been confirmed or does not exist." "members.registration.back","Zurück zur ursprünglichen Seite.","Back to the originating page." +"members.registration.confirm_preview","Hallo %username%, bitte bestätige nun deine Registrierung!","Hello %username%, please confirm your registration now!" +"members.registration.complete_confirmation","Registrierung abschliessen","Complete registration" "members.registration.submit","Registrieren","Register" "members.registration.flash.user_created","Der Benutzer wurde erfolgreich erstellt.","The user has been created successfully." "members.resetting.check_email","Eine E-Mail wurde verschickt. Sie beinhaltet einen Link zum Zurücksetzen des Passwortes. Hinweis: Ein neues Passwort kann nur alle %tokenLifetime% Stunden beantragt werden. Eventuell wurde diese E-Mail als Spam markiert, wenn sie nicht angekommen ist.","An email has been sent. It contains a link you must click to reset your password. Note: You can only request a new password once within %tokenLifetime% hours. If you don't get an email check your spam folder or try again." diff --git a/config/pimcore/routing/registration.yaml b/config/pimcore/routing/registration.yaml index cf69c3ba..869b7be9 100644 --- a/config/pimcore/routing/registration.yaml +++ b/config/pimcore/routing/registration.yaml @@ -11,6 +11,10 @@ members_user_registration_check_admin: path: /check-admin defaults: { _controller: MembersBundle\Controller\RegistrationController::checkAdminAction } methods: [GET] +members_user_registration_confirm_preview: + path: /confirm-preview/{token} + defaults: { _controller: MembersBundle\Controller\RegistrationController::confirmPreviewAction } + methods: [ GET ] members_user_registration_confirm: path: /confirm/{token} defaults: { _controller: MembersBundle\Controller\RegistrationController::confirmAction } diff --git a/docs/60_RegistrationTypes.md b/docs/60_RegistrationTypes.md index fbcd5073..bb325994 100644 --- a/docs/60_RegistrationTypes.md +++ b/docs/60_RegistrationTypes.md @@ -6,10 +6,33 @@ Name: `confirm_by_mail` > This is the default value. -After registration the user will receive a confirmation mail with a confirmation url. By clicking on that link the user gets automatically activated. +After registration the user will receive a confirmation mail with a confirmation url. +By clicking on that link the user gets automatically activated. If `send_admin_mail_after_register` is enabled, the system will send a notification mail to a defined admin. +#### Email prefetching + +> [!IMPORTANT] +> Some email providers have spam detection or security features that prefetch URLs from incoming emails +> (e.g., Safe Links in Microsoft Defender for Office 365). + +To prevent unintended automatic activations, you can enable a "preview confirmation" page. +This requires users to manually confirm their registration by clicking an additional button. + +This feature is disabled by default. To enable it, update your configuration as follows: + +```yaml + +members: + enable_preview_confirmation: true # default is false +``` + +When enabled, users will first be redirected to /confirm-preview/{token}, +where they must confirm their registration manually. + +*** + ### Confirm By Admin Name: `confirm_by_admin` @@ -17,11 +40,15 @@ After registration the user has to wait until a authorized admin activates the u If `send_user_mail_after_confirmed` is enabled, the system will send a notification mail to user. +*** + ### Confirm Instant Name: `confirm_instant` After registration the user gets automatically logged in without any further actions. +*** + ## Configuration Add those lines to your `config/config.yaml`: @@ -37,6 +64,8 @@ members: send_user_mail_after_confirmed: false ``` +*** + ## Registration Types with SSO If you're using the [SSO feature](./SSO/10_Overview.md), you may want to define some independent mail workflows. If Members detects an SSO registration process, you're able to define the registration type via the `post_register_type_oauth` flag. diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index e1c1d9a5..da8802b7 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -129,6 +129,22 @@ public function checkAdminAction(Request $request): Response return $this->renderTemplate('@Members/registration/check_admin.html.twig', ['user' => $user]); } + public function confirmPreviewAction(Request $request, string $token): Response + { + $user = $this->userManager->findUserByConfirmationToken($token); + + if ($user === null) { + throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token)); + } + + $confirmationUrl = $this->generateUrl('members_user_registration_confirm', ['token' => $user->getConfirmationToken()]); + + return $this->renderTemplate('@Members/registration/confirm_preview.html.twig', [ + 'user' => $user, + 'confirmationUrl' => $confirmationUrl, + ]); + } + public function confirmAction(Request $request, string $token): Response { $user = $this->userManager->findUserByConfirmationToken($token); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 43b33eae..b1d10ada 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -38,6 +38,7 @@ public function getConfigTreeBuilder() ->children() ->booleanNode('send_admin_mail_after_register')->defaultFalse()->end() ->booleanNode('send_user_mail_after_confirmed')->defaultFalse()->end() + ->booleanNode('enable_preview_confirmation')->defaultFalse()->end() ->enumNode('post_register_type') ->values($validPostRegisterTypes) ->defaultValue('confirm_by_mail') diff --git a/src/Mailer/Mailer.php b/src/Mailer/Mailer.php index 7e10330c..84669dba 100644 --- a/src/Mailer/Mailer.php +++ b/src/Mailer/Mailer.php @@ -30,8 +30,12 @@ public function __construct( public function sendConfirmationEmailMessage(UserInterface $user): void { + $route = $this->configuration->getConfig('enable_preview_confirmation') === true + ? 'members_user_registration_confirm_preview' + : 'members_user_registration_confirm'; + $template = $this->getMailTemplatePath('register_confirm', $user); - $url = $this->router->generate('members_user_registration_confirm', ['token' => $user->getConfirmationToken()], UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->router->generate($route, ['token' => $user->getConfirmationToken()], UrlGeneratorInterface::ABSOLUTE_URL); $mailParams = [ 'user' => $user, diff --git a/templates/registration/confirm_preview.html.twig b/templates/registration/confirm_preview.html.twig new file mode 100644 index 00000000..41f2516d --- /dev/null +++ b/templates/registration/confirm_preview.html.twig @@ -0,0 +1,9 @@ +{% extends '@Members/layout.html.twig' %} + +{% block members_user_content %} + {% set user_name = user is not null ? user.username|default(user.email) : '' %} +

{{ 'members.registration.confirm_preview'|trans({ '%username%': user_name }) }}

+ {% if confirmationUrl %} +

{{ 'members.registration.complete_confirmation'|trans }}

+ {% endif %} +{% endblock members_user_content %} \ No newline at end of file From a2c4b1e9ab907b5f9113cd2ea298810f1eecbc28 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Fri, 7 Mar 2025 12:18:07 +0100 Subject: [PATCH 2/3] adjust upgrade notes --- UPGRADE.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 90695227..df6dfb3b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,12 +1,10 @@ # Upgrade Notes -## 5.2.0 +## 5.1.0 - [NEW FEATURE] "Preview confirmation" workflow added to avoid registration confirmation by prefetching email processes. Read more about it [here](./docs/60_RegistrationTypes.md#email-prefetching). This also comes with a new template: `@Members/registration/confirm_preview.html.twig` and also two new translations ( `members.registration.confirm_preview`, `members.registration.complete_confirmation`) - -## 5.1.0 - [LICENSE] Dual-License with GPL and Dachcom Commercial License (DCL) added ### 5.0.3 From 894ddcfa47c340a8dc106e163e619785a8944a58 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Fri, 7 Mar 2025 13:57:46 +0100 Subject: [PATCH 3/3] fix unit tests --- tests/Unit/Config/ConfigurationTest.php | 10 ++----- tests/Unit/Dao/GroupTest.php | 2 +- tests/Unit/Dao/SsoIdentityTest.php | 2 +- tests/Unit/Dao/UserTest.php | 6 +---- tests/Unit/Manager/ClassManagerTest.php | 20 +++----------- tests/Unit/Manager/LoginManagerTest.php | 2 +- tests/Unit/Manager/RestrictionManagerTest.php | 6 ++--- tests/Unit/Manager/SsoIdentityManagerTest.php | 15 +++-------- tests/Unit/Manager/UserManagerTest.php | 3 --- .../Unit/Security/RoleOptionsProviderTest.php | 7 +---- tests/Unit/Security/UserCheckerTest.php | 21 ++++++++------- tests/Unit/Security/UserProviderTest.php | 26 +++++++++++-------- 12 files changed, 44 insertions(+), 76 deletions(-) diff --git a/tests/Unit/Config/ConfigurationTest.php b/tests/Unit/Config/ConfigurationTest.php index d965f3eb..56ce18dc 100644 --- a/tests/Unit/Config/ConfigurationTest.php +++ b/tests/Unit/Config/ConfigurationTest.php @@ -7,10 +7,7 @@ class ConfigurationTest extends DachcomBundleTestCase { - /** - * @throws \Codeception\Exception\ModuleException - */ - public function testConfigArrayGetter() + public function testConfigArrayGetter(): void { $configuration = $this->getContainer()->get(Configuration::class); $adminConfig = $configuration->getConfigArray(); @@ -19,10 +16,7 @@ public function testConfigArrayGetter() $this->assertArrayHasKey('send_admin_mail_after_register', $adminConfig); } - /** - * @throws \Codeception\Exception\ModuleException - */ - public function testConfigSlotGetter() + public function testConfigSlotGetter(): void { $configuration = $this->getContainer()->get(Configuration::class); $configSlot = $configuration->getConfig('post_register_type'); diff --git a/tests/Unit/Dao/GroupTest.php b/tests/Unit/Dao/GroupTest.php index d689ee87..ca8e6293 100644 --- a/tests/Unit/Dao/GroupTest.php +++ b/tests/Unit/Dao/GroupTest.php @@ -11,7 +11,7 @@ class GroupTest extends DachcomBundleTestCase /** * @throws \Exception */ - public function testGroupDaoEntity() + public function testGroupDaoEntity(): void { $group = $this->createUserGroup('group-1', ['ROLE_MEMBERS_MODERATOR']); $storedGroup = MembersGroup::getById($group->getId(), ['force' => true]); diff --git a/tests/Unit/Dao/SsoIdentityTest.php b/tests/Unit/Dao/SsoIdentityTest.php index 6a6c5d69..9b97f09f 100644 --- a/tests/Unit/Dao/SsoIdentityTest.php +++ b/tests/Unit/Dao/SsoIdentityTest.php @@ -10,7 +10,7 @@ class SsoIdentityTest extends DachcomBundleTestCase /** * @throws \Exception */ - public function testSsoIdentityDaoEntity() + public function testSsoIdentityDaoEntity(): void { $ssoIdentity = $this->createSsoIdentity(true, 'google', '1234'); diff --git a/tests/Unit/Dao/UserTest.php b/tests/Unit/Dao/UserTest.php index 7721b9c3..41a9c9bc 100644 --- a/tests/Unit/Dao/UserTest.php +++ b/tests/Unit/Dao/UserTest.php @@ -9,11 +9,7 @@ class UserTest extends DachcomBundleTestCase { - /** - * @throws \Codeception\Exception\ModuleException - * @throws \Exception - */ - public function testUserDaoEntity() + public function testUserDaoEntity(): void { $group1 = $this->createUserGroup('group-1'); $group2 = $this->createUserGroup('group-2'); diff --git a/tests/Unit/Manager/ClassManagerTest.php b/tests/Unit/Manager/ClassManagerTest.php index 70051ef7..7437df95 100644 --- a/tests/Unit/Manager/ClassManagerTest.php +++ b/tests/Unit/Manager/ClassManagerTest.php @@ -10,10 +10,7 @@ class ClassManagerTest extends DachcomBundleTestCase { - /** - * @throws ModuleException - */ - public function testGroupClass() + public function testGroupClass(): void { $classManager = $this->getContainer()->get(ClassManager::class); $groupClass = $classManager->getGroupClass(); @@ -21,10 +18,7 @@ public function testGroupClass() $this->assertEquals(MembersGroup::class, $groupClass); } - /** - * @throws ModuleException - */ - public function testGroupListing() + public function testGroupListing(): void { $classManager = $this->getContainer()->get(ClassManager::class); $groupListing = $classManager->getGroupListing(); @@ -32,10 +26,7 @@ public function testGroupListing() $this->assertInstanceOf(MembersGroup\Listing::class, $groupListing); } - /** - * @throws ModuleException - */ - public function testUserClass() + public function testUserClass(): void { $classManager = $this->getContainer()->get(ClassManager::class); $userClass = $classManager->getUserClass(); @@ -43,10 +34,7 @@ public function testUserClass() $this->assertEquals(MembersUser::class, $userClass); } - /** - * @throws ModuleException - */ - public function testUserListing() + public function testUserListing(): void { $classManager = $this->getContainer()->get(ClassManager::class); $userListing = $classManager->getUserListing(); diff --git a/tests/Unit/Manager/LoginManagerTest.php b/tests/Unit/Manager/LoginManagerTest.php index dea2782d..5bd24eb2 100644 --- a/tests/Unit/Manager/LoginManagerTest.php +++ b/tests/Unit/Manager/LoginManagerTest.php @@ -73,7 +73,7 @@ private function mockUser(): UserInterface $user ->expects($this->once()) ->method('getRoles') - ->will($this->returnValue(['ROLE_USER'])); + ->willReturn(['ROLE_USER']); return $user; } diff --git a/tests/Unit/Manager/RestrictionManagerTest.php b/tests/Unit/Manager/RestrictionManagerTest.php index 4dd82007..2d8e5fa9 100644 --- a/tests/Unit/Manager/RestrictionManagerTest.php +++ b/tests/Unit/Manager/RestrictionManagerTest.php @@ -8,7 +8,7 @@ class RestrictionManagerTest extends DachcomBundleTestCase { - public function testGetElementRestrictedGroupsDefault() + public function testGetElementRestrictedGroupsDefault(): void { $document = $this->createRestrictedDocument(); $restrictionManager = $this->getContainer()->get(RestrictionManager::class); @@ -19,7 +19,7 @@ public function testGetElementRestrictedGroupsDefault() $this->assertContains('default', $restrictionGroups); } - public function testGetElementRestrictedGroups() + public function testGetElementRestrictedGroups(): void { $group = $this->createUserGroup(); $document = $this->createRestrictedDocument([$group->getId()]); @@ -33,7 +33,7 @@ public function testGetElementRestrictedGroups() } - public function testGetElementRestrictionStatus() + public function testGetElementRestrictionStatus(): void { $group = $this->createUserGroup(); $document = $this->createRestrictedDocument([$group->getId()]); diff --git a/tests/Unit/Manager/SsoIdentityManagerTest.php b/tests/Unit/Manager/SsoIdentityManagerTest.php index 3bad2257..93ab561f 100644 --- a/tests/Unit/Manager/SsoIdentityManagerTest.php +++ b/tests/Unit/Manager/SsoIdentityManagerTest.php @@ -11,10 +11,7 @@ class SsoIdentityManagerTest extends DachcomBundleTestCase { - /** - * @throws \Exception - */ - public function testClassGetter() + public function testClassGetter(): void { $ssoIdentityManager = $this->getContainer()->get(SsoIdentityManager::class); $ssoIdentityClass = $ssoIdentityManager->getClass(); @@ -22,10 +19,7 @@ public function testClassGetter() $this->assertEquals(SsoIdentity::class, $ssoIdentityClass); } - /** - * @throws \Exception - */ - public function testCreateNewSsoIdentity() + public function testCreateNewSsoIdentity(): void { $ssoIdentity = $this->createSsoIdentity(true, 'google', '1234'); $this->assertInstanceOf(SsoIdentityInterface::class, $ssoIdentity); @@ -34,10 +28,7 @@ public function testCreateNewSsoIdentity() $this->assertEquals($expectedKey, $ssoIdentity->getKey()); } - /** - * @throws \Exception - */ - public function testFindUserBySsoIdentity() + public function testFindUserBySsoIdentity(): void { $ssoIdentity = $this->createSsoIdentity(true, 'google', '1234'); $ssoIdentityManager = $this->getContainer()->get(SsoIdentityManager::class); diff --git a/tests/Unit/Manager/UserManagerTest.php b/tests/Unit/Manager/UserManagerTest.php index 640e8acf..45dead5d 100644 --- a/tests/Unit/Manager/UserManagerTest.php +++ b/tests/Unit/Manager/UserManagerTest.php @@ -10,9 +10,6 @@ class UserManagerTest extends DachcomBundleTestCase { - /** - * @throws \Codeception\Exception\ModuleException - */ public function testClassGetter(): void { $userManager = $this->getContainer()->get(UserManager::class); diff --git a/tests/Unit/Security/RoleOptionsProviderTest.php b/tests/Unit/Security/RoleOptionsProviderTest.php index 579528f9..5839a5a0 100644 --- a/tests/Unit/Security/RoleOptionsProviderTest.php +++ b/tests/Unit/Security/RoleOptionsProviderTest.php @@ -8,10 +8,7 @@ class RoleOptionsProviderTest extends DachcomBundleTestCase { - /** - * @throws \Codeception\Exception\ModuleException - */ - public function testRoleOptions() + public function testRoleOptions(): void { /** @var RoleOptionsProvider $roleOptionsProvider */ $roleOptionsProvider = $this->getContainer()->get(RoleOptionsProvider::class); @@ -32,7 +29,5 @@ public function testRoleOptions() $this->assertArrayHasKey('value', $options[1]); $this->assertEquals('ROLE_MEMBERS_MODERATOR', $options[1]['key']); $this->assertEquals('ROLE_MEMBERS_MODERATOR', $options[1]['value']); - } - } diff --git a/tests/Unit/Security/UserCheckerTest.php b/tests/Unit/Security/UserCheckerTest.php index fa0ef486..3cfd027c 100644 --- a/tests/Unit/Security/UserCheckerTest.php +++ b/tests/Unit/Security/UserCheckerTest.php @@ -5,12 +5,15 @@ use DachcomBundle\Test\Support\Test\DachcomBundleTestCase; use MembersBundle\Security\UserChecker; use Pimcore\Model\DataObject\MembersUser; +use Symfony\Component\Security\Core\Exception\AccountExpiredException; +use Symfony\Component\Security\Core\Exception\DisabledException; +use Symfony\Component\Security\Core\Exception\LockedException; class UserCheckerTest extends DachcomBundleTestCase { - public function testCheckPreAuthFailsLockedOut() + public function testCheckPreAuthFailsLockedOut(): void { - $this->expectException(\Symfony\Component\Security\Core\Exception\LockedException::class); + $this->expectException(LockedException::class); $this->expectExceptionMessage('User account is locked.'); $userMock = $this->getUser(false, false, false); @@ -18,9 +21,9 @@ public function testCheckPreAuthFailsLockedOut() $checker->checkPreAuth($userMock); } - public function testCheckPreAuthFailsIsPublished() + public function testCheckPreAuthFailsIsPublished(): void { - $this->expectException(\Symfony\Component\Security\Core\Exception\DisabledException::class); + $this->expectException(DisabledException::class); $this->expectExceptionMessage('User account is disabled.'); $userMock = $this->getUser(true, false, false); @@ -28,9 +31,9 @@ public function testCheckPreAuthFailsIsPublished() $checker->checkPreAuth($userMock); } - public function testCheckPreAuthFailsIsAccountNonExpired() + public function testCheckPreAuthFailsIsAccountNonExpired(): void { - $this->expectException(\Symfony\Component\Security\Core\Exception\AccountExpiredException::class); + $this->expectException(AccountExpiredException::class); $this->expectExceptionMessage('User account has expired.'); $userMock = $this->getUser(true, true, false); @@ -38,7 +41,7 @@ public function testCheckPreAuthFailsIsAccountNonExpired() $checker->checkPreAuth($userMock); } - public function testCheckPreAuthSuccess() + public function testCheckPreAuthSuccess(): void { $userMock = $this->getUser(true, true, true); $checker = new UserChecker(); @@ -46,7 +49,7 @@ public function testCheckPreAuthSuccess() $this->assertNull($checker->checkPreAuth($userMock)); } - public function testCheckPostAuthSuccess() + public function testCheckPostAuthSuccess(): void { $userMock = $this->getUser(true, true, true); $checker = new UserChecker(); @@ -54,7 +57,7 @@ public function testCheckPostAuthSuccess() $this->assertNull($checker->checkPostAuth($userMock)); } - private function getUser($isAccountNonLocked, $isPublished, $isAccountNonExpired) + private function getUser($isAccountNonLocked, $isPublished, $isAccountNonExpired): MembersUser { $userMock = $this->getMockBuilder(MembersUser::class)->getMock(); $userMock diff --git a/tests/Unit/Security/UserProviderTest.php b/tests/Unit/Security/UserProviderTest.php index 0decde24..c6b7e9ca 100644 --- a/tests/Unit/Security/UserProviderTest.php +++ b/tests/Unit/Security/UserProviderTest.php @@ -9,6 +9,8 @@ use MembersBundle\Adapter\User\UserInterface; use MembersBundle\Manager\UserManagerInterface; use DachcomBundle\Test\Support\Test\TestUser; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; +use Symfony\Component\Security\Core\Exception\UserNotFoundException; class UserProviderTest extends DachcomBundleTestCase { @@ -28,7 +30,7 @@ public function testLoadUserByIdentifier(): void $this->userManager->expects($this->once()) ->method('findUserByUsername') ->with('foobar') - ->will($this->returnValue($user)); + ->willReturn($user); $this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar')); } @@ -38,9 +40,9 @@ public function testLoadUserByInvalidUsername(): void $this->userManager->expects($this->once()) ->method('findUserByUsername') ->with('foobar') - ->will($this->returnValue(null)); + ->willReturn(null); - $this->expectException(\Symfony\Component\Security\Core\Exception\UserNotFoundException::class); + $this->expectException(UserNotFoundException::class); $this->userProvider->loadUserByIdentifier('foobar'); } @@ -52,34 +54,36 @@ public function testRefreshUserBy(): void $user->expects($this->once()) ->method('getId') - ->will($this->returnValue(2)); + ->willReturn(2); $refreshedUser = $this->getMockBuilder(UserInterface::class)->getMock(); $this->userManager->expects($this->once()) ->method('findUserByCondition') ->with('oo_id = ?', [2]) - ->will($this->returnValue($refreshedUser)); + ->willReturn($refreshedUser); $this->userManager->expects($this->atLeastOnce()) ->method('getClass') - ->will($this->returnValue(get_class($user))); + ->willReturn(get_class($user)); $this->assertSame($refreshedUser, $this->userProvider->refreshUser($user)); } public function testRefreshDeleted(): void { - $user = $this->getMockForAbstractClass(MembersUser::class); + $user = $this->getMockBuilder(MembersUser::class) + ->getMock(); $this->userManager->expects($this->once()) ->method('findUserByCondition') ->willReturn(null); $this->userManager->expects($this->atLeastOnce()) ->method('getClass') - ->will($this->returnValue(get_class($user))); + ->willReturn(get_class($user)); + + $this->expectException(UserNotFoundException::class); - $this->expectException(\Symfony\Component\Security\Core\Exception\UserNotFoundException::class); $this->userProvider->refreshUser($user); } @@ -90,7 +94,7 @@ public function testRefreshInvalidUser(): void ->method('getClass') ->willReturn(get_class($user)); - $this->expectException(\Symfony\Component\Security\Core\Exception\UnsupportedUserException::class); + $this->expectException(UnsupportedUserException::class); $this->userProvider->refreshUser($user); } @@ -103,7 +107,7 @@ public function testRefreshInvalidUserClass(): void ->method('getClass') ->willReturn(get_class($user)); - $this->expectException(\Symfony\Component\Security\Core\Exception\UnsupportedUserException::class); + $this->expectException(UnsupportedUserException::class); $this->userProvider->refreshUser($providedUser); } }