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