TYPO3  7.6
ExtensionStatusTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Report;
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 
17 
21 class ExtensionStatusTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
22 {
26  protected $mockObjectManager;
27 
32 
37 
41  protected function setUp()
42  {
43  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
45  $this->mockRepositoryRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class, array(), array($this->mockObjectManager));
46  $this->mockLanguageService = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, array(), array(), '', false);
47  }
48 
53  {
54  $reportMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array(), array(), '', false);
55  $this->assertInstanceOf(\TYPO3\CMS\Reports\StatusProviderInterface::class, $reportMock);
56  }
57 
61  public function getStatusReturnsArray()
62  {
63  $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', false);
64  $this->assertInternalType('array', $report->getStatus());
65  }
66 
71  {
72  $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', false);
73  $this->assertSame(5, count($report->getStatus()));
74  }
75 
79  public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus()
80  {
81  $statusObject = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array('title', 'value'));
83  $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', false);
84  $report->expects($this->any())->method('getMainRepositoryStatus')->will($this->returnValue($statusObject));
85  $resultStatuses = $report->getStatus();
86  foreach ($resultStatuses as $status) {
87  if ($status) {
88  $this->assertInstanceOf(\TYPO3\CMS\Reports\Status::class, $status);
89  }
90  }
91  }
92 
96  public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult()
97  {
99  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
100  $mockTerObject
101  ->expects($this->any())
102  ->method('getVersion')
103  ->will($this->returnValue('1.0.6'));
104  $mockTerObject
105  ->expects($this->atLeastOnce())
106  ->method('getReviewState')
107  ->will($this->returnValue(0));
108  $mockExtensionList = array(
109  'enetcache' => array(
110  'installed' => true,
111  'terObject' => $mockTerObject
112  ),
113  );
115  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
116  $mockListUtility
117  ->expects($this->once())
118  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
119  ->will($this->returnValue($mockExtensionList));
120 
122  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getMainRepositoryStatus'), array(), '', false);
123  $mockReport->_set('objectManager', $this->mockObjectManager);
124  $mockReport->_set('listUtility', $mockListUtility);
125  $mockReport->_set('languageService', $this->mockLanguageService);
126  $mockReport
127  ->expects($this->once())
128  ->method('getMainRepositoryStatus')
129  ->will($this->returnValue('foo'));
130 
131  $result = $mockReport->getStatus();
132  $this->assertSame('foo', $result['mainRepositoryStatus']);
133  }
134 
138  public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound()
139  {
140  $this->mockRepositoryRepository
141  ->expects($this->once())
142  ->method('findOneTypo3OrgRepository')
143  ->will($this->returnValue(null));
144 
146  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
147  $mockReport->_set('objectManager', $this->mockObjectManager);
148  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
149  $this->mockObjectManager
150  ->expects($this->once())
151  ->method('get')
152  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
153  ->will($this->returnValue($statusMock));
154  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
155  $mockReport->_set('languageService', $this->mockLanguageService);
156 
157  $result = $mockReport->_call('getMainRepositoryStatus');
158  $this->assertSame($statusMock, $result);
159  }
160 
164  public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo()
165  {
167  $mockRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class);
168  $mockRepository
169  ->expects($this->once())
170  ->method('getLastUpdate')
171  ->will($this->returnValue(new \DateTime('-8 days')));
172 
173  $this->mockRepositoryRepository
174  ->expects($this->once())
175  ->method('findOneTypo3OrgRepository')
176  ->will($this->returnValue($mockRepository));
177 
179  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
180  $mockReport->_set('objectManager', $this->mockObjectManager);
181  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
182  $this->mockObjectManager
183  ->expects($this->once())
184  ->method('get')
185  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::NOTICE)
186  ->will($this->returnValue($statusMock));
187  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
188  $mockReport->_set('languageService', $this->mockLanguageService);
189 
191  $result = $mockReport->_call('getMainRepositoryStatus');
192  $this->assertSame($statusMock, $result);
193  }
194 
198  public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo()
199  {
201  $mockRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class);
202  $mockRepository
203  ->expects($this->once())
204  ->method('getLastUpdate')
205  ->will($this->returnValue(new \DateTime('-6 days')));
206 
207  $this->mockRepositoryRepository
208  ->expects($this->once())
209  ->method('findOneTypo3OrgRepository')
210  ->will($this->returnValue($mockRepository));
211 
213  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
214  $mockReport->_set('objectManager', $this->mockObjectManager);
215  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
216  $this->mockObjectManager
217  ->expects($this->once())
218  ->method('get')
219  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
220  ->will($this->returnValue($statusMock));
221  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
222  $mockReport->_set('languageService', $this->mockLanguageService);
223 
225  $result = $mockReport->_call('getMainRepositoryStatus');
226  $this->assertSame($statusMock, $result);
227  }
228 
232  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded()
233  {
235  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
236  $mockTerObject
237  ->expects($this->any())
238  ->method('getVersion')
239  ->will($this->returnValue('1.0.6'));
240  $mockTerObject
241  ->expects($this->atLeastOnce())
242  ->method('getReviewState')
243  ->will($this->returnValue(0));
244  $mockExtensionList = array(
245  'enetcache' => array(
246  'installed' => true,
247  'terObject' => $mockTerObject
248  ),
249  );
251  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
252  $mockListUtility
253  ->expects($this->once())
254  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
255  ->will($this->returnValue($mockExtensionList));
256 
258  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
259  $mockReport->_set('objectManager', $this->mockObjectManager);
260  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
261  $this->mockObjectManager
262  ->expects($this->at(0))
263  ->method('get')
264  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
265  ->will($this->returnValue($statusMock));
266  $mockReport->_set('listUtility', $mockListUtility);
267  $mockReport->_set('languageService', $this->mockLanguageService);
268 
269  $result = $mockReport->_call('getSecurityStatusOfExtensions');
271  $loadedResult = $result->loaded;
272  $this->assertSame($statusMock, $loadedResult);
273  }
274 
278  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded()
279  {
281  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
282  $mockTerObject
283  ->expects($this->any())
284  ->method('getVersion')
285  ->will($this->returnValue('1.0.6'));
286  $mockTerObject
287  ->expects($this->atLeastOnce())
288  ->method('getReviewState')
289  ->will($this->returnValue(-1));
290  $mockExtensionList = array(
291  'enetcache' => array(
292  'installed' => true,
293  'terObject' => $mockTerObject
294  ),
295  );
297  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
298  $mockListUtility
299  ->expects($this->once())
300  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
301  ->will($this->returnValue($mockExtensionList));
302 
304  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
305  $mockReport->_set('objectManager', $this->mockObjectManager);
306  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
307  $this->mockObjectManager
308  ->expects($this->at(0))
309  ->method('get')
310  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
311  ->will($this->returnValue($statusMock));
312  $mockReport->_set('listUtility', $mockListUtility);
313  $mockReport->_set('languageService', $this->mockLanguageService);
314 
315  $result = $mockReport->_call('getSecurityStatusOfExtensions');
317  $loadedResult = $result->loaded;
318  $this->assertSame($statusMock, $loadedResult);
319  }
320 
324  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists()
325  {
327  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
328  $mockTerObject
329  ->expects($this->any())
330  ->method('getVersion')
331  ->will($this->returnValue('1.0.6'));
332  $mockTerObject
333  ->expects($this->atLeastOnce())
334  ->method('getReviewState')
335  ->will($this->returnValue(0));
336  $mockExtensionList = array(
337  'enetcache' => array(
338  'terObject' => $mockTerObject
339  ),
340  );
342  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
343  $mockListUtility
344  ->expects($this->once())
345  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
346  ->will($this->returnValue($mockExtensionList));
347 
349  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
350  $mockReport->_set('objectManager', $this->mockObjectManager);
351  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
352  $this->mockObjectManager
353  ->expects($this->at(1))
354  ->method('get')
355  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
356  ->will($this->returnValue($statusMock));
357  $mockReport->_set('listUtility', $mockListUtility);
358  $mockReport->_set('languageService', $this->mockLanguageService);
359 
360  $result = $mockReport->_call('getSecurityStatusOfExtensions');
362  $loadedResult = $result->existing;
363  $this->assertSame($statusMock, $loadedResult);
364  }
365 
369  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists()
370  {
372  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
373  $mockTerObject
374  ->expects($this->any())
375  ->method('getVersion')
376  ->will($this->returnValue('1.0.6'));
377  $mockTerObject
378  ->expects($this->atLeastOnce())
379  ->method('getReviewState')
380  ->will($this->returnValue(-1));
381  $mockExtensionList = array(
382  'enetcache' => array(
383  'terObject' => $mockTerObject
384  ),
385  );
387  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
388  $mockListUtility
389  ->expects($this->once())
390  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
391  ->will($this->returnValue($mockExtensionList));
392 
394  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
395  $mockReport->_set('objectManager', $this->mockObjectManager);
396  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
397  $this->mockObjectManager
398  ->expects($this->at(1))
399  ->method('get')
400  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
401  ->will($this->returnValue($statusMock));
402  $mockReport->_set('listUtility', $mockListUtility);
403  $mockReport->_set('languageService', $this->mockLanguageService);
404 
405  $result = $mockReport->_call('getSecurityStatusOfExtensions');
407  $loadedResult = $result->existing;
408  $this->assertSame($statusMock, $loadedResult);
409  }
410 
414  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded()
415  {
417  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
418  $mockTerObject
419  ->expects($this->any())
420  ->method('getVersion')
421  ->will($this->returnValue('1.0.6'));
422  $mockTerObject
423  ->expects($this->atLeastOnce())
424  ->method('getReviewState')
425  ->will($this->returnValue(0));
426  $mockExtensionList = array(
427  'enetcache' => array(
428  'installed' => true,
429  'terObject' => $mockTerObject
430  ),
431  );
433  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
434  $mockListUtility
435  ->expects($this->once())
436  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
437  ->will($this->returnValue($mockExtensionList));
438 
440  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
441  $mockReport->_set('objectManager', $this->mockObjectManager);
442  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
443  $this->mockObjectManager
444  ->expects($this->at(2))
445  ->method('get')
446  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
447  ->will($this->returnValue($statusMock));
448  $mockReport->_set('listUtility', $mockListUtility);
449  $mockReport->_set('languageService', $this->mockLanguageService);
450 
451  $result = $mockReport->_call('getSecurityStatusOfExtensions');
453  $loadedResult = $result->loadedoutdated;
454  $this->assertSame($statusMock, $loadedResult);
455  }
456 
460  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded()
461  {
463  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
464  $mockTerObject
465  ->expects($this->any())
466  ->method('getVersion')
467  ->will($this->returnValue('1.0.6'));
468  $mockTerObject
469  ->expects($this->atLeastOnce())
470  ->method('getReviewState')
471  ->will($this->returnValue(-2));
472  $mockExtensionList = array(
473  'enetcache' => array(
474  'installed' => true,
475  'terObject' => $mockTerObject
476  ),
477  );
479  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
480  $mockListUtility
481  ->expects($this->once())
482  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
483  ->will($this->returnValue($mockExtensionList));
484 
486  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
487  $mockReport->_set('objectManager', $this->mockObjectManager);
488  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
489  $this->mockObjectManager
490  ->expects($this->at(2))
491  ->method('get')
492  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
493  ->will($this->returnValue($statusMock));
494  $mockReport->_set('listUtility', $mockListUtility);
495  $mockReport->_set('languageService', $this->mockLanguageService);
496 
497  $result = $mockReport->_call('getSecurityStatusOfExtensions');
499  $loadedResult = $result->loadedoutdated;
500  $this->assertSame($statusMock, $loadedResult);
501  }
502 
506  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists()
507  {
509  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
510  $mockTerObject
511  ->expects($this->any())
512  ->method('getVersion')
513  ->will($this->returnValue('1.0.6'));
514  $mockTerObject
515  ->expects($this->atLeastOnce())
516  ->method('getReviewState')
517  ->will($this->returnValue(0));
518  $mockExtensionList = array(
519  'enetcache' => array(
520  'terObject' => $mockTerObject
521  ),
522  );
524  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
525  $mockListUtility
526  ->expects($this->once())
527  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
528  ->will($this->returnValue($mockExtensionList));
529 
531  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
532  $mockReport->_set('objectManager', $this->mockObjectManager);
533  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
534  $this->mockObjectManager
535  ->expects($this->at(3))
536  ->method('get')
537  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
538  ->will($this->returnValue($statusMock));
539  $mockReport->_set('listUtility', $mockListUtility);
540  $mockReport->_set('languageService', $this->mockLanguageService);
541 
542  $result = $mockReport->_call('getSecurityStatusOfExtensions');
544  $loadedResult = $result->existingoutdated;
545  $this->assertSame($statusMock, $loadedResult);
546  }
547 
551  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists()
552  {
554  $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
555  $mockTerObject
556  ->expects($this->any())
557  ->method('getVersion')
558  ->will($this->returnValue('1.0.6'));
559  $mockTerObject
560  ->expects($this->atLeastOnce())
561  ->method('getReviewState')
562  ->will($this->returnValue(-2));
563  $mockExtensionList = array(
564  'enetcache' => array(
565  'terObject' => $mockTerObject
566  ),
567  );
569  $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
570  $mockListUtility
571  ->expects($this->once())
572  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
573  ->will($this->returnValue($mockExtensionList));
574 
576  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
577  $mockReport->_set('objectManager', $this->mockObjectManager);
578  $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', false);
579  $this->mockObjectManager
580  ->expects($this->at(3))
581  ->method('get')
582  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
583  ->will($this->returnValue($statusMock));
584  $mockReport->_set('listUtility', $mockListUtility);
585  $mockReport->_set('languageService', $this->mockLanguageService);
586 
587  $result = $mockReport->_call('getSecurityStatusOfExtensions');
589  $loadedResult = $result->existingoutdated;
590  $this->assertSame($statusMock, $loadedResult);
591  }
592 }