[TASK] Better mocking of $GLOBALS['LANG']
[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 * Copyright notice
6 *
7 * (c) 2010-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Extensionmanager\Report;
28
29 /**
30 * Test case
31 */
32 class ExtensionStatusTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
36 */
37 protected $mockObjectManager;
38
39 /**
40 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
41 */
42 protected $mockRepositoryRepository;
43
44 /**
45 * @var \TYPO3\CMS\Lang\LanguageService
46 */
47 protected $mockLanguageService;
48
49 /**
50 * Set up
51 */
52 public function setUp() {
53 $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
54 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository|\PHPUnit_Framework_MockObject_MockObject */
55 $this->mockRepositoryRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository', array(), array($this->mockObjectManager));
56 $this->mockLanguageService = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
57 }
58
59 /**
60 * @test
61 */
62 public function extensionStatusImplementsStatusProviderInterface() {
63 $reportMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array(), array(), '', FALSE);
64 $this->assertInstanceOf('TYPO3\\CMS\\Reports\\StatusProviderInterface', $reportMock);
65 }
66
67 /**
68 * @test
69 */
70 public function getStatusReturnsArray() {
71 $report = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', FALSE);
72 $this->assertInternalType('array', $report->getStatus());
73 }
74
75 /**
76 * @test
77 */
78 public function getStatusReturnArrayContainsFiveEntries() {
79 $report = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', FALSE);
80 $this->assertSame(5, count($report->getStatus()));
81 }
82
83 /**
84 * @test
85 */
86 public function getStatusReturnArrayContainsInstancesOfReportsStatusStatus() {
87 $statusObject = $this->objectManager->get('TYPO3\\CMS\\Reports\\Status', 'title', 'value');
88 /** @var \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus $report */
89 $report = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getSecurityStatusOfExtensions', 'getMainRepositoryStatus'), array(), '', FALSE);
90 $report->expects($this->any())->method('getMainRepositoryStatus')->will($this->returnValue($statusObject));
91 $resultStatuses = $report->getStatus();
92 foreach($resultStatuses as $status) {
93 if ($status) {
94 $this->assertInstanceOf('TYPO3\\CMS\\Reports\\Status', $status);
95 }
96 }
97 }
98
99 /**
100 * @test
101 */
102 public function getStatusCallsGetMainRepositoryStatusForMainRepositoryStatusResult() {
103 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
104 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
105 $mockTerObject
106 ->expects($this->any())
107 ->method('getVersion')
108 ->will($this->returnValue('1.0.6'));
109 $mockTerObject
110 ->expects($this->atLeastOnce())
111 ->method('getReviewState')
112 ->will($this->returnValue(0));
113 $mockExtensionList = array(
114 'enetcache' => array(
115 'installed' => TRUE,
116 'terObject' => $mockTerObject
117 ),
118 );
119 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
120 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
121 $mockListUtility
122 ->expects($this->once())
123 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
124 ->will($this->returnValue($mockExtensionList));
125
126 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject */
127 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('getMainRepositoryStatus'), array(), '', FALSE);
128 $mockReport->_set('objectManager', $this->mockObjectManager);
129 $mockReport->_set('listUtility', $mockListUtility);
130 $mockReport->_set('languageService', $this->mockLanguageService);
131 $mockReport
132 ->expects($this->once())
133 ->method('getMainRepositoryStatus')
134 ->will($this->returnValue('foo'));
135
136 $result = $mockReport->getStatus();
137 $this->assertSame('foo', $result['mainRepositoryStatus']);
138 }
139
140 /**
141 * @test
142 */
143 public function getMainRepositoryStatusReturnsErrorStatusIfRepositoryIsNotFound() {
144 $this->mockRepositoryRepository
145 ->expects($this->once())
146 ->method('findOneTypo3OrgRepository')
147 ->will($this->returnValue(NULL));
148
149 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
150 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
151 $mockReport->_set('objectManager', $this->objectManager);
152 $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
153 $mockReport->_set('languageService', $this->mockLanguageService);
154
155 /** @var $result \TYPO3\CMS\Reports\Status */
156 $result = $mockReport->_call('getMainRepositoryStatus');
157 $this->assertSame(\TYPO3\CMS\Reports\Status::ERROR, $result->getSeverity());
158 }
159
160 /**
161 * @test
162 */
163 public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo() {
164 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository|\PHPUnit_Framework_MockObject_MockObject */
165 $mockRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository');
166 $mockRepository
167 ->expects($this->once())
168 ->method('getLastUpdate')
169 ->will($this->returnValue(new \DateTime('-8 days')));
170
171 $this->mockRepositoryRepository
172 ->expects($this->once())
173 ->method('findOneTypo3OrgRepository')
174 ->will($this->returnValue($mockRepository));
175
176 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
177 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
178 $mockReport->_set('objectManager', $this->objectManager);
179 $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
180 $mockReport->_set('languageService', $this->mockLanguageService);
181
182 /** @var $result \TYPO3\CMS\Reports\Status */
183 $result = $mockReport->_call('getMainRepositoryStatus');
184 $this->assertSame(\TYPO3\CMS\Reports\Status::NOTICE, $result->getSeverity());
185 }
186
187 /**
188 * @test
189 */
190 public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo() {
191 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository|\PHPUnit_Framework_MockObject_MockObject */
192 $mockRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository');
193 $mockRepository
194 ->expects($this->once())
195 ->method('getLastUpdate')
196 ->will($this->returnValue(new \DateTime('-6 days')));
197
198 $this->mockRepositoryRepository
199 ->expects($this->once())
200 ->method('findOneTypo3OrgRepository')
201 ->will($this->returnValue($mockRepository));
202
203 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
204 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
205 $mockReport->_set('objectManager', $this->objectManager);
206 $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
207 $mockReport->_set('languageService', $this->mockLanguageService);
208
209 /** @var $result \TYPO3\CMS\Reports\Status */
210 $result = $mockReport->_call('getMainRepositoryStatus');
211 $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $result->getSeverity());
212 }
213
214 /**
215 * @test
216 */
217 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded() {
218 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
219 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
220 $mockTerObject
221 ->expects($this->any())
222 ->method('getVersion')
223 ->will($this->returnValue('1.0.6'));
224 $mockTerObject
225 ->expects($this->atLeastOnce())
226 ->method('getReviewState')
227 ->will($this->returnValue(0));
228 $mockExtensionList = array(
229 'enetcache' => array(
230 'installed' => TRUE,
231 'terObject' => $mockTerObject
232 ),
233 );
234 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
235 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
236 $mockListUtility
237 ->expects($this->once())
238 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
239 ->will($this->returnValue($mockExtensionList));
240
241 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
242 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
243 $mockReport->_set('objectManager', $this->objectManager);
244 $mockReport->_set('listUtility', $mockListUtility);
245 $mockReport->_set('languageService', $this->mockLanguageService);
246
247 $result = $mockReport->_call('getSecurityStatusOfExtensions');
248 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
249 $loadedResult = $result->loaded;
250 $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $loadedResult->getSeverity());
251 }
252
253 /**
254 * @test
255 */
256 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded() {
257 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
258 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
259 $mockTerObject
260 ->expects($this->any())
261 ->method('getVersion')
262 ->will($this->returnValue('1.0.6'));
263 $mockTerObject
264 ->expects($this->atLeastOnce())
265 ->method('getReviewState')
266 ->will($this->returnValue(-1));
267 $mockExtensionList = array(
268 'enetcache' => array(
269 'installed' => TRUE,
270 'terObject' => $mockTerObject
271 ),
272 );
273 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
274 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
275 $mockListUtility
276 ->expects($this->once())
277 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
278 ->will($this->returnValue($mockExtensionList));
279
280 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
281 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
282 $mockReport->_set('objectManager', $this->objectManager);
283 $mockReport->_set('listUtility', $mockListUtility);
284 $mockReport->_set('languageService', $this->mockLanguageService);
285
286 $result = $mockReport->_call('getSecurityStatusOfExtensions');
287 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
288 $loadedResult = $result->loaded;
289 $this->assertSame(\TYPO3\CMS\Reports\Status::ERROR, $loadedResult->getSeverity());
290 }
291
292 /**
293 * @test
294 */
295 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists() {
296 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
297 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
298 $mockTerObject
299 ->expects($this->any())
300 ->method('getVersion')
301 ->will($this->returnValue('1.0.6'));
302 $mockTerObject
303 ->expects($this->atLeastOnce())
304 ->method('getReviewState')
305 ->will($this->returnValue(0));
306 $mockExtensionList = array(
307 'enetcache' => array(
308 'terObject' => $mockTerObject
309 ),
310 );
311 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
312 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
313 $mockListUtility
314 ->expects($this->once())
315 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
316 ->will($this->returnValue($mockExtensionList));
317
318 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
319 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
320 $mockReport->_set('objectManager', $this->objectManager);
321 $mockReport->_set('listUtility', $mockListUtility);
322 $mockReport->_set('languageService', $this->mockLanguageService);
323
324 $result = $mockReport->_call('getSecurityStatusOfExtensions');
325 /** @var $existingResult \TYPO3\CMS\Reports\Status */
326 $existingResult = $result->existing;
327 $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $existingResult->getSeverity());
328 }
329
330 /**
331 * @test
332 */
333 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfInsecureExtensionExists() {
334 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
335 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
336 $mockTerObject
337 ->expects($this->any())
338 ->method('getVersion')
339 ->will($this->returnValue('1.0.6'));
340 $mockTerObject
341 ->expects($this->atLeastOnce())
342 ->method('getReviewState')
343 ->will($this->returnValue(-1));
344 $mockExtensionList = array(
345 'enetcache' => array(
346 'terObject' => $mockTerObject
347 ),
348 );
349 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
350 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
351 $mockListUtility
352 ->expects($this->once())
353 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
354 ->will($this->returnValue($mockExtensionList));
355
356 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
357 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
358 $mockReport->_set('objectManager', $this->objectManager);
359 $mockReport->_set('listUtility', $mockListUtility);
360 $mockReport->_set('languageService', $this->mockLanguageService);
361
362 $result = $mockReport->_call('getSecurityStatusOfExtensions');
363 /** @var $existingResult \TYPO3\CMS\Reports\Status */
364 $existingResult = $result->existing;
365 $this->assertSame(\TYPO3\CMS\Reports\Status::WARNING, $existingResult->getSeverity());
366 }
367
368 /**
369 * @test
370 */
371 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded() {
372 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
373 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
374 $mockTerObject
375 ->expects($this->any())
376 ->method('getVersion')
377 ->will($this->returnValue('1.0.6'));
378 $mockTerObject
379 ->expects($this->atLeastOnce())
380 ->method('getReviewState')
381 ->will($this->returnValue(0));
382 $mockExtensionList = array(
383 'enetcache' => array(
384 'installed' => TRUE,
385 'terObject' => $mockTerObject
386 ),
387 );
388 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
389 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
390 $mockListUtility
391 ->expects($this->once())
392 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
393 ->will($this->returnValue($mockExtensionList));
394
395 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
396 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
397 $mockReport->_set('objectManager', $this->objectManager);
398 $mockReport->_set('listUtility', $mockListUtility);
399 $mockReport->_set('languageService', $this->mockLanguageService);
400
401 $result = $mockReport->_call('getSecurityStatusOfExtensions');
402 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
403 $loadedResult = $result->loadedoutdated;
404 $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $loadedResult->getSeverity());
405 }
406
407 /**
408 * @test
409 */
410 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded() {
411 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
412 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
413 $mockTerObject
414 ->expects($this->any())
415 ->method('getVersion')
416 ->will($this->returnValue('1.0.6'));
417 $mockTerObject
418 ->expects($this->atLeastOnce())
419 ->method('getReviewState')
420 ->will($this->returnValue(-2));
421 $mockExtensionList = array(
422 'enetcache' => array(
423 'installed' => TRUE,
424 'terObject' => $mockTerObject
425 ),
426 );
427 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
428 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
429 $mockListUtility
430 ->expects($this->once())
431 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
432 ->will($this->returnValue($mockExtensionList));
433
434 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
435 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
436 $mockReport->_set('objectManager', $this->objectManager);
437 $mockReport->_set('listUtility', $mockListUtility);
438 $mockReport->_set('languageService', $this->mockLanguageService);
439
440 $result = $mockReport->_call('getSecurityStatusOfExtensions');
441 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
442 $loadedResult = $result->loadedoutdated;
443 $this->assertSame(\TYPO3\CMS\Reports\Status::WARNING, $loadedResult->getSeverity());
444 }
445
446 /**
447 * @test
448 */
449 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists() {
450 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
451 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
452 $mockTerObject
453 ->expects($this->any())
454 ->method('getVersion')
455 ->will($this->returnValue('1.0.6'));
456 $mockTerObject
457 ->expects($this->atLeastOnce())
458 ->method('getReviewState')
459 ->will($this->returnValue(0));
460 $mockExtensionList = array(
461 'enetcache' => array(
462 'terObject' => $mockTerObject
463 ),
464 );
465 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
466 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
467 $mockListUtility
468 ->expects($this->once())
469 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
470 ->will($this->returnValue($mockExtensionList));
471
472 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
473 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
474 $mockReport->_set('objectManager', $this->objectManager);
475 $mockReport->_set('listUtility', $mockListUtility);
476 $mockReport->_set('languageService', $this->mockLanguageService);
477
478 $result = $mockReport->_call('getSecurityStatusOfExtensions');
479 /** @var $existingResult \TYPO3\CMS\Reports\Status */
480 $existingResult = $result->existingoutdated;
481 $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $existingResult->getSeverity());
482 }
483
484 /**
485 * @test
486 */
487 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists() {
488 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
489 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
490 $mockTerObject
491 ->expects($this->any())
492 ->method('getVersion')
493 ->will($this->returnValue('1.0.6'));
494 $mockTerObject
495 ->expects($this->atLeastOnce())
496 ->method('getReviewState')
497 ->will($this->returnValue(-2));
498 $mockExtensionList = array(
499 'enetcache' => array(
500 'terObject' => $mockTerObject
501 ),
502 );
503 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
504 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
505 $mockListUtility
506 ->expects($this->once())
507 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
508 ->will($this->returnValue($mockExtensionList));
509
510 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
511 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
512 $mockReport->_set('objectManager', $this->objectManager);
513 $mockReport->_set('listUtility', $mockListUtility);
514 $mockReport->_set('languageService', $this->mockLanguageService);
515
516 $result = $mockReport->_call('getSecurityStatusOfExtensions');
517 /** @var $existingResult \TYPO3\CMS\Reports\Status */
518 $existingResult = $result->existingoutdated;
519 $this->assertSame(\TYPO3\CMS\Reports\Status::WARNING, $existingResult->getSeverity());
520 }
521 }