TYPO3  7.6
ExtensionCompatibilityTesterTest.php
Go to the documentation of this file.
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 
19 
23 class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
24 {
28  protected $backupPackageManager = null;
29 
35  protected function setUp()
36  {
37  // Package manager is mocked in some tests. Backup the original one here to re-inject it to
38  // ExtensionManagementUtility in tearDown() again. makeInstance() is allowed to be used here
39  // since the PackageManager is registered as singleton by bootstrap.
40  $this->backupPackageManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
41  }
42 
48  protected function tearDown()
49  {
50  ExtensionManagementUtility::setPackageManager($this->backupPackageManager);
51  if (file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt')) {
52  unlink(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt');
53  }
54  parent::tearDown();
55  }
56 
61  {
62  $GLOBALS['TYPO3_LOADED_EXT'] = array(
63  'news' => '',
64  'info' => ''
65  );
66  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('getExtensionsToExclude'), array());
67  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToExclude')->will($this->returnValue(array('info')));
68  $result = $extensionCompatibilityTesterMock->_call('getExtensionsToLoad');
69  $this->assertEquals(array('news' => ''), $result);
70  }
71 
76  {
77  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('getExtensionsToLoad', 'tryToLoadExtLocalconfAndExtTablesOfExtensions', 'deleteProtocolFile'), array());
78  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
79  $result = $extensionCompatibilityTesterMock->_call('executeAction');
80  $this->assertEquals('OK', $result);
81  }
82 
87  {
88  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('getExtensionsToLoad', 'deleteProtocolFile', 'tryToLoadExtLocalconfAndExtTablesOfExtensions'), array());
89  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
90  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad');
91  $extensionCompatibilityTesterMock->_call('executeAction');
92  }
93 
98  {
99  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'), array());
100  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
101  $extensionCompatibilityTesterMock->expects($this->once())->method('tryToLoadExtLocalconfAndExtTablesOfExtensions');
102  $extensionCompatibilityTesterMock->_call('executeAction');
103  }
104 
109  {
110  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'), array());
111  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
112  $_GET['install']['extensionCompatibilityTester']['forceCheck'] = 1;
113  $extensionCompatibilityTesterMock->expects($this->once())->method('deleteProtocolFile');
114  $extensionCompatibilityTesterMock->_call('executeAction');
115  unset($_GET['install']['extensionCompatibilityTester']['forceCheck']);
116  }
117 
122  {
123  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('dummy'), array());
124  GeneralUtility::writeFile(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt', 'foobar');
125  $extensionCompatibilityTesterMock->_call('deleteProtocolFile');
126  $this->assertFalse(file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt'));
127  }
128 
129 
130 
135  {
136  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
137  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
138  // not trigger unwanted side effects.
139  $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, array(), array(), '', false);
140  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
142 
143  $extension = array(
144  'demo1' => array(
145  'type' => 'L',
146  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
147  )
148  );
149  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
150  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtTablesForExtension');
151  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
152  }
153 
158  {
159  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
160  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
161  // not trigger unwanted side effects.
162  $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, array(), array(), '', false);
163  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
165 
166  $extension = array(
167  'demo1' => array(
168  'type' => 'L',
169  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
170  )
171  );
172  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
173  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtLocalconfForExtension');
174  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
175  }
176 
181  {
182  $extension = array(
183  'demo1' => array(
184  'type' => 'L',
185  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
186  )
187  );
188  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('dummy'), array());
189  $extensionCompatibilityTesterMock->_call('loadExtLocalconfForExtension', 'demo1', $extension['demo1']);
190  $this->assertArrayHasKey('demo1_executed', $GLOBALS);
191  $this->assertEquals('foobaz', $GLOBALS['demo1_executed']);
192  unset($GLOBALS['demo1_executed']);
193  }
194 
199  {
200  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
201  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
202  // not trigger unwanted side effects.
203  $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, array(), array(), '', false);
204  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
206 
207  $extension = array(
208  'demo1' => array(
209  'type' => 'L',
210  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
211  )
212  );
213  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
214  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('writeCurrentExtensionToFile')->with('demo1');
215  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
216  }
217 
222  {
223  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('dummy'), array());
224  $extensionCompatibilityTesterMock->_call('writeCurrentExtensionToFile', 'demo1');
225  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
226  $this->assertEquals('demo1', $fileContent);
227  }
228 
233  {
234  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('dummy'), array());
235  $returnValue = $extensionCompatibilityTesterMock->_call('getExtensionsToExclude');
236  $this->assertInternalType('array', $returnValue);
237  }
238 
245  {
246  return array(
247  'first' => array(
248  'demo1',
249  'demo1, demo2, demo3',
250  'demo2, demo3'
251  ),
252  'second' => array(
253  'demo2',
254  'demo1, demo2, demo3',
255  'demo1, demo3'
256  ),
257  'third' => array(
258  'demo3',
259  'demo1, demo2, demo3',
260  'demo1, demo2'
261  )
262  );
263  }
264 
269  public function removeCurrentExtensionFromFileRemovesGivenExtension($extensionToRemove, $extensions, $expectedExtensions)
270  {
271  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('dummy'), array());
272  GeneralUtility::writeFile($extensionCompatibilityTesterMock->_get('protocolFile'), $extensions);
273  $extensionCompatibilityTesterMock->_call('removeCurrentExtensionFromFile', $extensionToRemove);
274 
275  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
276  $this->assertEquals($expectedExtensions, $fileContent);
277  }
278 }