[TASK] typo3/testing-framework now flushes runtime caches
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Authentication / AbstractUserAuthenticationTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Authentication;
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
18 use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
19 use Prophecy\Argument;
20 use Prophecy\Prophecy\ObjectProphecy;
21 use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
22 use TYPO3\CMS\Core\Database\Connection;
23 use TYPO3\CMS\Core\Database\ConnectionPool;
24 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
25 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
26 use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29
30 /**
31 * Testcase for class \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
32 */
33 class AbstractUserAuthenticationTest extends UnitTestCase
34 {
35 /**
36 * @test
37 */
38 public function getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven()
39 {
40 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
41
42 /** @var Connection|ObjectProphecy $connection */
43 $connection = $this->prophesize(Connection::class);
44 $connection->getDatabasePlatform()->willReturn(new MockPlatform());
45 $connection->getExpressionBuilder()->willReturn(new ExpressionBuilder($connection->reveal()));
46
47 // TODO: This should rather be a functional test if we need a query builder
48 // or we should clean up the code itself to not need to mock internal behavior here
49 $queryBuilder = new QueryBuilder(
50 $connection->reveal(),
51 null,
52 $this->prophesize(DoctrineQueryBuilder::class)->reveal()
53 );
54
55 /** @var ConnectionPool|ObjectProphecy $connection */
56 $connectionPool = $this->prophesize(ConnectionPool::class);
57 $connectionPool->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilder);
58
59 GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
60
61 /** @var $mock \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication */
62 $mock = $this->getMockBuilder(AbstractUserAuthentication::class)
63 ->setMethods(['dummy'])
64 ->getMock();
65 $mock->checkPid = true;
66 $mock->checkPid_value = null;
67 $mock->user_table = 'be_users';
68 $result = $mock->getAuthInfoArray();
69 $this->assertEquals('', $result['db_user']['checkPidList']);
70 }
71
72 /**
73 * @test
74 */
75 public function getHttpHeadersReturnsNormalNoCacheHeadersForNonIe()
76 {
77 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.2; rv:22.0) Gecko/20130405 Firefox/23.0';
78 $_SERVER['HTTPS'] = 'on';
79 $subject = $this->getAccessibleMockForAbstractClass(AbstractUserAuthentication::class);
80 $result = $subject->_call('getHttpHeaders');
81 $this->assertEquals($result['Pragma'], 'no-cache');
82 }
83
84 /**
85 * @test
86 */
87 public function getHttpHeadersReturnsSpecialNoCacheHeadersForIe()
88 {
89 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)';
90 $_SERVER['HTTPS'] = 'on';
91 $subject = $this->getAccessibleMockForAbstractClass(AbstractUserAuthentication::class);
92 $result = $subject->_call('getHttpHeaders');
93 $this->assertEquals($result['Pragma'], 'private');
94 }
95 }