‪TYPO3CMS  9.5
AbstractUserAuthenticationTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
19 use Prophecy\Argument;
20 use Prophecy\Prophecy\ObjectProphecy;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪AbstractUserAuthenticationTest extends UnitTestCase
34 {
39  {
40  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
41 
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 
56  $connectionPool = $this->prophesize(ConnectionPool::class);
57  $connectionPool->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilder);
58 
59  GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
60 
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 
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 
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 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest\getHttpHeadersReturnsNormalNoCacheHeadersForNonIe
‪getHttpHeadersReturnsNormalNoCacheHeadersForNonIe()
Definition: AbstractUserAuthenticationTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest\getHttpHeadersReturnsSpecialNoCacheHeadersForIe
‪getHttpHeadersReturnsSpecialNoCacheHeadersForIe()
Definition: AbstractUserAuthenticationTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Authentication
Definition: AbstractUserAuthenticationTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest
Definition: AbstractUserAuthenticationTest.php:34
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform
Definition: MockPlatform.php:21
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest\getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven
‪getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven()
Definition: AbstractUserAuthenticationTest.php:38
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51