[BUGFIX] Unit tests: Superfluous backup
[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 /**
52 * Sets up this test case.
53 *
54 * @return void
55 */
56 protected function setUp() {
57 $GLOBALS['TYPO3_LOADED_EXT'] = array();
58 $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
59 $this->templateServiceMock = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
60 }
61
62 /**
63 * Tears down this test case.
64 *
65 * @return void
66 */
67 protected function tearDown() {
68 unset($this->templateService);
69 unset($this->templateServiceMock);
70 }
71
72 /**
73 * @test
74 */
75 public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow() {
76 $row = array('foo');
77 $GLOBALS['TSFE'] = new \stdClass();
78 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
79 $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
80 $GLOBALS['TSFE']->sys_page = $sysPageMock;
81 $this->templateService->versionOL($row);
82 }
83
84 /**
85 * @test
86 */
87 public function extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested() {
88 $identifier = uniqid('test');
89 $GLOBALS['TYPO3_LOADED_EXT'] = array(
90 $identifier => array(
91 'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
92 'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
93 ),
94 ),
95 );
96
97 $this->templateService->runThroughTemplates(array(), 0);
98 $this->assertFalse(
99 in_array('test.Core.TypoScript = 1', $this->templateService->config)
100 );
101 }
102
103 /**
104 * @test
105 */
106 public function extensionStaticsAreProcessedIfExplicitlyRequested() {
107 $identifier = uniqid('test');
108 $GLOBALS['TYPO3_LOADED_EXT'] = array(
109 $identifier => array(
110 'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
111 'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
112 ),
113 ),
114 );
115
116 $this->templateService->setProcessExtensionStatics(TRUE);
117 $this->templateService->runThroughTemplates(array(), 0);
118 $this->assertTrue(
119 in_array('test.Core.TypoScript = 1', $this->templateService->config)
120 );
121 }
122
123 /**
124 * @test
125 */
126 public function updateRootlineDataOverwritesOwnArrayData() {
127 $originalRootline = array(
128 0 => array('uid' => 2, 'title' => 'originalTitle'),
129 1 => array('uid' => 3, 'title' => 'originalTitle2'),
130 );
131
132 $updatedRootline = array(
133 0 => array('uid' => 1, 'title' => 'newTitle'),
134 1 => array('uid' => 2, 'title' => 'newTitle2'),
135 2 => array('uid' => 3, 'title' => 'newTitle3'),
136 );
137
138 $expectedRootline = array(
139 0 => array('uid' => 2, 'title' => 'newTitle2'),
140 1 => array('uid' => 3, 'title' => 'newTitle3'),
141 );
142
143 $this->templateServiceMock->_set('rootLine', $originalRootline);
144 $this->templateServiceMock->updateRootlineData($updatedRootline);
145 $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
146 }
147
148 /**
149 * @test
150 * @expectedException \RuntimeException
151 */
152 public function updateRootlineDataWithInvalidNewRootlineThrowsException() {
153 $originalRootline = array(
154 0 => array('uid' => 2, 'title' => 'originalTitle'),
155 1 => array('uid' => 3, 'title' => 'originalTitle2'),
156 );
157
158 $newInvalidRootline = array(
159 0 => array('uid' => 1, 'title' => 'newTitle'),
160 1 => array('uid' => 2, 'title' => 'newTitle2'),
161 );
162
163 $this->templateServiceMock->_set('rootLine', $originalRootline);
164 $this->templateServiceMock->updateRootlineData($newInvalidRootline);
165 }
166
167 }