[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / saltedpasswords / Tests / Functional / SaltedPasswordServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Saltedpasswords\Tests\Functional;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Saltedpasswords\SaltedPasswordService;
20
21 /**
22 * Test case for \TYPO3\CMS\Saltedpasswords\SaltedPasswordService
23 */
24 class SaltedPasswordServiceTest extends \TYPO3\CMS\Components\TestingFramework\Core\FunctionalTestCase
25 {
26
27 /**
28 * XML database fixtures to be loaded into database.
29 *
30 * @var array
31 */
32 protected $xmlDatabaseFixtures = [
33 'typo3/sysext/saltedpasswords/Tests/Functional/Fixtures/be_users.xml'
34 ];
35
36 /**
37 * @var SaltedPasswordService
38 */
39 protected $subject;
40
41 /**
42 * Sets up this test suite.
43 *
44 * @return void
45 */
46 protected function setUp()
47 {
48 parent::setUp();
49 foreach ($this->xmlDatabaseFixtures as $fixture) {
50 $this->importDataSet($fixture);
51 }
52 $this->subject = GeneralUtility::makeInstance(SaltedPasswordService::class);
53 }
54
55 /**
56 * Check if service updates backend user password
57 *
58 * @test
59 */
60 public function checkIfServiceUpdatesBackendUserPassword()
61 {
62 $newPassword = ['password' => '008c5926ca861023c1d2a36653fd88e2'];
63
64 $this->subject->pObj = new \stdClass();
65 $this->subject->pObj->user_table = 'be_users';
66
67 $this->callInaccessibleMethod($this->subject, 'updatePassword', 3, $newPassword);
68
69 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
70
71 $currentPassword = $queryBuilder
72 ->select('password')
73 ->from('be_users')
74 ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(3, \PDO::PARAM_INT)))
75 ->execute()
76 ->fetchColumn();
77
78 $this->assertEquals($newPassword['password'], $currentPassword);
79 }
80 }