‪TYPO3CMS  10.4
AbstractUserAuthenticationTest.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 
20 use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
21 use Prophecy\Argument;
22 use Prophecy\Prophecy\ObjectProphecy;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪AbstractUserAuthenticationTest extends UnitTestCase
36 {
41  {
42  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
43 
45  $connection = $this->prophesize(Connection::class);
46  $connection->getDatabasePlatform()->willReturn(new ‪MockPlatform());
47  $connection->getExpressionBuilder()->willReturn(new ‪ExpressionBuilder($connection->reveal()));
48 
49  // TODO: This should rather be a functional test if we need a query builder
50  // or we should clean up the code itself to not need to mock internal behavior here
51  $queryBuilder = new ‪QueryBuilder(
52  $connection->reveal(),
53  null,
54  $this->prophesize(DoctrineQueryBuilder::class)->reveal()
55  );
56 
58  $connectionPool = $this->prophesize(ConnectionPool::class);
59  $connectionPool->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilder);
60 
61  GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
62 
64  $mock = $this->getMockBuilder(AbstractUserAuthentication::class)
65  ->setMethods(['dummy'])
66  ->disableOriginalConstructor()
67  ->getMock();
68  $mock->loginType = 'BE';
69  $mock->checkPid = true;
70  $mock->checkPid_value = null;
71  $mock->user_table = 'be_users';
72  $result = $mock->getAuthInfoArray();
73  self::assertEquals('', $result['db_user']['checkPidList']);
74  }
75 
80  {
81  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.2; rv:22.0) Gecko/20130405 Firefox/23.0';
82  $_SERVER['HTTPS'] = 'on';
83  $subject = $this->getAccessibleMockForAbstractClass(AbstractUserAuthentication::class, [], '', false);
84  $subject->_set('loginType', 'BE');
85  $result = $subject->_call('getHttpHeaders');
86  self::assertEquals($result['Pragma'], 'no-cache');
87  }
88 
93  {
94  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)';
95  $_SERVER['HTTPS'] = 'on';
96  $subject = $this->getAccessibleMockForAbstractClass(AbstractUserAuthentication::class, [], '', false);
97  $result = $subject->_call('getHttpHeaders');
98  self::assertEquals($result['Pragma'], 'private');
99  }
100 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest\getHttpHeadersReturnsNormalNoCacheHeadersForNonIe
‪getHttpHeadersReturnsNormalNoCacheHeadersForNonIe()
Definition: AbstractUserAuthenticationTest.php:79
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest\getHttpHeadersReturnsSpecialNoCacheHeadersForIe
‪getHttpHeadersReturnsSpecialNoCacheHeadersForIe()
Definition: AbstractUserAuthenticationTest.php:92
‪TYPO3\CMS\Core\Tests\Unit\Authentication
Definition: AbstractUserAuthenticationTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest
Definition: AbstractUserAuthenticationTest.php:36
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:52
‪TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform
Definition: MockPlatform.php:22
‪TYPO3\CMS\Core\Tests\Unit\Authentication\AbstractUserAuthenticationTest\getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven
‪getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven()
Definition: AbstractUserAuthenticationTest.php:40
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51