2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Report;
41 protected function setUp()
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);
54 $reportMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array(), array(),
'',
false);
55 $this->assertInstanceOf(\TYPO3\CMS\Reports\StatusProviderInterface::class, $reportMock);
63 $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array(
'getSecurityStatusOfExtensions',
'getMainRepositoryStatus'), array(),
'',
false);
64 $this->assertInternalType(
'array', $report->getStatus());
72 $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array(
'getSecurityStatusOfExtensions',
'getMainRepositoryStatus'), array(),
'',
false);
73 $this->assertSame(5, count($report->getStatus()));
79 public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus()
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) {
88 $this->assertInstanceOf(\TYPO3\CMS\Reports\Status::class, $status);
96 public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult()
99 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
101 ->expects($this->any())
102 ->method(
'getVersion')
103 ->will($this->returnValue(
'1.0.6'));
105 ->expects($this->atLeastOnce())
106 ->method(
'getReviewState')
107 ->will($this->returnValue(0));
108 $mockExtensionList = array(
109 'enetcache' => array(
111 'terObject' => $mockTerObject
115 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
117 ->expects($this->once())
118 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
119 ->will($this->returnValue($mockExtensionList));
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);
127 ->expects($this->once())
128 ->method(
'getMainRepositoryStatus')
129 ->will($this->returnValue(
'foo'));
131 $result = $mockReport->getStatus();
132 $this->assertSame(
'foo', $result[
'mainRepositoryStatus']);
138 public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound()
140 $this->mockRepositoryRepository
141 ->expects($this->once())
142 ->method(
'findOneTypo3OrgRepository')
143 ->will($this->returnValue(null));
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())
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);
157 $result = $mockReport->_call(
'getMainRepositoryStatus');
158 $this->assertSame($statusMock, $result);
164 public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo()
167 $mockRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class);
169 ->expects($this->once())
170 ->method(
'getLastUpdate')
171 ->will($this->returnValue(
new \DateTime(
'-8 days')));
173 $this->mockRepositoryRepository
174 ->expects($this->once())
175 ->method(
'findOneTypo3OrgRepository')
176 ->will($this->returnValue($mockRepository));
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())
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);
191 $result = $mockReport->_call(
'getMainRepositoryStatus');
192 $this->assertSame($statusMock, $result);
198 public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo()
201 $mockRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class);
203 ->expects($this->once())
204 ->method(
'getLastUpdate')
205 ->will($this->returnValue(
new \DateTime(
'-6 days')));
207 $this->mockRepositoryRepository
208 ->expects($this->once())
209 ->method(
'findOneTypo3OrgRepository')
210 ->will($this->returnValue($mockRepository));
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())
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);
225 $result = $mockReport->_call(
'getMainRepositoryStatus');
226 $this->assertSame($statusMock, $result);
232 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded()
235 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
237 ->expects($this->any())
238 ->method(
'getVersion')
239 ->will($this->returnValue(
'1.0.6'));
241 ->expects($this->atLeastOnce())
242 ->method(
'getReviewState')
243 ->will($this->returnValue(0));
244 $mockExtensionList = array(
245 'enetcache' => array(
247 'terObject' => $mockTerObject
251 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
253 ->expects($this->once())
254 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
255 ->will($this->returnValue($mockExtensionList));
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))
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);
269 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
271 $loadedResult = $result->loaded;
272 $this->assertSame($statusMock, $loadedResult);
278 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded()
281 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
283 ->expects($this->any())
284 ->method(
'getVersion')
285 ->will($this->returnValue(
'1.0.6'));
287 ->expects($this->atLeastOnce())
288 ->method(
'getReviewState')
289 ->will($this->returnValue(-1));
290 $mockExtensionList = array(
291 'enetcache' => array(
293 'terObject' => $mockTerObject
297 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
299 ->expects($this->once())
300 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
301 ->will($this->returnValue($mockExtensionList));
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))
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);
315 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
317 $loadedResult = $result->loaded;
318 $this->assertSame($statusMock, $loadedResult);
324 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists()
327 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
329 ->expects($this->any())
330 ->method(
'getVersion')
331 ->will($this->returnValue(
'1.0.6'));
333 ->expects($this->atLeastOnce())
334 ->method(
'getReviewState')
335 ->will($this->returnValue(0));
336 $mockExtensionList = array(
337 'enetcache' => array(
338 'terObject' => $mockTerObject
342 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
344 ->expects($this->once())
345 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
346 ->will($this->returnValue($mockExtensionList));
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))
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);
360 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
362 $loadedResult = $result->existing;
363 $this->assertSame($statusMock, $loadedResult);
369 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists()
372 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
374 ->expects($this->any())
375 ->method(
'getVersion')
376 ->will($this->returnValue(
'1.0.6'));
378 ->expects($this->atLeastOnce())
379 ->method(
'getReviewState')
380 ->will($this->returnValue(-1));
381 $mockExtensionList = array(
382 'enetcache' => array(
383 'terObject' => $mockTerObject
387 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
389 ->expects($this->once())
390 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
391 ->will($this->returnValue($mockExtensionList));
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))
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);
405 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
407 $loadedResult = $result->existing;
408 $this->assertSame($statusMock, $loadedResult);
414 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded()
417 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
419 ->expects($this->any())
420 ->method(
'getVersion')
421 ->will($this->returnValue(
'1.0.6'));
423 ->expects($this->atLeastOnce())
424 ->method(
'getReviewState')
425 ->will($this->returnValue(0));
426 $mockExtensionList = array(
427 'enetcache' => array(
429 'terObject' => $mockTerObject
433 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
435 ->expects($this->once())
436 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
437 ->will($this->returnValue($mockExtensionList));
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))
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);
451 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
453 $loadedResult = $result->loadedoutdated;
454 $this->assertSame($statusMock, $loadedResult);
460 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded()
463 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
465 ->expects($this->any())
466 ->method(
'getVersion')
467 ->will($this->returnValue(
'1.0.6'));
469 ->expects($this->atLeastOnce())
470 ->method(
'getReviewState')
471 ->will($this->returnValue(-2));
472 $mockExtensionList = array(
473 'enetcache' => array(
475 'terObject' => $mockTerObject
479 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
481 ->expects($this->once())
482 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
483 ->will($this->returnValue($mockExtensionList));
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))
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);
497 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
499 $loadedResult = $result->loadedoutdated;
500 $this->assertSame($statusMock, $loadedResult);
506 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists()
509 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
511 ->expects($this->any())
512 ->method(
'getVersion')
513 ->will($this->returnValue(
'1.0.6'));
515 ->expects($this->atLeastOnce())
516 ->method(
'getReviewState')
517 ->will($this->returnValue(0));
518 $mockExtensionList = array(
519 'enetcache' => array(
520 'terObject' => $mockTerObject
524 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
526 ->expects($this->once())
527 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
528 ->will($this->returnValue($mockExtensionList));
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))
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);
542 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
544 $loadedResult = $result->existingoutdated;
545 $this->assertSame($statusMock, $loadedResult);
551 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists()
554 $mockTerObject = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
556 ->expects($this->any())
557 ->method(
'getVersion')
558 ->will($this->returnValue(
'1.0.6'));
560 ->expects($this->atLeastOnce())
561 ->method(
'getReviewState')
562 ->will($this->returnValue(-2));
563 $mockExtensionList = array(
564 'enetcache' => array(
565 'terObject' => $mockTerObject
569 $mockListUtility = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
571 ->expects($this->once())
572 ->method(
'getAvailableAndInstalledExtensionsWithAdditionalInformation')
573 ->will($this->returnValue($mockExtensionList));
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))
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);
587 $result = $mockReport->_call(
'getSecurityStatusOfExtensions');
589 $loadedResult = $result->existingoutdated;
590 $this->assertSame($statusMock, $loadedResult);