[FEATURE] Integrate preliminary PackageManager API
[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 * Copyright notice
6 *
7 * (c) 2012-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for \TYPO3\CMS\Core\TypoScript\TemplateService
29 *
30 * @author Christian Kuhn <lolli@schwarzbu.ch>
31 */
32 class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * Enable backup of global and system variables
36 *
37 * @var boolean
38 */
39 protected $backupGlobals = TRUE;
40
41 /**
42 * @var \TYPO3\CMS\Core\TypoScript\TemplateService
43 */
44 protected $templateService;
45
46 /**
47 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Core\TypoScript\TemplateService
48 */
49 protected $templateServiceMock;
50
51 protected $backupTypo3LoadedExt;
52
53 /**
54 * Sets up this test case.
55 *
56 * @return void
57 */
58 protected function setUp() {
59 $this->backupTypo3LoadedExt = $GLOBALS['TYPO3_LOADED_EXT'];
60 $GLOBALS['TYPO3_LOADED_EXT'] = array();
61 $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
62 $this->templateServiceMock = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
63 }
64
65 /**
66 * Tears down this test case.
67 *
68 * @return void
69 */
70 protected function tearDown() {
71 $GLOBALS['TYPO3_LOADED_EXT'] = $this->backupTypo3LoadedExt;
72 unset($this->templateService);
73 unset($this->templateServiceMock);
74 }
75
76 /**
77 * @test
78 */
79 public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow() {
80 $row = array('foo');
81 $GLOBALS['TSFE'] = new \stdClass();
82 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
83 $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
84 $GLOBALS['TSFE']->sys_page = $sysPageMock;
85 $this->templateService->versionOL($row);
86 }
87
88 /**
89 * @test
90 */
91 public function extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested() {
92 $identifier = uniqid('test');
93 $GLOBALS['TYPO3_LOADED_EXT'] = array(
94 $identifier => array(
95 'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
96 'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
97 ),
98 ),
99 );
100
101 $this->templateService->runThroughTemplates(array(), 0);
102 $this->assertFalse(
103 in_array('test.Core.TypoScript = 1', $this->templateService->config)
104 );
105 }
106
107 /**
108 * @test
109 */
110 public function extensionStaticsAreProcessedIfExplicitlyRequested() {
111 $identifier = uniqid('test');
112 $GLOBALS['TYPO3_LOADED_EXT'] = array(
113 $identifier => array(
114 'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
115 'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
116 ),
117 ),
118 );
119
120 $this->templateService->setProcessExtensionStatics(TRUE);
121 $this->templateService->runThroughTemplates(array(), 0);
122 $this->assertTrue(
123 in_array('test.Core.TypoScript = 1', $this->templateService->config)
124 );
125 }
126
127 /**
128 * @test
129 */
130 public function updateRootlineDataOverwritesOwnArrayData() {
131 $originalRootline = array(
132 0 => array('uid' => 2, 'title' => 'originalTitle'),
133 1 => array('uid' => 3, 'title' => 'originalTitle2'),
134 );
135
136 $updatedRootline = array(
137 0 => array('uid' => 1, 'title' => 'newTitle'),
138 1 => array('uid' => 2, 'title' => 'newTitle2'),
139 2 => array('uid' => 3, 'title' => 'newTitle3'),
140 );
141
142 $expectedRootline = array(
143 0 => array('uid' => 2, 'title' => 'newTitle2'),
144 1 => array('uid' => 3, 'title' => 'newTitle3'),
145 );
146
147 $this->templateServiceMock->_set('rootLine', $originalRootline);
148 $this->templateServiceMock->updateRootlineData($updatedRootline);
149 $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
150 }
151
152 /**
153 * @test
154 * @expectedException \RuntimeException
155 */
156 public function updateRootlineDataWithInvalidNewRootlineThrowsException() {
157 $originalRootline = array(
158 0 => array('uid' => 2, 'title' => 'originalTitle'),
159 1 => array('uid' => 3, 'title' => 'originalTitle2'),
160 );
161
162 $newInvalidRootline = array(
163 0 => array('uid' => 1, 'title' => 'newTitle'),
164 1 => array('uid' => 2, 'title' => 'newTitle2'),
165 );
166
167 $this->templateServiceMock->_set('rootLine', $originalRootline);
168 $this->templateServiceMock->updateRootlineData($newInvalidRootline);
169 }
170
171 }