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