[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Controller / Action / Ajax / ExtensionCompatibilityTesterTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\Controller\Action\Ajax;
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
17 use TYPO3\CMS\Core\Utility;
18
19 /**
20 * Test case
21 */
22 class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * Tear down
26 *
27 * @return void
28 */
29 public function tearDown() {
30 if (file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt')) {
31 unlink(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt');
32 }
33 parent::tearDown();
34 }
35
36 /**
37 * @test
38 */
39 public function getExtensionsToLoadGetsExtensionsWithoutExcluded() {
40 $GLOBALS['TYPO3_LOADED_EXT'] = array(
41 'cms' => '',
42 'news' => '',
43 'info' => ''
44 );
45 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('getExtensionsToExclude'), array());
46 $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToExclude')->will($this->returnValue(array('cms', 'info')));
47 $result = $extensionCompatibilityTesterMock->_call('getExtensionsToLoad');
48 $this->assertEquals(array('news' => ''), $result);
49 }
50
51 /**
52 * @test
53 */
54 public function executeActionReturnsStringOkIfAllIsWell() {
55 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('getExtensionsToLoad', 'tryToLoadExtLocalconfAndExtTablesOfExtensions', 'deleteProtocolFile'), array());
56 $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
57 $result = $extensionCompatibilityTesterMock->_call('executeAction');
58 $this->assertEquals('OK', $result);
59 }
60
61 /**
62 * @test
63 */
64 public function executeActionCallsGetExtensionsToLoad() {
65 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('getExtensionsToLoad', 'deleteProtocolFile', 'tryToLoadExtLocalconfAndExtTablesOfExtensions'), array());
66 $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
67 $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad');
68 $extensionCompatibilityTesterMock->_call('executeAction');
69 }
70
71 /**
72 * @test
73 */
74 public function executeActionCallsLoadExtensions() {
75 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'), array());
76 $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
77 $extensionCompatibilityTesterMock->expects($this->once())->method('tryToLoadExtLocalconfAndExtTablesOfExtensions');
78 $extensionCompatibilityTesterMock->_call('executeAction');
79 }
80
81 /**
82 * @test
83 */
84 public function executeActionCallsDeleteProtocolFileIfForceCheckIsSet() {
85 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'), array());
86 $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
87 $_GET['install']['extensionCompatibilityTester']['forceCheck'] = 1;
88 $extensionCompatibilityTesterMock->expects($this->once())->method('deleteProtocolFile');
89 $extensionCompatibilityTesterMock->_call('executeAction');
90 unset($_GET['install']['extensionCompatibilityTester']['forceCheck']);
91 }
92
93 /**
94 * @test
95 */
96 public function deleteProtocolFileDeletesFile() {
97 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
98 Utility\GeneralUtility::writeFile(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt', 'foobar');
99 $extensionCompatibilityTesterMock->_call('deleteProtocolFile');
100 $this->assertFalse(file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt'));
101 }
102
103
104
105 /**
106 * @test
107 */
108 public function tryToLoadExtLocalconfAndExtTablesOfExtensionsCallsLoadExtTablesForExtension() {
109 $extension = array(
110 'demo1' => array(
111 'type' => 'L',
112 'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
113 )
114 );
115 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
116 $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtTablesForExtension');
117 $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
118 }
119
120 /**
121 * @test
122 */
123 public function tryToLoadExtLocalconfAndExtTablesOfExtensionsCallsLoadExtLocalconfForExtension() {
124 $extension = array(
125 'demo1' => array(
126 'type' => 'L',
127 'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
128 )
129 );
130 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
131 $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtLocalconfForExtension');
132 $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
133 }
134
135 /**
136 * @test
137 */
138 public function loadExtLocalconfForExtensionIncludesExtLocalconfPhp() {
139 $extension = array(
140 'demo1' => array(
141 'type' => 'L',
142 'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
143 )
144 );
145 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
146 $extensionCompatibilityTesterMock->_call('loadExtLocalconfForExtension', 'demo1', $extension['demo1']);
147 $this->assertArrayHasKey('demo1_executed', $GLOBALS);
148 $this->assertEquals('foobaz', $GLOBALS['demo1_executed']);
149 unset($GLOBALS['demo1_executed']);
150 }
151
152 /**
153 * @test
154 */
155 public function tryToLoadExtLocalconfAndExtTablesOfExtensionsCallsWriteCurrentExtensionToFile() {
156 $extension = array(
157 'demo1' => array(
158 'type' => 'L',
159 'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
160 )
161 );
162 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
163 $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('writeCurrentExtensionToFile')->with('demo1');
164 $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
165 }
166
167 /**
168 * @test
169 */
170 public function writeCurrentExtensionToFileWritesExtensionKeyToFile() {
171 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
172 $extensionCompatibilityTesterMock->_call('writeCurrentExtensionToFile', 'demo1');
173 $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
174 $this->assertEquals('demo1', $fileContent);
175 }
176
177 /**
178 * @test
179 */
180 public function getExtensionsToExcludeReturnsArray() {
181 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
182 $returnValue = $extensionCompatibilityTesterMock->_call('getExtensionsToExclude');
183 $this->assertInternalType('array', $returnValue);
184 }
185
186 /**
187 * removeCurrentExtensionFromFileRemovesGivenExtensionDataProvider
188 *
189 * @return array
190 */
191 public function removeCurrentExtensionFromFileRemovesGivenExtensionDataProvider() {
192 return array(
193 'first' => array(
194 'demo1',
195 'demo1, demo2, demo3',
196 'demo2, demo3'
197 ),
198 'second' => array(
199 'demo2',
200 'demo1, demo2, demo3',
201 'demo1, demo3'
202 ),
203 'third' => array(
204 'demo3',
205 'demo1, demo2, demo3',
206 'demo1, demo2'
207 )
208 );
209 }
210
211 /**
212 * @test
213 * @dataProvider removeCurrentExtensionFromFileRemovesGivenExtensionDataProvider
214 */
215 public function removeCurrentExtensionFromFileRemovesGivenExtension($extensionToRemove, $extensions, $expectedExtensions) {
216 $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
217 Utility\GeneralUtility::writeFile($extensionCompatibilityTesterMock->_get('protocolFile'), $extensions);
218 $extensionCompatibilityTesterMock->_call('removeCurrentExtensionFromFile', $extensionToRemove);
219
220 $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
221 $this->assertEquals($expectedExtensions, $fileContent);
222 }
223 }