4d910dbb469313aa528df804ab970d9e6a7e1b53
[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 Prophecy\Argument;
17 use TYPO3\CMS\Core\Cache\CacheManager;
18 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Localization\LanguageService;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
24
25 /**
26 * Test case
27 */
28 class AdminPanelViewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
30 /**
31 * Subject is not notice free, disable E_NOTICES
32 */
33 protected static $suppressNotices = true;
34
35 /**
36 * Set up
37 */
38 protected function setUp()
39 {
40 $GLOBALS['LANG'] = $this->createMock(LanguageService::class);
41 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
42 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
43 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
44 $cacheManagerProphecy->getCache('cache_pages')->willReturn($cacheFrontendProphecy->reveal());
45 $GLOBALS['TSFE'] = new TypoScriptFrontendController([], 1, 1);
46 }
47
48 protected function tearDown()
49 {
50 GeneralUtility::purgeInstances();
51 parent::tearDown();
52 }
53
54 /**
55 * @test
56 */
57 public function extGetFeAdminValueReturnsTimestamp()
58 {
59 $strTime = '2013-01-01 01:00:00';
60 $timestamp = strtotime($strTime);
61
62 $backendUser = $this->getMockBuilder(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class)->getMock();
63 $backendUser->uc['TSFE_adminConfig']['preview_simulateDate'] = $timestamp;
64 unset($backendUser->extAdminConfig['override.']['preview.']);
65 unset($backendUser->extAdminConfig['override.']['preview']);
66 $GLOBALS['BE_USER'] = $backendUser;
67
68 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
69 ->setMethods(['isAdminModuleEnabled', 'isAdminModuleOpen'])
70 ->disableOriginalConstructor()
71 ->getMock();
72 $adminPanelMock->expects($this->any())->method('isAdminModuleEnabled')->will($this->returnValue(true));
73 $adminPanelMock->expects($this->any())->method('isAdminModuleOpen')->will($this->returnValue(true));
74
75 $timestampReturned = $adminPanelMock->extGetFeAdminValue('preview', 'simulateDate');
76 $this->assertEquals($timestamp, $timestampReturned);
77 }
78
79 /////////////////////////////////////////////
80 // Test concerning extendAdminPanel hook
81 /////////////////////////////////////////////
82
83 /**
84 * @test
85 */
86 public function extendAdminPanelHookThrowsExceptionIfHookClassDoesNotImplementInterface()
87 {
88 $this->expectException(\UnexpectedValueException::class);
89 $this->expectExceptionCode(1311942539);
90 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = \TYPO3\CMS\Frontend\Tests\Unit\Fixtures\AdminPanelHookWithoutInterfaceFixture::class;
91 /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */
92 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
93 ->setMethods(['dummy'])
94 ->disableOriginalConstructor()
95 ->getMock();
96 $adminPanelMock->display();
97 }
98
99 /**
100 * @test
101 */
102 public function extendAdminPanelHookCallsExtendAdminPanelMethodOfHook()
103 {
104 $hookClass = $this->getUniqueId('tx_coretest');
105 $hookMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface::class)
106 ->setMockClassName($hookClass)
107 ->getMock();
108 GeneralUtility::addInstance($hookClass, $hookMock);
109 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass;
110 /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */
111 $adminPanelMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\View\AdminPanelView::class)
112 ->setMethods(['extGetLL'])
113 ->disableOriginalConstructor()
114 ->getMock();
115 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
116 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
117 $iconProphecy = $this->prophesize(Icon::class);
118 $iconFactoryProphecy->getIcon(Argument::cetera())->willReturn($iconProphecy->reveal());
119 $iconProphecy->render(Argument::cetera())->willReturn('');
120 $adminPanelMock->initialize();
121 $hookMock->expects($this->once())->method('extendAdminPanel')->with($this->isType('string'), $this->isInstanceOf(\TYPO3\CMS\Frontend\View\AdminPanelView::class));
122 $adminPanelMock->display();
123 }
124 }