[TASK] Removes extra empty lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Report / ExtensionStatusTest.php
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 /**
18 * Test case
19 */
20 class ExtensionStatusTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
24 */
25 protected $mockObjectManager;
26
27 /**
28 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
29 */
30 protected $mockRepositoryRepository;
31
32 /**
33 * @var \TYPO3\CMS\Lang\LanguageService
34 */
35 protected $mockLanguageService;
36
37 /**
38 * Set up
39 */
40 protected function setUp()
41 {
42 $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
43 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository|\PHPUnit_Framework_MockObject_MockObject */
44 $this->mockRepositoryRepository = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class, array(), array($this->mockObjectManager));
45 $this->mockLanguageService = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, array(), array(), '', false);
46 }
47
48 /**
49 * @test
50 */
51 public function extensionStatusImplementsStatusProviderInterface()
52 {
53 $reportMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array(), array(), '', false);
54 $this->assertInstanceOf(\TYPO3\CMS\Reports\StatusProviderInterface::class, $reportMock);
55 }
56
57 /**
58 * @test
59 */
60 public function getStatusReturnsArray()
61 {
62 $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', false);
63 $this->assertInternalType('array', $report->getStatus());
64 }
65
66 /**
67 * @test
68 */
69 public function getStatusReturnArrayContainsFiveEntries()
70 {
71 $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', false);
72 $this->assertSame(5, count($report->getStatus()));
73 }
74
75 /**
76 * @test
77 */
78 public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus()
79 {
80 $statusObject = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array('title', 'value'));
81 /** @var \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus $report */
82 $report = $this->getMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', 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
92 /**
93 * @test
94 */
95 public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult()
96 {
97 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
108 'enetcache' => array(
109 'installed' => true,
110 'terObject' => $mockTerObject
111 ),
112 );
113 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
120 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject */
121 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('getMainRepositoryStatus'), array(), '', 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
134 /**
135 * @test
136 */
137 public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound()
138 {
139 $this->mockRepositoryRepository
140 ->expects($this->once())
141 ->method('findOneTypo3OrgRepository')
142 ->will($this->returnValue(null));
143
144 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
145 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
146 $mockReport->_set('objectManager', $this->mockObjectManager);
147 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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
160 /**
161 * @test
162 */
163 public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo()
164 {
165 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository|\PHPUnit_Framework_MockObject_MockObject */
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
177 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
178 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
179 $mockReport->_set('objectManager', $this->mockObjectManager);
180 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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
189 /** @var $result \TYPO3\CMS\Reports\Status */
190 $result = $mockReport->_call('getMainRepositoryStatus');
191 $this->assertSame($statusMock, $result);
192 }
193
194 /**
195 * @test
196 */
197 public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo()
198 {
199 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository|\PHPUnit_Framework_MockObject_MockObject */
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
211 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
212 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
213 $mockReport->_set('objectManager', $this->mockObjectManager);
214 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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
223 /** @var $result \TYPO3\CMS\Reports\Status */
224 $result = $mockReport->_call('getMainRepositoryStatus');
225 $this->assertSame($statusMock, $result);
226 }
227
228 /**
229 * @test
230 */
231 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded()
232 {
233 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
244 'enetcache' => array(
245 'installed' => true,
246 'terObject' => $mockTerObject
247 ),
248 );
249 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
256 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
257 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
258 $mockReport->_set('objectManager', $this->mockObjectManager);
259 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
269 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
270 $loadedResult = $result->loaded;
271 $this->assertSame($statusMock, $loadedResult);
272 }
273
274 /**
275 * @test
276 */
277 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded()
278 {
279 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
290 'enetcache' => array(
291 'installed' => true,
292 'terObject' => $mockTerObject
293 ),
294 );
295 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
302 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
303 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
304 $mockReport->_set('objectManager', $this->mockObjectManager);
305 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
315 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
316 $loadedResult = $result->loaded;
317 $this->assertSame($statusMock, $loadedResult);
318 }
319
320 /**
321 * @test
322 */
323 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists()
324 {
325 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
336 'enetcache' => array(
337 'terObject' => $mockTerObject
338 ),
339 );
340 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
347 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
348 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
349 $mockReport->_set('objectManager', $this->mockObjectManager);
350 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
360 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
361 $loadedResult = $result->existing;
362 $this->assertSame($statusMock, $loadedResult);
363 }
364
365 /**
366 * @test
367 */
368 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists()
369 {
370 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
381 'enetcache' => array(
382 'terObject' => $mockTerObject
383 ),
384 );
385 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
392 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
393 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
394 $mockReport->_set('objectManager', $this->mockObjectManager);
395 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
405 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
406 $loadedResult = $result->existing;
407 $this->assertSame($statusMock, $loadedResult);
408 }
409
410 /**
411 * @test
412 */
413 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded()
414 {
415 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
426 'enetcache' => array(
427 'installed' => true,
428 'terObject' => $mockTerObject
429 ),
430 );
431 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
438 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
439 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
440 $mockReport->_set('objectManager', $this->mockObjectManager);
441 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
451 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
452 $loadedResult = $result->loadedoutdated;
453 $this->assertSame($statusMock, $loadedResult);
454 }
455
456 /**
457 * @test
458 */
459 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded()
460 {
461 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
472 'enetcache' => array(
473 'installed' => true,
474 'terObject' => $mockTerObject
475 ),
476 );
477 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
484 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
485 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
486 $mockReport->_set('objectManager', $this->mockObjectManager);
487 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
497 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
498 $loadedResult = $result->loadedoutdated;
499 $this->assertSame($statusMock, $loadedResult);
500 }
501
502 /**
503 * @test
504 */
505 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists()
506 {
507 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
518 'enetcache' => array(
519 'terObject' => $mockTerObject
520 ),
521 );
522 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
529 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
530 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
531 $mockReport->_set('objectManager', $this->mockObjectManager);
532 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
542 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
543 $loadedResult = $result->existingoutdated;
544 $this->assertSame($statusMock, $loadedResult);
545 }
546
547 /**
548 * @test
549 */
550 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists()
551 {
552 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
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 = array(
563 'enetcache' => array(
564 'terObject' => $mockTerObject
565 ),
566 );
567 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
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
574 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
575 $mockReport = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Report\ExtensionStatus::class, array('dummy'), array(), '', false);
576 $mockReport->_set('objectManager', $this->mockObjectManager);
577 $statusMock = $this->getMock(\TYPO3\CMS\Reports\Status::class, array(), array(), '', 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');
587 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
588 $loadedResult = $result->existingoutdated;
589 $this->assertSame($statusMock, $loadedResult);
590 }
591 }