[TASK] Streamline Admin Panel
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / View / AdminPanelViewTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\View;
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 */
16 use TYPO3\CMS\Core\Utility\GeneralUtility;
17 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
18 use TYPO3\CMS\Lang\LanguageService;
19
20 /**
21 * Test case
22 */
23 class AdminPanelViewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * Set up
27 */
28 protected function setUp()
29 {
30 $GLOBALS['LANG'] = $this->createMock(LanguageService::class);
31 $GLOBALS['TSFE'] = new TypoScriptFrontendController([], 1, 1);
32 }
33
34 /**
35 * @test
36 */
37 public function extGetFeAdminValueReturnsTimestamp()
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
59 /////////////////////////////////////////////
60 // Test concerning extendAdminPanel hook
61 /////////////////////////////////////////////
62
63 /**
64 * @test
65 */
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;
71 /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */
72 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
73 ->setMethods(['dummy'])
74 ->disableOriginalConstructor()
75 ->getMock();
76 $adminPanelMock->display();
77 }
78
79 /**
80 * @test
81 */
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;
90 /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */
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 }