TYPO3 CMS  TYPO3_7-6
ExtensionStatusTest.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 
21 {
25  protected $mockObjectManager;
26 
31 
36 
40  protected function setUp()
41  {
42  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
44  $this->mockRepositoryRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class, [], [$this->mockObjectManager]);
45  $this->mockLanguageService = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, [], [], '', false);
46  }
47 
52  {
53  $reportMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, [], [], '', false);
54  $this->assertInstanceOf(\TYPO3\CMS\Reports\StatusProviderInterface::class, $reportMock);
55  }
56 
60  public function getStatusReturnsArray()
61  {
62  $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'], [], '', false);
63  $this->assertInternalType('array', $report->getStatus());
64  }
65 
70  {
71  $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'], [], '', false);
72  $this->assertSame(5, count($report->getStatus()));
73  }
74 
78  public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus()
79  {
80  $statusObject = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], ['title', 'value']);
82  $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'], [], '', false);
83  $report->expects($this->any())->method('getMainRepositoryStatus')->will($this->returnValue($statusObject));
84  $resultStatuses = $report->getStatus();
85  foreach ($resultStatuses as $status) {
86  if ($status) {
87  $this->assertInstanceOf(\TYPO3\CMS\Reports\Status::class, $status);
88  }
89  }
90  }
91 
95  public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult()
96  {
98  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
99  $mockTerObject
100  ->expects($this->any())
101  ->method('getVersion')
102  ->will($this->returnValue('1.0.6'));
103  $mockTerObject
104  ->expects($this->atLeastOnce())
105  ->method('getReviewState')
106  ->will($this->returnValue(0));
107  $mockExtensionList = [
108  'enetcache' => [
109  'installed' => true,
110  'terObject' => $mockTerObject
111  ],
112  ];
114  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
115  $mockListUtility
116  ->expects($this->once())
117  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
118  ->will($this->returnValue($mockExtensionList));
119 
121  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['getMainRepositoryStatus'], [], '', false);
122  $mockReport->_set('objectManager', $this->mockObjectManager);
123  $mockReport->_set('listUtility', $mockListUtility);
124  $mockReport->_set('languageService', $this->mockLanguageService);
125  $mockReport
126  ->expects($this->once())
127  ->method('getMainRepositoryStatus')
128  ->will($this->returnValue('foo'));
129 
130  $result = $mockReport->getStatus();
131  $this->assertSame('foo', $result['mainRepositoryStatus']);
132  }
133 
137  public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound()
138  {
139  $this->mockRepositoryRepository
140  ->expects($this->once())
141  ->method('findOneTypo3OrgRepository')
142  ->will($this->returnValue(null));
143 
145  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
146  $mockReport->_set('objectManager', $this->mockObjectManager);
147  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
148  $this->mockObjectManager
149  ->expects($this->once())
150  ->method('get')
151  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
152  ->will($this->returnValue($statusMock));
153  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
154  $mockReport->_set('languageService', $this->mockLanguageService);
155 
156  $result = $mockReport->_call('getMainRepositoryStatus');
157  $this->assertSame($statusMock, $result);
158  }
159 
163  public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo()
164  {
166  $mockRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class);
167  $mockRepository
168  ->expects($this->once())
169  ->method('getLastUpdate')
170  ->will($this->returnValue(new \DateTime('-8 days')));
171 
172  $this->mockRepositoryRepository
173  ->expects($this->once())
174  ->method('findOneTypo3OrgRepository')
175  ->will($this->returnValue($mockRepository));
176 
178  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
179  $mockReport->_set('objectManager', $this->mockObjectManager);
180  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
181  $this->mockObjectManager
182  ->expects($this->once())
183  ->method('get')
184  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::NOTICE)
185  ->will($this->returnValue($statusMock));
186  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
187  $mockReport->_set('languageService', $this->mockLanguageService);
188 
190  $result = $mockReport->_call('getMainRepositoryStatus');
191  $this->assertSame($statusMock, $result);
192  }
193 
197  public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo()
198  {
200  $mockRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class);
201  $mockRepository
202  ->expects($this->once())
203  ->method('getLastUpdate')
204  ->will($this->returnValue(new \DateTime('-6 days')));
205 
206  $this->mockRepositoryRepository
207  ->expects($this->once())
208  ->method('findOneTypo3OrgRepository')
209  ->will($this->returnValue($mockRepository));
210 
212  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
213  $mockReport->_set('objectManager', $this->mockObjectManager);
214  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
215  $this->mockObjectManager
216  ->expects($this->once())
217  ->method('get')
218  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
219  ->will($this->returnValue($statusMock));
220  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
221  $mockReport->_set('languageService', $this->mockLanguageService);
222 
224  $result = $mockReport->_call('getMainRepositoryStatus');
225  $this->assertSame($statusMock, $result);
226  }
227 
231  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded()
232  {
234  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
235  $mockTerObject
236  ->expects($this->any())
237  ->method('getVersion')
238  ->will($this->returnValue('1.0.6'));
239  $mockTerObject
240  ->expects($this->atLeastOnce())
241  ->method('getReviewState')
242  ->will($this->returnValue(0));
243  $mockExtensionList = [
244  'enetcache' => [
245  'installed' => true,
246  'terObject' => $mockTerObject
247  ],
248  ];
250  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
251  $mockListUtility
252  ->expects($this->once())
253  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
254  ->will($this->returnValue($mockExtensionList));
255 
257  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
258  $mockReport->_set('objectManager', $this->mockObjectManager);
259  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
260  $this->mockObjectManager
261  ->expects($this->at(0))
262  ->method('get')
263  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
264  ->will($this->returnValue($statusMock));
265  $mockReport->_set('listUtility', $mockListUtility);
266  $mockReport->_set('languageService', $this->mockLanguageService);
267 
268  $result = $mockReport->_call('getSecurityStatusOfExtensions');
270  $loadedResult = $result->loaded;
271  $this->assertSame($statusMock, $loadedResult);
272  }
273 
277  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded()
278  {
280  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
281  $mockTerObject
282  ->expects($this->any())
283  ->method('getVersion')
284  ->will($this->returnValue('1.0.6'));
285  $mockTerObject
286  ->expects($this->atLeastOnce())
287  ->method('getReviewState')
288  ->will($this->returnValue(-1));
289  $mockExtensionList = [
290  'enetcache' => [
291  'installed' => true,
292  'terObject' => $mockTerObject
293  ],
294  ];
296  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
297  $mockListUtility
298  ->expects($this->once())
299  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
300  ->will($this->returnValue($mockExtensionList));
301 
303  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
304  $mockReport->_set('objectManager', $this->mockObjectManager);
305  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
306  $this->mockObjectManager
307  ->expects($this->at(0))
308  ->method('get')
309  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
310  ->will($this->returnValue($statusMock));
311  $mockReport->_set('listUtility', $mockListUtility);
312  $mockReport->_set('languageService', $this->mockLanguageService);
313 
314  $result = $mockReport->_call('getSecurityStatusOfExtensions');
316  $loadedResult = $result->loaded;
317  $this->assertSame($statusMock, $loadedResult);
318  }
319 
323  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists()
324  {
326  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
327  $mockTerObject
328  ->expects($this->any())
329  ->method('getVersion')
330  ->will($this->returnValue('1.0.6'));
331  $mockTerObject
332  ->expects($this->atLeastOnce())
333  ->method('getReviewState')
334  ->will($this->returnValue(0));
335  $mockExtensionList = [
336  'enetcache' => [
337  'terObject' => $mockTerObject
338  ],
339  ];
341  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
342  $mockListUtility
343  ->expects($this->once())
344  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
345  ->will($this->returnValue($mockExtensionList));
346 
348  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
349  $mockReport->_set('objectManager', $this->mockObjectManager);
350  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
351  $this->mockObjectManager
352  ->expects($this->at(1))
353  ->method('get')
354  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
355  ->will($this->returnValue($statusMock));
356  $mockReport->_set('listUtility', $mockListUtility);
357  $mockReport->_set('languageService', $this->mockLanguageService);
358 
359  $result = $mockReport->_call('getSecurityStatusOfExtensions');
361  $loadedResult = $result->existing;
362  $this->assertSame($statusMock, $loadedResult);
363  }
364 
368  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists()
369  {
371  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
372  $mockTerObject
373  ->expects($this->any())
374  ->method('getVersion')
375  ->will($this->returnValue('1.0.6'));
376  $mockTerObject
377  ->expects($this->atLeastOnce())
378  ->method('getReviewState')
379  ->will($this->returnValue(-1));
380  $mockExtensionList = [
381  'enetcache' => [
382  'terObject' => $mockTerObject
383  ],
384  ];
386  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
387  $mockListUtility
388  ->expects($this->once())
389  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
390  ->will($this->returnValue($mockExtensionList));
391 
393  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
394  $mockReport->_set('objectManager', $this->mockObjectManager);
395  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
396  $this->mockObjectManager
397  ->expects($this->at(1))
398  ->method('get')
399  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
400  ->will($this->returnValue($statusMock));
401  $mockReport->_set('listUtility', $mockListUtility);
402  $mockReport->_set('languageService', $this->mockLanguageService);
403 
404  $result = $mockReport->_call('getSecurityStatusOfExtensions');
406  $loadedResult = $result->existing;
407  $this->assertSame($statusMock, $loadedResult);
408  }
409 
413  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded()
414  {
416  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
417  $mockTerObject
418  ->expects($this->any())
419  ->method('getVersion')
420  ->will($this->returnValue('1.0.6'));
421  $mockTerObject
422  ->expects($this->atLeastOnce())
423  ->method('getReviewState')
424  ->will($this->returnValue(0));
425  $mockExtensionList = [
426  'enetcache' => [
427  'installed' => true,
428  'terObject' => $mockTerObject
429  ],
430  ];
432  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
433  $mockListUtility
434  ->expects($this->once())
435  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
436  ->will($this->returnValue($mockExtensionList));
437 
439  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
440  $mockReport->_set('objectManager', $this->mockObjectManager);
441  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
442  $this->mockObjectManager
443  ->expects($this->at(2))
444  ->method('get')
445  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
446  ->will($this->returnValue($statusMock));
447  $mockReport->_set('listUtility', $mockListUtility);
448  $mockReport->_set('languageService', $this->mockLanguageService);
449 
450  $result = $mockReport->_call('getSecurityStatusOfExtensions');
452  $loadedResult = $result->loadedoutdated;
453  $this->assertSame($statusMock, $loadedResult);
454  }
455 
459  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded()
460  {
462  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
463  $mockTerObject
464  ->expects($this->any())
465  ->method('getVersion')
466  ->will($this->returnValue('1.0.6'));
467  $mockTerObject
468  ->expects($this->atLeastOnce())
469  ->method('getReviewState')
470  ->will($this->returnValue(-2));
471  $mockExtensionList = [
472  'enetcache' => [
473  'installed' => true,
474  'terObject' => $mockTerObject
475  ],
476  ];
478  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
479  $mockListUtility
480  ->expects($this->once())
481  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
482  ->will($this->returnValue($mockExtensionList));
483 
485  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
486  $mockReport->_set('objectManager', $this->mockObjectManager);
487  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
488  $this->mockObjectManager
489  ->expects($this->at(2))
490  ->method('get')
491  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
492  ->will($this->returnValue($statusMock));
493  $mockReport->_set('listUtility', $mockListUtility);
494  $mockReport->_set('languageService', $this->mockLanguageService);
495 
496  $result = $mockReport->_call('getSecurityStatusOfExtensions');
498  $loadedResult = $result->loadedoutdated;
499  $this->assertSame($statusMock, $loadedResult);
500  }
501 
505  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists()
506  {
508  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
509  $mockTerObject
510  ->expects($this->any())
511  ->method('getVersion')
512  ->will($this->returnValue('1.0.6'));
513  $mockTerObject
514  ->expects($this->atLeastOnce())
515  ->method('getReviewState')
516  ->will($this->returnValue(0));
517  $mockExtensionList = [
518  'enetcache' => [
519  'terObject' => $mockTerObject
520  ],
521  ];
523  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
524  $mockListUtility
525  ->expects($this->once())
526  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
527  ->will($this->returnValue($mockExtensionList));
528 
530  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
531  $mockReport->_set('objectManager', $this->mockObjectManager);
532  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
533  $this->mockObjectManager
534  ->expects($this->at(3))
535  ->method('get')
536  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
537  ->will($this->returnValue($statusMock));
538  $mockReport->_set('listUtility', $mockListUtility);
539  $mockReport->_set('languageService', $this->mockLanguageService);
540 
541  $result = $mockReport->_call('getSecurityStatusOfExtensions');
543  $loadedResult = $result->existingoutdated;
544  $this->assertSame($statusMock, $loadedResult);
545  }
546 
550  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists()
551  {
553  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
554  $mockTerObject
555  ->expects($this->any())
556  ->method('getVersion')
557  ->will($this->returnValue('1.0.6'));
558  $mockTerObject
559  ->expects($this->atLeastOnce())
560  ->method('getReviewState')
561  ->will($this->returnValue(-2));
562  $mockExtensionList = [
563  'enetcache' => [
564  'terObject' => $mockTerObject
565  ],
566  ];
568  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
569  $mockListUtility
570  ->expects($this->once())
571  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
572  ->will($this->returnValue($mockExtensionList));
573 
575  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
576  $mockReport->_set('objectManager', $this->mockObjectManager);
577  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, [], [], '', false);
578  $this->mockObjectManager
579  ->expects($this->at(3))
580  ->method('get')
581  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
582  ->will($this->returnValue($statusMock));
583  $mockReport->_set('listUtility', $mockListUtility);
584  $mockReport->_set('languageService', $this->mockLanguageService);
585 
586  $result = $mockReport->_call('getSecurityStatusOfExtensions');
588  $loadedResult = $result->existingoutdated;
589  $this->assertSame($statusMock, $loadedResult);
590  }
591 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)