TYPO3 CMS  TYPO3_8-7
AdminPanelViewTest.php
Go to the documentation of this file.
1 <?php
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  */
19 
23 class AdminPanelViewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
28  protected function setUp()
29  {
30  $GLOBALS['LANG'] = $this->createMock(LanguageService::class);
31  $GLOBALS['TSFE'] = new TypoScriptFrontendController([], 1, 1);
32  }
33 
38  {
39  $strTime = '2013-01-01 01:00:00';
40  $timestamp = strtotime($strTime);
41 
42  $backendUser = $this->getMockBuilder(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class)->getMock();
43  $backendUser->uc['TSFE_adminConfig']['preview_simulateDate'] = $timestamp;
44  unset($backendUser->extAdminConfig['override.']['preview.']);
45  unset($backendUser->extAdminConfig['override.']['preview']);
46  $GLOBALS['BE_USER'] = $backendUser;
47 
48  $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
49  ->setMethods(['isAdminModuleEnabled', 'isAdminModuleOpen'])
50  ->disableOriginalConstructor()
51  ->getMock();
52  $adminPanelMock->expects($this->any())->method('isAdminModuleEnabled')->will($this->returnValue(true));
53  $adminPanelMock->expects($this->any())->method('isAdminModuleOpen')->will($this->returnValue(true));
54 
55  $timestampReturned = $adminPanelMock->extGetFeAdminValue('preview', 'simulateDate');
56  $this->assertEquals($timestamp, $timestampReturned);
57  }
58 
60  // Test concerning extendAdminPanel hook
62 
66  public function extendAdminPanelHookThrowsExceptionIfHookClassDoesNotImplementInterface()
67  {
68  $this->expectException(\UnexpectedValueException::class);
69  $this->expectExceptionCode(1311942539);
70  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = \TYPO3\CMS\Frontend\Tests\Unit\Fixtures\AdminPanelHookWithoutInterfaceFixture::class;
72  $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
73  ->setMethods(['dummy'])
74  ->disableOriginalConstructor()
75  ->getMock();
76  $adminPanelMock->display();
77  }
78 
82  public function extendAdminPanelHookCallsExtendAdminPanelMethodOfHook()
83  {
84  $hookClass = $this->getUniqueId('tx_coretest');
85  $hookMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface::class)
86  ->setMockClassName($hookClass)
87  ->getMock();
88  GeneralUtility::addInstance($hookClass, $hookMock);
89  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass;
91  $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
92  ->setMethods(['extGetLL'])
93  ->disableOriginalConstructor()
94  ->getMock();
95  $adminPanelMock->initialize();
96  $hookMock->expects($this->once())->method('extendAdminPanel')->with($this->isType('string'), $this->isInstanceOf(\TYPO3\CMS\Frontend\View\AdminPanelView::class));
97  $adminPanelMock->display();
98  }
99 }
static addInstance($className, $instance)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']