f79311f8389b9483f7ff02ca65847cfd13f95016
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Authentication / AbstractUserAuthenticationTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Authentication;
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 Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Core\Database\Connection;
20 use TYPO3\CMS\Core\Database\ConnectionPool;
21 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
22 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
23 use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26 /**
27 * Testcase for class \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
28 *
29 */
30 class AbstractUserAuthenticationTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
31 {
32 /**
33 * @test
34 */
35 public function getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven()
36 {
37 /** @var Connection|ObjectProphecy $connection */
38 $connection = $this->prophesize(Connection::class);
39 $connection->getDatabasePlatform()->willReturn(new MockPlatform());
40 $connection->getExpressionBuilder()->willReturn(new ExpressionBuilder($connection->reveal()));
41
42 // TODO: This should rather be a functional test if we need a query builder
43 // or we should clean up the code itself to not need to mock internal behavior here
44 $queryBuilder = new QueryBuilder(
45 $connection->reveal(),
46 null,
47 $this->prophesize(\Doctrine\DBAL\Query\QueryBuilder::class)->reveal()
48 );
49
50 /** @var ConnectionPool|ObjectProphecy $connection */
51 $connectionPool = $this->prophesize(ConnectionPool::class);
52 $connectionPool->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilder);
53
54 GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
55
56 /** @var $mock \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication */
57 $mock = $this->getMockBuilder(\TYPO3\CMS\Core\Authentication\AbstractUserAuthentication::class)
58 ->setMethods(['dummy'])
59 ->getMock();
60 $mock->checkPid = true;
61 $mock->checkPid_value = null;
62 $mock->user_table = 'be_users';
63 $result = $mock->getAuthInfoArray();
64 $this->assertEquals('', $result['db_user']['checkPidList']);
65 }
66 }