[TASK] Add framework for frontend rendering functional tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Framework / Frontend / Hook / BackendUserHandler.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Hook;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use \TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * Handler for backend user
31 */
32 class BackendUserHandler implements \TYPO3\CMS\Core\SingletonInterface {
33
34 /**
35 * @param array $parameters
36 * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $frontendController
37 */
38 public function initialize(array $parameters, \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $frontendController) {
39 $backendUserId = (int)GeneralUtility::_GP('backendUserId');
40 $workspaceId = (int)GeneralUtility::_GP('workspaceId');
41
42 if (empty($backendUserId) || empty($workspaceId)) {
43 return;
44 }
45
46 $backendUser = $this->createBackendUser();
47 $backendUser->user = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'be_users', 'uid=' . $backendUserId);
48 $backendUser->setTemporaryWorkspace($workspaceId);
49 $frontendController->beUserLogin = 1;
50
51 $parameters['BE_USER'] = $backendUser;
52 $GLOBALS['BE_USER'] = $backendUser;
53 }
54
55 /**
56 * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
57 */
58 protected function createBackendUser() {
59 return GeneralUtility::makeInstance(
60 'TYPO3\\CMS\\Backend\\FrontendBackendUserAuthentication'
61 );
62 }
63
64 /**
65 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
66 */
67 protected function getDatabaseConnection() {
68 return $GLOBALS['TYPO3_DB'];
69 }
70
71 }