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