ffe2038b523c09c67aa16d6866346a8719e9495d
[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
18 /**
19 * Test case
20 */
21 class AdminPanelViewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
23 /**
24 * Set up
25 */
26 protected function setUp()
27 {
28 $GLOBALS['LANG'] = $this->createMock(\TYPO3\CMS\Lang\LanguageService::class);
29 }
30
31 /**
32 * @test
33 */
34 public function extGetFeAdminValueReturnsTimestamp()
35 {
36 $strTime = '2013-01-01 01:00:00';
37 $timestamp = strtotime($strTime);
38
39 $backendUser = $this->getMockBuilder(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class)->getMock();
40 $backendUser->uc['TSFE_adminConfig']['preview_simulateDate'] = $timestamp;
41 unset($backendUser->extAdminConfig['override.']['preview.']);
42 unset($backendUser->extAdminConfig['override.']['preview']);
43 $GLOBALS['BE_USER'] = $backendUser;
44
45 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
46 ->setMethods(['isAdminModuleEnabled', 'isAdminModuleOpen'])
47 ->disableOriginalConstructor()
48 ->getMock();
49 $adminPanelMock->expects($this->any())->method('isAdminModuleEnabled')->will($this->returnValue(true));
50 $adminPanelMock->expects($this->any())->method('isAdminModuleOpen')->will($this->returnValue(true));
51
52 $timestampReturned = $adminPanelMock->extGetFeAdminValue('preview', 'simulateDate');
53 $this->assertEquals($timestamp, $timestampReturned);
54 }
55
56 /////////////////////////////////////////////
57 // Test concerning extendAdminPanel hook
58 /////////////////////////////////////////////
59
60 /**
61 * @test
62 */
63 public function extendAdminPanelHookThrowsExceptionIfHookClassDoesNotImplementInterface()
64 {
65 $this->expectException(\UnexpectedValueException::class);
66 $this->expectExceptionCode(1311942539);
67 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = \TYPO3\CMS\Frontend\Tests\Unit\Fixtures\AdminPanelHookWithoutInterfaceFixture::class;
68 /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */
69 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
70 ->setMethods(['dummy'])
71 ->disableOriginalConstructor()
72 ->getMock();
73 $adminPanelMock->display();
74 }
75
76 /**
77 * @test
78 */
79 public function extendAdminPanelHookCallsExtendAdminPanelMethodOfHook()
80 {
81 $hookClass = $this->getUniqueId('tx_coretest');
82 $hookMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface::class)
83 ->setMockClassName($hookClass)
84 ->getMock();
85 GeneralUtility::addInstance($hookClass, $hookMock);
86 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass;
87 /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */
88 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
89 ->setMethods(['extGetLL'])
90 ->disableOriginalConstructor()
91 ->getMock();
92 $hookMock->expects($this->once())->method('extendAdminPanel')->with($this->isType('string'), $this->isInstanceOf(\TYPO3\CMS\Frontend\View\AdminPanelView::class));
93 $adminPanelMock->display();
94 }
95 }