TYPO3 CMS  TYPO3_8-7
ExtensionCompatibilityTesterTest.php
Go to the documentation of this file.
1 <?php
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 
20 
24 class ExtensionCompatibilityTesterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
29  protected $backupPackageManager = null;
30 
34  protected function setUp()
35  {
37  }
38 
42  protected function tearDown()
43  {
45  if (file_exists(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt')) {
46  unlink(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt');
47  }
48  parent::tearDown();
49  }
50 
55  {
56  $GLOBALS['TYPO3_LOADED_EXT'] = [
57  'news' => '',
58  'info' => ''
59  ];
60  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['getExtensionsToExclude'], []);
61  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToExclude')->will($this->returnValue(['info']));
62  $result = $extensionCompatibilityTesterMock->_call('getExtensionsToLoad');
63  $this->assertEquals(['news' => ''], $result);
64  }
65 
70  {
71  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['getExtensionsToLoad', 'tryToLoadExtLocalconfAndExtTablesOfExtensions', 'deleteProtocolFile'], []);
72  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
73  $result = $extensionCompatibilityTesterMock->_call('executeAction');
74  $this->assertEquals('OK', $result);
75  }
76 
81  {
82  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['getExtensionsToLoad', 'deleteProtocolFile', 'tryToLoadExtLocalconfAndExtTablesOfExtensions'], []);
83  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
84  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad');
85  $extensionCompatibilityTesterMock->_call('executeAction');
86  }
87 
92  {
93  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'], []);
94  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
95  $extensionCompatibilityTesterMock->expects($this->once())->method('tryToLoadExtLocalconfAndExtTablesOfExtensions');
96  $extensionCompatibilityTesterMock->_call('executeAction');
97  }
98 
103  {
104  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'], []);
105  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
106  $_GET['install']['extensionCompatibilityTester']['forceCheck'] = 1;
107  $extensionCompatibilityTesterMock->expects($this->once())->method('deleteProtocolFile');
108  $extensionCompatibilityTesterMock->_call('executeAction');
109  unset($_GET['install']['extensionCompatibilityTester']['forceCheck']);
110  }
111 
116  {
117  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
118  GeneralUtility::writeFile(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt', 'foobar');
119  $extensionCompatibilityTesterMock->_call('deleteProtocolFile');
120  $this->assertFalse(file_exists(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt'));
121  }
122 
127  {
128  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
129  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
130  // not trigger unwanted side effects.
131  $packageManager = $this->createMock(\TYPO3\CMS\Core\Package\PackageManager::class);
132  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue([]));
134 
135  $extension = [
136  'demo1' => [
137  'type' => 'L',
138  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
139  ]
140  ];
141  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'], []);
142  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtTablesForExtension');
143  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
144  }
145 
150  {
151  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
152  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
153  // not trigger unwanted side effects.
154  $packageManager = $this->createMock(\TYPO3\CMS\Core\Package\PackageManager::class);
155  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue([]));
157 
158  $extension = [
159  'demo1' => [
160  'type' => 'L',
161  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
162  ]
163  ];
164  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'], []);
165  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtLocalconfForExtension');
166  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
167  }
168 
173  {
174  $extension = [
175  'demo1' => [
176  'type' => 'L',
177  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
178  ]
179  ];
180  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
181  $extensionCompatibilityTesterMock->_call('loadExtLocalconfForExtension', 'demo1', $extension['demo1']);
182  $this->assertArrayHasKey('demo1_executed', $GLOBALS);
183  $this->assertEquals('foobaz', $GLOBALS['demo1_executed']);
184  unset($GLOBALS['demo1_executed']);
185  }
186 
191  {
192  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
193  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
194  // not trigger unwanted side effects.
195  $packageManager = $this->createMock(\TYPO3\CMS\Core\Package\PackageManager::class);
196  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue([]));
198 
199  $extension = [
200  'demo1' => [
201  'type' => 'L',
202  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
203  ]
204  ];
205  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'], []);
206  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('writeCurrentExtensionToFile')->with('demo1');
207  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
208  }
209 
214  {
215  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
216  $extensionCompatibilityTesterMock->_call('writeCurrentExtensionToFile', 'demo1');
217  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
218  $this->assertEquals('demo1', $fileContent);
219  }
220 
225  {
226  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
227  $returnValue = $extensionCompatibilityTesterMock->_call('getExtensionsToExclude');
228  $this->assertInternalType('array', $returnValue);
229  }
230 
237  {
238  return [
239  'first' => [
240  'demo1',
241  'demo1, demo2, demo3',
242  'demo2, demo3'
243  ],
244  'second' => [
245  'demo2',
246  'demo1, demo2, demo3',
247  'demo1, demo3'
248  ],
249  'third' => [
250  'demo3',
251  'demo1, demo2, demo3',
252  'demo1, demo2'
253  ]
254  ];
255  }
256 
261  public function removeCurrentExtensionFromFileRemovesGivenExtension($extensionToRemove, $extensions, $expectedExtensions)
262  {
263  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
264  GeneralUtility::writeFile($extensionCompatibilityTesterMock->_get('protocolFile'), $extensions);
265  $extensionCompatibilityTesterMock->_call('removeCurrentExtensionFromFile', $extensionToRemove);
266 
267  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
268  $this->assertEquals($expectedExtensions, $fileContent);
269  }
270 }
static setPackageManager(PackageManager $packageManager)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static writeFile($file, $content, $changePermissions=false)