[TASK] Re-work/simplify copyright header in PHP files - Part 4
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / TypoScript / TemplateServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
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\ExtensionManagementUtility;
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Testcase for \TYPO3\CMS\Core\TypoScript\TemplateService
21 *
22 * @author Christian Kuhn <lolli@schwarzbu.ch>
23 */
24 class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * Enable backup of global and system variables
28 *
29 * @var boolean
30 */
31 protected $backupGlobals = TRUE;
32
33 /**
34 * @var \TYPO3\CMS\Core\TypoScript\TemplateService
35 */
36 protected $templateService;
37
38 /**
39 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Core\TypoScript\TemplateService
40 */
41 protected $templateServiceMock;
42
43 /**
44 * Sets up this test case.
45 *
46 * @return void
47 */
48 protected function setUp() {
49 $GLOBALS['TYPO3_LOADED_EXT'] = array();
50 $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
51 $this->templateServiceMock = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
52 }
53
54 /**
55 * @test
56 */
57 public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow() {
58 $row = array('foo');
59 $GLOBALS['TSFE'] = new \stdClass();
60 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
61 $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
62 $GLOBALS['TSFE']->sys_page = $sysPageMock;
63 $this->templateService->versionOL($row);
64 }
65
66 /**
67 * @test
68 */
69 public function extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested() {
70 $identifier = uniqid('test');
71 $GLOBALS['TYPO3_LOADED_EXT'] = array(
72 $identifier => array(
73 'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
74 'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
75 ),
76 ),
77 );
78
79 $this->templateService->runThroughTemplates(array(), 0);
80 $this->assertFalse(
81 in_array('test.Core.TypoScript = 1', $this->templateService->config)
82 );
83 }
84
85 /**
86 * @test
87 */
88 public function extensionStaticsAreProcessedIfExplicitlyRequested() {
89 $identifier = uniqid('test');
90 $GLOBALS['TYPO3_LOADED_EXT'] = array(
91 $identifier => array(
92 'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
93 'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
94 ),
95 'ext_typoscript_constants.txt' => ''
96 ),
97 );
98
99 $mockPackage = $this->getMock('TYPO3\\CMS\\Core\\Package\\Package', array('getPackagePath'), array(), '', FALSE);
100 $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
101
102 $mockPackageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive' , 'getPackage'));
103 $mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(TRUE));
104 $mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
105 ExtensionManagementUtility::setPackageManager($mockPackageManager);
106
107 $this->templateService->setProcessExtensionStatics(TRUE);
108 $this->templateService->runThroughTemplates(array(), 0);
109
110 $this->assertTrue(
111 in_array('test.Core.TypoScript = 1', $this->templateService->config)
112 );
113
114 ExtensionManagementUtility::setPackageManager(GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager'));
115 }
116
117 /**
118 * @test
119 */
120 public function updateRootlineDataOverwritesOwnArrayData() {
121 $originalRootline = array(
122 0 => array('uid' => 2, 'title' => 'originalTitle'),
123 1 => array('uid' => 3, 'title' => 'originalTitle2'),
124 );
125
126 $updatedRootline = array(
127 0 => array('uid' => 1, 'title' => 'newTitle'),
128 1 => array('uid' => 2, 'title' => 'newTitle2'),
129 2 => array('uid' => 3, 'title' => 'newTitle3'),
130 );
131
132 $expectedRootline = array(
133 0 => array('uid' => 2, 'title' => 'newTitle2'),
134 1 => array('uid' => 3, 'title' => 'newTitle3'),
135 );
136
137 $this->templateServiceMock->_set('rootLine', $originalRootline);
138 $this->templateServiceMock->updateRootlineData($updatedRootline);
139 $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
140 }
141
142 /**
143 * @test
144 * @expectedException \RuntimeException
145 */
146 public function updateRootlineDataWithInvalidNewRootlineThrowsException() {
147 $originalRootline = array(
148 0 => array('uid' => 2, 'title' => 'originalTitle'),
149 1 => array('uid' => 3, 'title' => 'originalTitle2'),
150 );
151
152 $newInvalidRootline = array(
153 0 => array('uid' => 1, 'title' => 'newTitle'),
154 1 => array('uid' => 2, 'title' => 'newTitle2'),
155 );
156
157 $this->templateServiceMock->_set('rootLine', $originalRootline);
158 $this->templateServiceMock->updateRootlineData($newInvalidRootline);
159 }
160
161 }