TYPO3 CMS  TYPO3_6-2
ExtensionManagementServiceTest.php
Go to the documentation of this file.
1 <?php
3 
22 
28  $managementMock = $this->getAccessibleMock(
29  'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
30  array('downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension')
31  );
32  $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue(array()));
33  $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
34  $extensionModelMock->_set('extensionKey', 'foobar');
35  $extensionModelMock->_set('version', '1.0.0');
36  $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkDependencies'));
37  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
38  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
39  $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('getExtensionQueue', 'addExtensionToInstallQueue'));
40  $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue(array(
41  'download' => array(
42  'foo' => $extensionModelMock
43  )
44  )));
45  $managementMock->_set('downloadQueue', $downloadQueueMock);
46  $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
47  $managementMock->_call('installExtension', $extensionModelMock);
48  }
49 
55  $managementMock = $this->getAccessibleMock(
56  'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
57  array('downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension')
58  );
59  $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue(array()));
60  $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
61  $extensionModelMock->_set('extensionKey', 'foobar');
62  $extensionModelMock->_set('version', '1.0.0');
63  $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkDependencies'));
64  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
65  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
66  $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('getExtensionQueue', 'addExtensionToInstallQueue'));
67  $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue(array(
68  'update' => array(
69  'foo' => $extensionModelMock
70  )
71  )));
72  $managementMock->_set('downloadQueue', $downloadQueueMock);
73  $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
74  $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
75  $managementMock->_call('installExtension', $extensionModelMock);
76  }
77 
83  $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
84  'dummy'
85  ));
86 
87  $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
88  $extensionModelMock->_set('extensionKey', 'foobar');
89  $extensionModelMock->_set('version', '1.0.0');
90 
91  $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
92  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
93  $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
94  $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
95  $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
96  $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
97  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
98  $managementMock->_set('installUtility', $installUtilityMock);
99  $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
100 
101  $downloadQueue = array(
102  $extensionModelMock
103  );
104  $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
105  $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
106  $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
107  $managementMock->_set('downloadUtility', $downloadUtilityMock);
108  $managementMock->_set('downloadQueue', $downloadQueueMock);
109  $managementMock->_call('downloadDependencies', $downloadQueue);
110  }
111 
116  public function downloadDependenciesCallsRemoveExtensionFromQueue() {
117  $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
118  'dummy'
119  ));
120 
122  $extensionModelMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
123  $extensionModelMock->setExtensionKey('foobar');
124  $extensionModelMock->setVersion('1.0.0');
125  $downloadQueue = array(
126  $extensionModelMock
127  );
128 
129  $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
130  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
131  $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
132  $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
133  $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
134  $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
135  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
136  $managementMock->_set('installUtility', $installUtilityMock);
137  $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
138 
139  $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
140  $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
141  $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
142  $managementMock->_set('downloadUtility', $downloadUtilityMock);
143  $managementMock->_set('downloadQueue', $downloadQueueMock);
144  $managementMock->_call('downloadDependencies', $downloadQueue);
145  }
146 
152  $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
153  'dummy'
154  ));
155 
156  $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
157  $extensionModelMock->_set('extensionKey', 'foobar');
158  $extensionModelMock->_set('version', '1.0.0');
159  $downloadQueue = array(
160  $extensionModelMock
161  );
162 
163  $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
164  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
165  $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
166  $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
167  $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
168  $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
169  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
170  $managementMock->_set('installUtility', $installUtilityMock);
171  $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
172 
173  $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
174  $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
175  $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
176  $managementMock->_set('downloadUtility', $downloadUtilityMock);
177  $managementMock->_set('downloadQueue', $downloadQueueMock);
178  $resolvedDependencies = $managementMock->_call('downloadDependencies', $downloadQueue);
179  $this->assertEquals(array('downloaded' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
180  }
181 
187  $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
188  'dummy'
189  ));
190  $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
191  $extensionModelMock->_set('extensionKey', 'foobar');
192  $extensionModelMock->_set('version', '1.0.0');
193  $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
194  $downloadQueue = array(
195  $extensionModelMock
196  );
197  $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'), array(), '', FALSE);
198  $installUtility->expects($this->once())->method('uninstall')->with('foobar');
199  $managementMock->_set('installUtility', $installUtility);
200  $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
201  }
202 
208  $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
209  'dummy'
210  ));
211  $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
212  $extensionModelMock->_set('extensionKey', 'foobar');
213  $extensionModelMock->_set('version', '1.0.0');
214  $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
215  $downloadQueue = array(
216  $extensionModelMock
217  );
218  $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'), array(), '', FALSE);
219  $managementMock->_set('installUtility', $installUtility);
220  $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
221  $this->assertEquals(array('updated' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
222  }
223 
228  public function installDependenciesCallsInstall() {
229  $managementMock = $this->getAccessibleMock(
230  'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
231  array('emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal')
232  );
234  $extensionMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
235  $extensionMock->setExtensionKey('foobar');
236  $installQueue = array(
237  'foobar' => $extensionMock,
238  );
239  $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install','emitWillInstallExtensionsSignal'), array(), '', FALSE);
240  $installUtility->expects($this->once())->method('install')->with('foobar');
241  $managementMock->_set('installUtility', $installUtility);
242  $managementMock->_call('installDependencies', $installQueue);
243  }
244 
249  public function installDependenciesReturnsResolvedDependencies() {
250  $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
251  'emitWillInstallExtensionsSignal',
252  'emitHasInstalledExtensionSignal'
253  ));
255  $extensionMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
256  $extensionMock->setExtensionKey('foobar');
257  $installQueue = array(
258  'foobar' => $extensionMock,
259  );
260  $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install','emitWillInstallExtensionsSignal'), array(), '', FALSE);
261  $installUtility->expects($this->once())->method('install')->with('foobar');
262  $managementMock->_set('installUtility', $installUtility);
263  $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
264  $this->assertEquals(array(
265  'installed' => array(
266  'foobar' => 'foobar'
267  )
268  ), $resolvedDependencies);
269  }
270 
271 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)