TYPO3 CMS  TYPO3_6-2
ExtensionStatusTest.php
Go to the documentation of this file.
1 <?php
3 
18 
23 
27  protected $mockObjectManager;
28 
33 
38 
42  public function setUp() {
43  $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
45  $this->mockRepositoryRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository', array(), array($this->mockObjectManager));
46  $this->mockLanguageService = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
47  }
48 
53  $reportMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array(), array(), '', FALSE);
54  $this->assertInstanceOf('TYPO3\\CMS\\Reports\\StatusProviderInterface', $reportMock);
55  }
56 
60  public function getStatusReturnsArray() {
61  $report = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', FALSE);
62  $this->assertInternalType('array', $report->getStatus());
63  }
64 
69  $report = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', FALSE);
70  $this->assertSame(5, count($report->getStatus()));
71  }
72 
76  public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus() {
77  $statusObject = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array('title', 'value'));
79  $report = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', FALSE);
80  $report->expects($this->any())->method('getMainRepositoryStatus')->will($this->returnValue($statusObject));
81  $resultStatuses = $report->getStatus();
82  foreach($resultStatuses as $status) {
83  if ($status) {
84  $this->assertInstanceOf('TYPO3\\CMS\\Reports\\Status', $status);
85  }
86  }
87  }
88 
92  public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult() {
94  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
95  $mockTerObject
96  ->expects($this->any())
97  ->method('getVersion')
98  ->will($this->returnValue('1.0.6'));
99  $mockTerObject
100  ->expects($this->atLeastOnce())
101  ->method('getReviewState')
102  ->will($this->returnValue(0));
103  $mockExtensionList = array(
104  'enetcache' => array(
105  'installed' => TRUE,
106  'terObject' => $mockTerObject
107  ),
108  );
110  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
111  $mockListUtility
112  ->expects($this->once())
113  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
114  ->will($this->returnValue($mockExtensionList));
115 
117  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getMainRepositoryStatus'), array(), '', FALSE);
118  $mockReport->_set('objectManager', $this->mockObjectManager);
119  $mockReport->_set('listUtility', $mockListUtility);
120  $mockReport->_set('languageService', $this->mockLanguageService);
121  $mockReport
122  ->expects($this->once())
123  ->method('getMainRepositoryStatus')
124  ->will($this->returnValue('foo'));
125 
126  $result = $mockReport->getStatus();
127  $this->assertSame('foo', $result['mainRepositoryStatus']);
128  }
129 
133  public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound() {
134  $this->mockRepositoryRepository
135  ->expects($this->once())
136  ->method('findOneTypo3OrgRepository')
137  ->will($this->returnValue(NULL));
138 
140  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
141  $mockReport->_set('objectManager', $this->mockObjectManager);
142  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
143  $this->mockObjectManager
144  ->expects($this->once())
145  ->method('get')
146  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
147  ->will($this->returnValue($statusMock));
148  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
149  $mockReport->_set('languageService', $this->mockLanguageService);
150 
151  $result = $mockReport->_call('getMainRepositoryStatus');
152  $this->assertSame($statusMock, $result);
153  }
154 
158  public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo() {
160  $mockRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository');
161  $mockRepository
162  ->expects($this->once())
163  ->method('getLastUpdate')
164  ->will($this->returnValue(new \DateTime('-8 days')));
165 
166  $this->mockRepositoryRepository
167  ->expects($this->once())
168  ->method('findOneTypo3OrgRepository')
169  ->will($this->returnValue($mockRepository));
170 
172  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
173  $mockReport->_set('objectManager', $this->mockObjectManager);
174  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
175  $this->mockObjectManager
176  ->expects($this->once())
177  ->method('get')
178  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::NOTICE)
179  ->will($this->returnValue($statusMock));
180  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
181  $mockReport->_set('languageService', $this->mockLanguageService);
182 
184  $result = $mockReport->_call('getMainRepositoryStatus');
185  $this->assertSame($statusMock, $result);
186  }
187 
191  public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo() {
193  $mockRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository');
194  $mockRepository
195  ->expects($this->once())
196  ->method('getLastUpdate')
197  ->will($this->returnValue(new \DateTime('-6 days')));
198 
199  $this->mockRepositoryRepository
200  ->expects($this->once())
201  ->method('findOneTypo3OrgRepository')
202  ->will($this->returnValue($mockRepository));
203 
205  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
206  $mockReport->_set('objectManager', $this->mockObjectManager);
207  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
208  $this->mockObjectManager
209  ->expects($this->once())
210  ->method('get')
211  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
212  ->will($this->returnValue($statusMock));
213  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
214  $mockReport->_set('languageService', $this->mockLanguageService);
215 
217  $result = $mockReport->_call('getMainRepositoryStatus');
218  $this->assertSame($statusMock, $result);
219  }
220 
224  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded() {
226  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
227  $mockTerObject
228  ->expects($this->any())
229  ->method('getVersion')
230  ->will($this->returnValue('1.0.6'));
231  $mockTerObject
232  ->expects($this->atLeastOnce())
233  ->method('getReviewState')
234  ->will($this->returnValue(0));
235  $mockExtensionList = array(
236  'enetcache' => array(
237  'installed' => TRUE,
238  'terObject' => $mockTerObject
239  ),
240  );
242  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
243  $mockListUtility
244  ->expects($this->once())
245  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
246  ->will($this->returnValue($mockExtensionList));
247 
249  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
250  $mockReport->_set('objectManager', $this->mockObjectManager);
251  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
252  $this->mockObjectManager
253  ->expects($this->at(0))
254  ->method('get')
255  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
256  ->will($this->returnValue($statusMock));
257  $mockReport->_set('listUtility', $mockListUtility);
258  $mockReport->_set('languageService', $this->mockLanguageService);
259 
260  $result = $mockReport->_call('getSecurityStatusOfExtensions');
262  $loadedResult = $result->loaded;
263  $this->assertSame($statusMock, $loadedResult);
264  }
265 
269  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded() {
271  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
272  $mockTerObject
273  ->expects($this->any())
274  ->method('getVersion')
275  ->will($this->returnValue('1.0.6'));
276  $mockTerObject
277  ->expects($this->atLeastOnce())
278  ->method('getReviewState')
279  ->will($this->returnValue(-1));
280  $mockExtensionList = array(
281  'enetcache' => array(
282  'installed' => TRUE,
283  'terObject' => $mockTerObject
284  ),
285  );
287  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
288  $mockListUtility
289  ->expects($this->once())
290  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
291  ->will($this->returnValue($mockExtensionList));
292 
294  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
295  $mockReport->_set('objectManager', $this->mockObjectManager);
296  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
297  $this->mockObjectManager
298  ->expects($this->at(0))
299  ->method('get')
300  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
301  ->will($this->returnValue($statusMock));
302  $mockReport->_set('listUtility', $mockListUtility);
303  $mockReport->_set('languageService', $this->mockLanguageService);
304 
305  $result = $mockReport->_call('getSecurityStatusOfExtensions');
307  $loadedResult = $result->loaded;
308  $this->assertSame($statusMock, $loadedResult);
309  }
310 
314  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists() {
316  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
317  $mockTerObject
318  ->expects($this->any())
319  ->method('getVersion')
320  ->will($this->returnValue('1.0.6'));
321  $mockTerObject
322  ->expects($this->atLeastOnce())
323  ->method('getReviewState')
324  ->will($this->returnValue(0));
325  $mockExtensionList = array(
326  'enetcache' => array(
327  'terObject' => $mockTerObject
328  ),
329  );
331  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
332  $mockListUtility
333  ->expects($this->once())
334  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
335  ->will($this->returnValue($mockExtensionList));
336 
338  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
339  $mockReport->_set('objectManager', $this->mockObjectManager);
340  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
341  $this->mockObjectManager
342  ->expects($this->at(1))
343  ->method('get')
344  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
345  ->will($this->returnValue($statusMock));
346  $mockReport->_set('listUtility', $mockListUtility);
347  $mockReport->_set('languageService', $this->mockLanguageService);
348 
349  $result = $mockReport->_call('getSecurityStatusOfExtensions');
351  $loadedResult = $result->existing;
352  $this->assertSame($statusMock, $loadedResult);
353  }
354 
358  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists() {
360  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
361  $mockTerObject
362  ->expects($this->any())
363  ->method('getVersion')
364  ->will($this->returnValue('1.0.6'));
365  $mockTerObject
366  ->expects($this->atLeastOnce())
367  ->method('getReviewState')
368  ->will($this->returnValue(-1));
369  $mockExtensionList = array(
370  'enetcache' => array(
371  'terObject' => $mockTerObject
372  ),
373  );
375  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
376  $mockListUtility
377  ->expects($this->once())
378  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
379  ->will($this->returnValue($mockExtensionList));
380 
382  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
383  $mockReport->_set('objectManager', $this->mockObjectManager);
384  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
385  $this->mockObjectManager
386  ->expects($this->at(1))
387  ->method('get')
388  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
389  ->will($this->returnValue($statusMock));
390  $mockReport->_set('listUtility', $mockListUtility);
391  $mockReport->_set('languageService', $this->mockLanguageService);
392 
393  $result = $mockReport->_call('getSecurityStatusOfExtensions');
395  $loadedResult = $result->existing;
396  $this->assertSame($statusMock, $loadedResult);
397  }
398 
402  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded() {
404  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
405  $mockTerObject
406  ->expects($this->any())
407  ->method('getVersion')
408  ->will($this->returnValue('1.0.6'));
409  $mockTerObject
410  ->expects($this->atLeastOnce())
411  ->method('getReviewState')
412  ->will($this->returnValue(0));
413  $mockExtensionList = array(
414  'enetcache' => array(
415  'installed' => TRUE,
416  'terObject' => $mockTerObject
417  ),
418  );
420  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
421  $mockListUtility
422  ->expects($this->once())
423  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
424  ->will($this->returnValue($mockExtensionList));
425 
427  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
428  $mockReport->_set('objectManager', $this->mockObjectManager);
429  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
430  $this->mockObjectManager
431  ->expects($this->at(2))
432  ->method('get')
433  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
434  ->will($this->returnValue($statusMock));
435  $mockReport->_set('listUtility', $mockListUtility);
436  $mockReport->_set('languageService', $this->mockLanguageService);
437 
438  $result = $mockReport->_call('getSecurityStatusOfExtensions');
440  $loadedResult = $result->loadedoutdated;
441  $this->assertSame($statusMock, $loadedResult);
442  }
443 
447  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded() {
449  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
450  $mockTerObject
451  ->expects($this->any())
452  ->method('getVersion')
453  ->will($this->returnValue('1.0.6'));
454  $mockTerObject
455  ->expects($this->atLeastOnce())
456  ->method('getReviewState')
457  ->will($this->returnValue(-2));
458  $mockExtensionList = array(
459  'enetcache' => array(
460  'installed' => TRUE,
461  'terObject' => $mockTerObject
462  ),
463  );
465  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
466  $mockListUtility
467  ->expects($this->once())
468  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
469  ->will($this->returnValue($mockExtensionList));
470 
472  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
473  $mockReport->_set('objectManager', $this->mockObjectManager);
474  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
475  $this->mockObjectManager
476  ->expects($this->at(2))
477  ->method('get')
478  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
479  ->will($this->returnValue($statusMock));
480  $mockReport->_set('listUtility', $mockListUtility);
481  $mockReport->_set('languageService', $this->mockLanguageService);
482 
483  $result = $mockReport->_call('getSecurityStatusOfExtensions');
485  $loadedResult = $result->loadedoutdated;
486  $this->assertSame($statusMock, $loadedResult);
487  }
488 
492  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists() {
494  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
495  $mockTerObject
496  ->expects($this->any())
497  ->method('getVersion')
498  ->will($this->returnValue('1.0.6'));
499  $mockTerObject
500  ->expects($this->atLeastOnce())
501  ->method('getReviewState')
502  ->will($this->returnValue(0));
503  $mockExtensionList = array(
504  'enetcache' => array(
505  'terObject' => $mockTerObject
506  ),
507  );
509  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
510  $mockListUtility
511  ->expects($this->once())
512  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
513  ->will($this->returnValue($mockExtensionList));
514 
516  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
517  $mockReport->_set('objectManager', $this->mockObjectManager);
518  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
519  $this->mockObjectManager
520  ->expects($this->at(3))
521  ->method('get')
522  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
523  ->will($this->returnValue($statusMock));
524  $mockReport->_set('listUtility', $mockListUtility);
525  $mockReport->_set('languageService', $this->mockLanguageService);
526 
527  $result = $mockReport->_call('getSecurityStatusOfExtensions');
529  $loadedResult = $result->existingoutdated;
530  $this->assertSame($statusMock, $loadedResult);
531  }
532 
536  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists() {
538  $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
539  $mockTerObject
540  ->expects($this->any())
541  ->method('getVersion')
542  ->will($this->returnValue('1.0.6'));
543  $mockTerObject
544  ->expects($this->atLeastOnce())
545  ->method('getReviewState')
546  ->will($this->returnValue(-2));
547  $mockExtensionList = array(
548  'enetcache' => array(
549  'terObject' => $mockTerObject
550  ),
551  );
553  $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
554  $mockListUtility
555  ->expects($this->once())
556  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
557  ->will($this->returnValue($mockExtensionList));
558 
560  $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
561  $mockReport->_set('objectManager', $this->mockObjectManager);
562  $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
563  $this->mockObjectManager
564  ->expects($this->at(3))
565  ->method('get')
566  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
567  ->will($this->returnValue($statusMock));
568  $mockReport->_set('listUtility', $mockListUtility);
569  $mockReport->_set('languageService', $this->mockLanguageService);
570 
571  $result = $mockReport->_call('getSecurityStatusOfExtensions');
573  $loadedResult = $result->existingoutdated;
574  $this->assertSame($statusMock, $loadedResult);
575  }
576 }
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.