TYPO3 CMS  TYPO3_8-7
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 
20 class ExtensionStatusTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $mockObjectManager;
26 
31 
36 
40  protected function setUp()
41  {
42  $this->mockObjectManager = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class)->getMock();
44  $this->mockRepositoryRepository = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class)
45  ->setConstructorArgs([$this->mockObjectManager])
46  ->getMock();
47  $this->mockLanguageService = $this->createMock(\TYPO3\CMS\Lang\LanguageService::class);
48  }
49 
54  {
55  $reportMock = $this->createMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class);
56  $this->assertInstanceOf(\TYPO3\CMS\Reports\StatusProviderInterface::class, $reportMock);
57  }
58 
62  public function getStatusReturnsArray()
63  {
64  $report = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class)
65  ->setMethods(['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'])
66  ->disableOriginalConstructor()
67  ->getMock();
68  $this->assertInternalType('array', $report->getStatus());
69  }
70 
75  {
76  $report = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class)
77  ->setMethods(['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'])
78  ->disableOriginalConstructor()
79  ->getMock();
80  $this->assertSame(5, count($report->getStatus()));
81  }
82 
86  public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus()
87  {
88  $statusObject = $this->getMockBuilder(\TYPO3\CMS\Reports\Status::class)
89  ->setConstructorArgs(['title', 'value'])
90  ->getMock();
92  $report = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class)
93  ->setMethods(['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'])
94  ->disableOriginalConstructor()
95  ->getMock();
96  $report->expects($this->any())->method('getMainRepositoryStatus')->will($this->returnValue($statusObject));
97  $resultStatuses = $report->getStatus();
98  foreach ($resultStatuses as $status) {
99  if ($status) {
100  $this->assertInstanceOf(\TYPO3\CMS\Reports\Status::class, $status);
101  }
102  }
103  }
104 
108  public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult()
109  {
111  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
112  $mockTerObject
113  ->expects($this->any())
114  ->method('getVersion')
115  ->will($this->returnValue('1.0.6'));
116  $mockTerObject
117  ->expects($this->atLeastOnce())
118  ->method('getReviewState')
119  ->will($this->returnValue(0));
120  $mockExtensionList = [
121  'enetcache' => [
122  'installed' => true,
123  'terObject' => $mockTerObject
124  ],
125  ];
127  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
128  $mockListUtility
129  ->expects($this->once())
130  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
131  ->will($this->returnValue($mockExtensionList));
132 
134  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['getMainRepositoryStatus'], [], '', false);
135  $mockReport->_set('objectManager', $this->mockObjectManager);
136  $mockReport->_set('listUtility', $mockListUtility);
137  $mockReport->_set('languageService', $this->mockLanguageService);
138  $mockReport
139  ->expects($this->once())
140  ->method('getMainRepositoryStatus')
141  ->will($this->returnValue('foo'));
142 
143  $result = $mockReport->getStatus();
144  $this->assertSame('foo', $result['mainRepositoryStatus']);
145  }
146 
150  public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound()
151  {
152  $this->mockRepositoryRepository
153  ->expects($this->once())
154  ->method('findOneTypo3OrgRepository')
155  ->will($this->returnValue(null));
156 
158  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
159  $mockReport->_set('objectManager', $this->mockObjectManager);
160  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
161  $this->mockObjectManager
162  ->expects($this->once())
163  ->method('get')
164  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
165  ->will($this->returnValue($statusMock));
166  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
167  $mockReport->_set('languageService', $this->mockLanguageService);
168 
169  $result = $mockReport->_call('getMainRepositoryStatus');
170  $this->assertSame($statusMock, $result);
171  }
172 
176  public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo()
177  {
179  $mockRepository = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class)->getMock();
180  $mockRepository
181  ->expects($this->once())
182  ->method('getLastUpdate')
183  ->will($this->returnValue(new \DateTime('-8 days')));
184 
185  $this->mockRepositoryRepository
186  ->expects($this->once())
187  ->method('findOneTypo3OrgRepository')
188  ->will($this->returnValue($mockRepository));
189 
191  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
192  $mockReport->_set('objectManager', $this->mockObjectManager);
193  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
194  $this->mockObjectManager
195  ->expects($this->once())
196  ->method('get')
197  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::NOTICE)
198  ->will($this->returnValue($statusMock));
199  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
200  $mockReport->_set('languageService', $this->mockLanguageService);
201 
203  $result = $mockReport->_call('getMainRepositoryStatus');
204  $this->assertSame($statusMock, $result);
205  }
206 
210  public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo()
211  {
213  $mockRepository = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class)->getMock();
214  $mockRepository
215  ->expects($this->once())
216  ->method('getLastUpdate')
217  ->will($this->returnValue(new \DateTime('-6 days')));
218 
219  $this->mockRepositoryRepository
220  ->expects($this->once())
221  ->method('findOneTypo3OrgRepository')
222  ->will($this->returnValue($mockRepository));
223 
225  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
226  $mockReport->_set('objectManager', $this->mockObjectManager);
227  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
228  $this->mockObjectManager
229  ->expects($this->once())
230  ->method('get')
231  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
232  ->will($this->returnValue($statusMock));
233  $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
234  $mockReport->_set('languageService', $this->mockLanguageService);
235 
237  $result = $mockReport->_call('getMainRepositoryStatus');
238  $this->assertSame($statusMock, $result);
239  }
240 
244  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded()
245  {
247  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
248  $mockTerObject
249  ->expects($this->any())
250  ->method('getVersion')
251  ->will($this->returnValue('1.0.6'));
252  $mockTerObject
253  ->expects($this->atLeastOnce())
254  ->method('getReviewState')
255  ->will($this->returnValue(0));
256  $mockExtensionList = [
257  'enetcache' => [
258  'installed' => true,
259  'terObject' => $mockTerObject
260  ],
261  ];
263  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
264  $mockListUtility
265  ->expects($this->once())
266  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
267  ->will($this->returnValue($mockExtensionList));
268 
270  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
271  $mockReport->_set('objectManager', $this->mockObjectManager);
272  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
273  $this->mockObjectManager
274  ->expects($this->at(0))
275  ->method('get')
276  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
277  ->will($this->returnValue($statusMock));
278  $mockReport->_set('listUtility', $mockListUtility);
279  $mockReport->_set('languageService', $this->mockLanguageService);
280 
281  $result = $mockReport->_call('getSecurityStatusOfExtensions');
283  $loadedResult = $result->loaded;
284  $this->assertSame($statusMock, $loadedResult);
285  }
286 
290  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded()
291  {
293  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
294  $mockTerObject
295  ->expects($this->any())
296  ->method('getVersion')
297  ->will($this->returnValue('1.0.6'));
298  $mockTerObject
299  ->expects($this->atLeastOnce())
300  ->method('getReviewState')
301  ->will($this->returnValue(-1));
302  $mockExtensionList = [
303  'enetcache' => [
304  'installed' => true,
305  'terObject' => $mockTerObject
306  ],
307  ];
309  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
310  $mockListUtility
311  ->expects($this->once())
312  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
313  ->will($this->returnValue($mockExtensionList));
314 
316  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
317  $mockReport->_set('objectManager', $this->mockObjectManager);
318  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
319  $this->mockObjectManager
320  ->expects($this->at(0))
321  ->method('get')
322  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
323  ->will($this->returnValue($statusMock));
324  $mockReport->_set('listUtility', $mockListUtility);
325  $mockReport->_set('languageService', $this->mockLanguageService);
326 
327  $result = $mockReport->_call('getSecurityStatusOfExtensions');
329  $loadedResult = $result->loaded;
330  $this->assertSame($statusMock, $loadedResult);
331  }
332 
336  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists()
337  {
339  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
340  $mockTerObject
341  ->expects($this->any())
342  ->method('getVersion')
343  ->will($this->returnValue('1.0.6'));
344  $mockTerObject
345  ->expects($this->atLeastOnce())
346  ->method('getReviewState')
347  ->will($this->returnValue(0));
348  $mockExtensionList = [
349  'enetcache' => [
350  'terObject' => $mockTerObject
351  ],
352  ];
354  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
355  $mockListUtility
356  ->expects($this->once())
357  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
358  ->will($this->returnValue($mockExtensionList));
359 
361  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
362  $mockReport->_set('objectManager', $this->mockObjectManager);
363  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
364  $this->mockObjectManager
365  ->expects($this->at(1))
366  ->method('get')
367  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
368  ->will($this->returnValue($statusMock));
369  $mockReport->_set('listUtility', $mockListUtility);
370  $mockReport->_set('languageService', $this->mockLanguageService);
371 
372  $result = $mockReport->_call('getSecurityStatusOfExtensions');
374  $loadedResult = $result->existing;
375  $this->assertSame($statusMock, $loadedResult);
376  }
377 
381  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists()
382  {
384  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
385  $mockTerObject
386  ->expects($this->any())
387  ->method('getVersion')
388  ->will($this->returnValue('1.0.6'));
389  $mockTerObject
390  ->expects($this->atLeastOnce())
391  ->method('getReviewState')
392  ->will($this->returnValue(-1));
393  $mockExtensionList = [
394  'enetcache' => [
395  'terObject' => $mockTerObject
396  ],
397  ];
399  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
400  $mockListUtility
401  ->expects($this->once())
402  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
403  ->will($this->returnValue($mockExtensionList));
404 
406  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
407  $mockReport->_set('objectManager', $this->mockObjectManager);
408  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
409  $this->mockObjectManager
410  ->expects($this->at(1))
411  ->method('get')
412  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
413  ->will($this->returnValue($statusMock));
414  $mockReport->_set('listUtility', $mockListUtility);
415  $mockReport->_set('languageService', $this->mockLanguageService);
416 
417  $result = $mockReport->_call('getSecurityStatusOfExtensions');
419  $loadedResult = $result->existing;
420  $this->assertSame($statusMock, $loadedResult);
421  }
422 
426  public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded()
427  {
429  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
430  $mockTerObject
431  ->expects($this->any())
432  ->method('getVersion')
433  ->will($this->returnValue('1.0.6'));
434  $mockTerObject
435  ->expects($this->atLeastOnce())
436  ->method('getReviewState')
437  ->will($this->returnValue(0));
438  $mockExtensionList = [
439  'enetcache' => [
440  'installed' => true,
441  'terObject' => $mockTerObject
442  ],
443  ];
445  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
446  $mockListUtility
447  ->expects($this->once())
448  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
449  ->will($this->returnValue($mockExtensionList));
450 
452  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
453  $mockReport->_set('objectManager', $this->mockObjectManager);
454  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
455  $this->mockObjectManager
456  ->expects($this->at(2))
457  ->method('get')
458  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
459  ->will($this->returnValue($statusMock));
460  $mockReport->_set('listUtility', $mockListUtility);
461  $mockReport->_set('languageService', $this->mockLanguageService);
462 
463  $result = $mockReport->_call('getSecurityStatusOfExtensions');
465  $loadedResult = $result->loadedoutdated;
466  $this->assertSame($statusMock, $loadedResult);
467  }
468 
472  public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded()
473  {
475  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
476  $mockTerObject
477  ->expects($this->any())
478  ->method('getVersion')
479  ->will($this->returnValue('1.0.6'));
480  $mockTerObject
481  ->expects($this->atLeastOnce())
482  ->method('getReviewState')
483  ->will($this->returnValue(-2));
484  $mockExtensionList = [
485  'enetcache' => [
486  'installed' => true,
487  'terObject' => $mockTerObject
488  ],
489  ];
491  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
492  $mockListUtility
493  ->expects($this->once())
494  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
495  ->will($this->returnValue($mockExtensionList));
496 
498  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
499  $mockReport->_set('objectManager', $this->mockObjectManager);
500  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
501  $this->mockObjectManager
502  ->expects($this->at(2))
503  ->method('get')
504  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
505  ->will($this->returnValue($statusMock));
506  $mockReport->_set('listUtility', $mockListUtility);
507  $mockReport->_set('languageService', $this->mockLanguageService);
508 
509  $result = $mockReport->_call('getSecurityStatusOfExtensions');
511  $loadedResult = $result->loadedoutdated;
512  $this->assertSame($statusMock, $loadedResult);
513  }
514 
518  public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists()
519  {
521  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
522  $mockTerObject
523  ->expects($this->any())
524  ->method('getVersion')
525  ->will($this->returnValue('1.0.6'));
526  $mockTerObject
527  ->expects($this->atLeastOnce())
528  ->method('getReviewState')
529  ->will($this->returnValue(0));
530  $mockExtensionList = [
531  'enetcache' => [
532  'terObject' => $mockTerObject
533  ],
534  ];
536  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
537  $mockListUtility
538  ->expects($this->once())
539  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
540  ->will($this->returnValue($mockExtensionList));
541 
543  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
544  $mockReport->_set('objectManager', $this->mockObjectManager);
545  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
546  $this->mockObjectManager
547  ->expects($this->at(3))
548  ->method('get')
549  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
550  ->will($this->returnValue($statusMock));
551  $mockReport->_set('listUtility', $mockListUtility);
552  $mockReport->_set('languageService', $this->mockLanguageService);
553 
554  $result = $mockReport->_call('getSecurityStatusOfExtensions');
556  $loadedResult = $result->existingoutdated;
557  $this->assertSame($statusMock, $loadedResult);
558  }
559 
563  public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists()
564  {
566  $mockTerObject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
567  $mockTerObject
568  ->expects($this->any())
569  ->method('getVersion')
570  ->will($this->returnValue('1.0.6'));
571  $mockTerObject
572  ->expects($this->atLeastOnce())
573  ->method('getReviewState')
574  ->will($this->returnValue(-2));
575  $mockExtensionList = [
576  'enetcache' => [
577  'terObject' => $mockTerObject
578  ],
579  ];
581  $mockListUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)->getMock();
582  $mockListUtility
583  ->expects($this->once())
584  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
585  ->will($this->returnValue($mockExtensionList));
586 
588  $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, ['dummy'], [], '', false);
589  $mockReport->_set('objectManager', $this->mockObjectManager);
590  $statusMock = $this->createMock(\TYPO3\CMS\Reports\Status::class);
591  $this->mockObjectManager
592  ->expects($this->at(3))
593  ->method('get')
594  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
595  ->will($this->returnValue($statusMock));
596  $mockReport->_set('listUtility', $mockListUtility);
597  $mockReport->_set('languageService', $this->mockLanguageService);
598 
599  $result = $mockReport->_call('getSecurityStatusOfExtensions');
601  $loadedResult = $result->existingoutdated;
602  $this->assertSame($statusMock, $loadedResult);
603  }
604 }