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