TYPO3 CMS  TYPO3_6-2
TemplateServiceTest.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
31  protected $backupGlobals = TRUE;
32 
36  protected $templateService;
37 
42 
48  protected function setUp() {
49  $GLOBALS['TYPO3_LOADED_EXT'] = array();
50  $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
51  $this->templateService->tt_track = FALSE;
52  $this->templateServiceMock = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
53  $this->templateServiceMock->tt_track = FALSE;
54  }
55 
60  $row = array('foo');
61  $GLOBALS['TSFE'] = new \stdClass();
62  $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
63  $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
64  $GLOBALS['TSFE']->sys_page = $sysPageMock;
65  $this->templateService->versionOL($row);
66  }
67 
72  $identifier = $this->getUniqueId('test');
73  $GLOBALS['TYPO3_LOADED_EXT'] = array(
74  $identifier => array(
75  'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
76  'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
77  ),
78  ),
79  );
80 
81  $this->templateService->runThroughTemplates(array(), 0);
82  $this->assertFalse(
83  in_array('test.Core.TypoScript = 1', $this->templateService->config)
84  );
85  }
86 
91  $identifier = $this->getUniqueId('test');
92  $GLOBALS['TYPO3_LOADED_EXT'] = array(
93  $identifier => array(
94  'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
95  'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
96  ),
97  'ext_typoscript_constants.txt' => ''
98  ),
99  );
100 
101  $mockPackage = $this->getMock('TYPO3\\CMS\\Core\\Package\\Package', array('getPackagePath'), array(), '', FALSE);
102  $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
103 
104  $mockPackageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive' , 'getPackage'));
105  $mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(TRUE));
106  $mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
108 
109  $this->templateService->setProcessExtensionStatics(TRUE);
110  $this->templateService->runThroughTemplates(array(), 0);
111 
112  $this->assertTrue(
113  in_array('test.Core.TypoScript = 1', $this->templateService->config)
114  );
115 
116  ExtensionManagementUtility::setPackageManager(GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager'));
117  }
118 
123  $originalRootline = array(
124  0 => array('uid' => 2, 'title' => 'originalTitle'),
125  1 => array('uid' => 3, 'title' => 'originalTitle2'),
126  );
127 
128  $updatedRootline = array(
129  0 => array('uid' => 1, 'title' => 'newTitle'),
130  1 => array('uid' => 2, 'title' => 'newTitle2'),
131  2 => array('uid' => 3, 'title' => 'newTitle3'),
132  );
133 
134  $expectedRootline = array(
135  0 => array('uid' => 2, 'title' => 'newTitle2'),
136  1 => array('uid' => 3, 'title' => 'newTitle3'),
137  );
138 
139  $this->templateServiceMock->_set('rootLine', $originalRootline);
140  $this->templateServiceMock->updateRootlineData($updatedRootline);
141  $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
142  }
143 
149  $originalRootline = array(
150  0 => array('uid' => 2, 'title' => 'originalTitle'),
151  1 => array('uid' => 3, 'title' => 'originalTitle2'),
152  );
153 
154  $newInvalidRootline = array(
155  0 => array('uid' => 1, 'title' => 'newTitle'),
156  1 => array('uid' => 2, 'title' => 'newTitle2'),
157  );
158 
159  $this->templateServiceMock->_set('rootLine', $originalRootline);
160  $this->templateServiceMock->updateRootlineData($newInvalidRootline);
161  }
162 
166  public function getFileNameReturnsUrlCorrectly() {
167  $this->assertSame('http://example.com', $this->templateService->getFileName('http://example.com'));
168  $this->assertSame('https://example.com', $this->templateService->getFileName('https://example.com'));
169  }
170 
175  $this->assertSame('typo3/index.php', $this->templateService->getFileName('typo3/index.php'));
176  }
177 
182  $this->assertNull($this->templateService->getFileName(__DIR__));
183  }
184 
189  $this->assertNull($this->templateService->getFileName(' '));
190  $this->assertNull($this->templateService->getFileName('something/../else'));
191  }
192 
193 }
static setPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]