‪TYPO3CMS  10.4
FrontendUserRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪FrontendUserRepositoryTest extends FunctionalTestCase
28 {
32  protected ‪$coreExtensionsToLoad = ['extbase', 'felogin'];
33 
37  protected ‪$repository;
38 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42 
43  $context = new ‪Context();
44  ‪$GLOBALS['TSFE'] = static::getMockBuilder(TypoScriptFrontendController::class)
45  ->disableOriginalConstructor()
46  ->getMock()
47  ;
48 
49  ‪$GLOBALS['TSFE']->fe_user = new ‪FrontendUserAuthentication();
50 
51  $this->repository = new ‪FrontendUserRepository(
52  new ‪UserService(),
53  $context
54  );
55 
56  $this->importDataSet(__DIR__ . '/../../Fixtures/fe_users.xml');
57  }
58 
62  public function ‪getTable()
63  {
64  self::assertSame('fe_users', $this->repository->getTable());
65  }
66 
70  public function ‪findEmailByUsernameOrEmailOnPages()
71  {
72  self::assertNull($this->repository->findEmailByUsernameOrEmailOnPages(''));
73  self::assertNull($this->repository->findEmailByUsernameOrEmailOnPages('non-existent-email-or-username'));
74  self::assertNull($this->repository->findEmailByUsernameOrEmailOnPages('user-with-username-without-email'));
75  self::assertNull($this->repository->findEmailByUsernameOrEmailOnPages('foobar', [99]));
76 
77  self::assertSame('foo@bar.baz', $this->repository->findEmailByUsernameOrEmailOnPages('foobar'));
78  self::assertSame('foo@bar.baz', $this->repository->findEmailByUsernameOrEmailOnPages('foo@bar.baz'));
79  }
80 
84  public function ‪existsUserWithHash()
85  {
86  self::assertFalse($this->repository->existsUserWithHash('non-existent-hash'));
87  self::assertTrue($this->repository->existsUserWithHash('cf8edd6fa435b4a9fcbb953f81bd84f2'));
88  }
89 
96  public function ‪fetchUserInformationByEmail(string $emailAddress, array $expected)
97  {
98  // strval() is used since not all of the DBMS return an integer for the "uid" field
99  self::assertSame($expected, array_map('strval', $this->repository->fetchUserInformationByEmail($emailAddress)));
100  }
101 
102  public function ‪fetchUserInformationByEmailDataProvider(): array
103  {
104  return [
105  'foo@bar.baz' => [
106  'foo@bar.baz',
107  [
108  'uid' => '1',
109  'username' => 'foobar',
110  'email' => 'foo@bar.baz',
111  'first_name' => '',
112  'middle_name' => '',
113  'last_name' => '',
114  ]
115  ],
116  '' => [
117  '',
118  [
119  'uid' => '2',
120  'username' => 'user-with-username-without-email',
121  'email' => '',
122  'first_name' => '',
123  'middle_name' => '',
124  'last_name' => '',
125  ]
126  ],
127  'non existing user' => [
128  'non-existing@user.com',
129  []
130  ],
131  ];
132  }
133 
137  public function ‪findOneByForgotPasswordHash()
138  {
139  self::assertNull($this->repository->findOneByForgotPasswordHash(''));
140  self::assertNull($this->repository->findOneByForgotPasswordHash('non-existent-hash'));
141  self::assertIsArray($this->repository->findOneByForgotPasswordHash('cf8edd6fa435b4a9fcbb953f81bd84f2'));
142  }
143 
147  public function ‪findRedirectIdPageByUserId()
148  {
149  self::assertNull($this->repository->findRedirectIdPageByUserId(99));
150  self::assertSame(10, $this->repository->findRedirectIdPageByUserId(1));
151  }
152 
156  public function ‪updateForgotHashForUserByEmail()
157  {
158  $email = 'foo@bar.baz';
159  $newPasswordHash = 'new-hash';
160 
161  $this->repository->updateForgotHashForUserByEmail($email, $newPasswordHash);
162 
163  $queryBuilder = $this->getConnectionPool()
164  ->getConnectionForTable('fe_users')
165  ->createQueryBuilder();
166 
167  $query = $queryBuilder
168  ->select('felogin_forgotHash')
169  ->from('fe_users')
170  ->where($queryBuilder->expr()->eq(
171  'email',
172  $queryBuilder->createNamedParameter($email)
173  ))
174  ;
175 
176  self::assertSame($newPasswordHash, $query->execute()->fetchColumn());
177  }
178 
182  public function ‪updatePasswordAndInvalidateHash()
183  {
184  $this->repository->updatePasswordAndInvalidateHash('cf8edd6fa435b4a9fcbb953f81bd84f2', 'new-password');
185 
186  $queryBuilder = $this->getConnectionPool()
187  ->getConnectionForTable('fe_users')
188  ->createQueryBuilder();
189 
190  $query = $queryBuilder
191  ->select('*')
192  ->from('fe_users')
193  ->where($queryBuilder->expr()->eq(
194  'uid',
195  $queryBuilder->createNamedParameter(1)
196  ))
197  ;
198 
199  $user = $query->execute()->fetch();
200 
201  self::assertSame('new-password', $user['password']);
202  self::assertSame('', $user['felogin_forgotHash']);
203  }
204 }
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\updatePasswordAndInvalidateHash
‪updatePasswordAndInvalidateHash()
Definition: FrontendUserRepositoryTest.php:180
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\fetchUserInformationByEmailDataProvider
‪fetchUserInformationByEmailDataProvider()
Definition: FrontendUserRepositoryTest.php:100
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\getTable
‪getTable()
Definition: FrontendUserRepositoryTest.php:60
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: FrontendUserRepositoryTest.php:31
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository
Definition: FrontendUserRepository.php:31
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\findOneByForgotPasswordHash
‪findOneByForgotPasswordHash()
Definition: FrontendUserRepositoryTest.php:135
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\$repository
‪FrontendUserRepository $repository
Definition: FrontendUserRepositoryTest.php:35
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\existsUserWithHash
‪existsUserWithHash()
Definition: FrontendUserRepositoryTest.php:82
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\fetchUserInformationByEmail
‪fetchUserInformationByEmail(string $emailAddress, array $expected)
Definition: FrontendUserRepositoryTest.php:94
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\FrontendLogin\Service\UserService
Definition: UserService.php:26
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest
Definition: FrontendUserRepositoryTest.php:28
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\findRedirectIdPageByUserId
‪findRedirectIdPageByUserId()
Definition: FrontendUserRepositoryTest.php:145
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\setUp
‪setUp()
Definition: FrontendUserRepositoryTest.php:37
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\updateForgotHashForUserByEmail
‪updateForgotHashForUserByEmail()
Definition: FrontendUserRepositoryTest.php:154
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:30
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository\FrontendUserRepositoryTest\findEmailByUsernameOrEmailOnPages
‪findEmailByUsernameOrEmailOnPages()
Definition: FrontendUserRepositoryTest.php:68
‪TYPO3\CMS\FrontendLogin\Tests\Functional\Domain\Repository
Definition: FrontendUserGroupRepositoryTest.php:18