TYPO3 CMS  TYPO3_6-2
ExtensionCompatibilityTesterTest.php
Go to the documentation of this file.
1 <?php
3 
18 
23 
27  protected $backupPackageManager = NULL;
28 
34  public function setUp() {
35  // Package manager is mocked in some tests. Backup the original one here to re-inject it to
36  // ExtensionManagementUtility in tearDown() again. makeInstance() is allowed to be used here
37  // since the PackageManager is registered as singleton by bootstrap.
38  $this->backupPackageManager = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
39  }
40 
46  public function tearDown() {
47  Utility\ExtensionManagementUtility::setPackageManager($this->backupPackageManager);
48  if (file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt')) {
49  unlink(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt');
50  }
51  parent::tearDown();
52  }
53 
58  $GLOBALS['TYPO3_LOADED_EXT'] = array(
59  'cms' => '',
60  'news' => '',
61  'info' => ''
62  );
63  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('getExtensionsToExclude'), array());
64  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToExclude')->will($this->returnValue(array('cms', 'info')));
65  $result = $extensionCompatibilityTesterMock->_call('getExtensionsToLoad');
66  $this->assertEquals(array('news' => ''), $result);
67  }
68 
73  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('getExtensionsToLoad', 'tryToLoadExtLocalconfAndExtTablesOfExtensions', 'deleteProtocolFile'), array());
74  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
75  $result = $extensionCompatibilityTesterMock->_call('executeAction');
76  $this->assertEquals('OK', $result);
77  }
78 
83  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('getExtensionsToLoad', 'deleteProtocolFile', 'tryToLoadExtLocalconfAndExtTablesOfExtensions'), array());
84  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
85  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad');
86  $extensionCompatibilityTesterMock->_call('executeAction');
87  }
88 
93  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'), array());
94  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
95  $extensionCompatibilityTesterMock->expects($this->once())->method('tryToLoadExtLocalconfAndExtTablesOfExtensions');
96  $extensionCompatibilityTesterMock->_call('executeAction');
97  }
98 
103  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('tryToLoadExtLocalconfAndExtTablesOfExtensions', 'getExtensionsToLoad', 'deleteProtocolFile'), array());
104  $extensionCompatibilityTesterMock->expects($this->once())->method('getExtensionsToLoad')->will($this->returnValue(array()));
105  $_GET['install']['extensionCompatibilityTester']['forceCheck'] = 1;
106  $extensionCompatibilityTesterMock->expects($this->once())->method('deleteProtocolFile');
107  $extensionCompatibilityTesterMock->_call('executeAction');
108  unset($_GET['install']['extensionCompatibilityTester']['forceCheck']);
109  }
110 
114  public function deleteProtocolFileDeletesFile() {
115  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
116  Utility\GeneralUtility::writeFile(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt', 'foobar');
117  $extensionCompatibilityTesterMock->_call('deleteProtocolFile');
118  $this->assertFalse(file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt'));
119  }
120 
121 
122 
127  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
128  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
129  // not trigger unwanted side effects.
130  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array(), array(), '', FALSE);
131  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
132  Utility\ExtensionManagementUtility::setPackageManager($packageManager);
133 
134  $extension = array(
135  'demo1' => array(
136  'type' => 'L',
137  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
138  )
139  );
140  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
141  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('loadExtTablesForExtension');
142  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
143  }
144 
149  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
150  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
151  // not trigger unwanted side effects.
152  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array(), array(), '', FALSE);
153  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
154  Utility\ExtensionManagementUtility::setPackageManager($packageManager);
155 
156  $extension = array(
157  'demo1' => array(
158  'type' => 'L',
159  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.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('loadExtLocalconfForExtension');
164  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
165  }
166 
171  $extension = array(
172  'demo1' => array(
173  'type' => 'L',
174  'ext_localconf.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_localconf.php'
175  )
176  );
177  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
178  $extensionCompatibilityTesterMock->_call('loadExtLocalconfForExtension', 'demo1', $extension['demo1']);
179  $this->assertArrayHasKey('demo1_executed', $GLOBALS);
180  $this->assertEquals('foobaz', $GLOBALS['demo1_executed']);
181  unset($GLOBALS['demo1_executed']);
182  }
183 
188  // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
189  // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
190  // not trigger unwanted side effects.
191  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array(), array(), '', FALSE);
192  $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
193  Utility\ExtensionManagementUtility::setPackageManager($packageManager);
194 
195  $extension = array(
196  'demo1' => array(
197  'type' => 'L',
198  'ext_tables.php' => PATH_typo3 . 'sysext/install/Tests/Unit/Controller/Action/Ajax/Fixtures/demo1/ext_tables.php'
199  )
200  );
201  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('loadExtLocalconfForExtension', 'writeCurrentExtensionToFile', 'loadExtTablesForExtension', 'removeCurrentExtensionFromFile'), array());
202  $extensionCompatibilityTesterMock->expects($this->atLeastOnce())->method('writeCurrentExtensionToFile')->with('demo1');
203  $extensionCompatibilityTesterMock->_call('tryToLoadExtLocalconfAndExtTablesOfExtensions', $extension);
204  }
205 
210  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
211  $extensionCompatibilityTesterMock->_call('writeCurrentExtensionToFile', 'demo1');
212  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
213  $this->assertEquals('demo1', $fileContent);
214  }
215 
220  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
221  $returnValue = $extensionCompatibilityTesterMock->_call('getExtensionsToExclude');
222  $this->assertInternalType('array', $returnValue);
223  }
224 
231  return array(
232  'first' => array(
233  'demo1',
234  'demo1, demo2, demo3',
235  'demo2, demo3'
236  ),
237  'second' => array(
238  'demo2',
239  'demo1, demo2, demo3',
240  'demo1, demo3'
241  ),
242  'third' => array(
243  'demo3',
244  'demo1, demo2, demo3',
245  'demo1, demo2'
246  )
247  );
248  }
249 
254  public function removeCurrentExtensionFromFileRemovesGivenExtension($extensionToRemove, $extensions, $expectedExtensions) {
255  $extensionCompatibilityTesterMock = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\ExtensionCompatibilityTester', array('dummy'), array());
256  Utility\GeneralUtility::writeFile($extensionCompatibilityTesterMock->_get('protocolFile'), $extensions);
257  $extensionCompatibilityTesterMock->_call('removeCurrentExtensionFromFile', $extensionToRemove);
258 
259  $fileContent = file_get_contents($extensionCompatibilityTesterMock->_get('protocolFile'));
260  $this->assertEquals($expectedExtensions, $fileContent);
261  }
262 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]