TYPO3 CMS  TYPO3_7-6
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 
19 
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'] = [
63  'news' => '',
64  'info' => ''
65  ];
66  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['getExtensionsToExclude'], []);
67  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToExclude')->will($this->returnValue(['info']));
68  $result = $extensionCompatibilityTesterMock->_call('getExtensionsToLoad');
69  $this->assertEquals(['news' => ''], $result);
70  }
71 
76  {
77  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['getExtensionsToLoad', 'tryToLoadExtLocalconfAndExtTablesOfExtensions', 'deleteProtocolFile'], []);
78  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
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, ['getExtensionsToLoad', 'deleteProtocolFile', 'tryToLoadExtLocalconfAndExtTablesOfExtensions'], []);
89  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
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, ['tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'], []);
100  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
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, ['tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'], []);
111  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue([]));
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, ['dummy'], []);
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 
133  {
134  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
135  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
136  // not trigger unwanted side effects.
137  $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, [], [], '', false);
138  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue([]));
140 
141  $extension = [
142  'demo1' => [
143  'type' => 'L',
144  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
145  ]
146  ];
147  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'], []);
148  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtTablesForExtension');
149  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
150  }
151 
156  {
157  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
158  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
159  // not trigger unwanted side effects.
160  $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, [], [], '', false);
161  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue([]));
163 
164  $extension = [
165  'demo1' => [
166  'type' => 'L',
167  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
168  ]
169  ];
170  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'], []);
171  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtLocalconfForExtension');
172  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
173  }
174 
179  {
180  $extension = [
181  'demo1' => [
182  'type' => 'L',
183  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
184  ]
185  ];
186  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
187  $extensionCompatibilityTesterMock->_call('loadExtLocalconfForExtension', 'demo1', $extension['demo1']);
188  $this->assertArrayHasKey('demo1_executed', $GLOBALS);
189  $this->assertEquals('foobaz', $GLOBALS['demo1_executed']);
190  unset($GLOBALS['demo1_executed']);
191  }
192 
197  {
198  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
199  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
200  // not trigger unwanted side effects.
201  $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, [], [], '', false);
202  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue([]));
204 
205  $extension = [
206  'demo1' => [
207  'type' => 'L',
208  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
209  ]
210  ];
211  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'], []);
212  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('writeCurrentExtensionToFile')->with('demo1');
213  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
214  }
215 
220  {
221  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
222  $extensionCompatibilityTesterMock->_call('writeCurrentExtensionToFile', 'demo1');
223  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
224  $this->assertEquals('demo1', $fileContent);
225  }
226 
231  {
232  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
233  $returnValue = $extensionCompatibilityTesterMock->_call('getExtensionsToExclude');
234  $this->assertInternalType('array', $returnValue);
235  }
236 
243  {
244  return [
245  'first' => [
246  'demo1',
247  'demo1, demo2, demo3',
248  'demo2, demo3'
249  ],
250  'second' => [
251  'demo2',
252  'demo1, demo2, demo3',
253  'demo1, demo3'
254  ],
255  'third' => [
256  'demo3',
257  'demo1, demo2, demo3',
258  'demo1, demo2'
259  ]
260  ];
261  }
262 
267  public function removeCurrentExtensionFromFileRemovesGivenExtension($extensionToRemove, $extensions, $expectedExtensions)
268  {
269  $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, ['dummy'], []);
270  GeneralUtility::writeFile($extensionCompatibilityTesterMock->_get('protocolFile'), $extensions);
271  $extensionCompatibilityTesterMock->_call('removeCurrentExtensionFromFile', $extensionToRemove);
272 
273  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
274  $this->assertEquals($expectedExtensions, $fileContent);
275  }
276 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
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)