0c5690382d8503487d5b96396603655331950edd
[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\Core\Tests\UnitTestCase {
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->getMock('TYPO3\\CMS\\Reports\\Status', array(), array('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->mockObjectManager);
152 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
153 $this->mockObjectManager
154 ->expects($this->once())
155 ->method('get')
156 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
157 ->will($this->returnValue($statusMock));
158 $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
159 $mockReport->_set('languageService', $this->mockLanguageService);
160
161 $result = $mockReport->_call('getMainRepositoryStatus');
162 $this->assertSame($statusMock, $result);
163 }
164
165 /**
166 * @test
167 */
168 public function getMainRepositoryStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo() {
169 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository|\PHPUnit_Framework_MockObject_MockObject */
170 $mockRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository');
171 $mockRepository
172 ->expects($this->once())
173 ->method('getLastUpdate')
174 ->will($this->returnValue(new \DateTime('-8 days')));
175
176 $this->mockRepositoryRepository
177 ->expects($this->once())
178 ->method('findOneTypo3OrgRepository')
179 ->will($this->returnValue($mockRepository));
180
181 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
182 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
183 $mockReport->_set('objectManager', $this->mockObjectManager);
184 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
185 $this->mockObjectManager
186 ->expects($this->once())
187 ->method('get')
188 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::NOTICE)
189 ->will($this->returnValue($statusMock));
190 $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
191 $mockReport->_set('languageService', $this->mockLanguageService);
192
193 /** @var $result \TYPO3\CMS\Reports\Status */
194 $result = $mockReport->_call('getMainRepositoryStatus');
195 $this->assertSame($statusMock, $result);
196 }
197
198 /**
199 * @test
200 */
201 public function getMainRepositoryStatusReturnsOkIfUpdatedLessThanSevenDaysAgo() {
202 /** @var $mockRepositoryRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository|\PHPUnit_Framework_MockObject_MockObject */
203 $mockRepository = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository');
204 $mockRepository
205 ->expects($this->once())
206 ->method('getLastUpdate')
207 ->will($this->returnValue(new \DateTime('-6 days')));
208
209 $this->mockRepositoryRepository
210 ->expects($this->once())
211 ->method('findOneTypo3OrgRepository')
212 ->will($this->returnValue($mockRepository));
213
214 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
215 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
216 $mockReport->_set('objectManager', $this->mockObjectManager);
217 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
218 $this->mockObjectManager
219 ->expects($this->once())
220 ->method('get')
221 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
222 ->will($this->returnValue($statusMock));
223 $mockReport->_set('repositoryRepository', $this->mockRepositoryRepository);
224 $mockReport->_set('languageService', $this->mockLanguageService);
225
226 /** @var $result \TYPO3\CMS\Reports\Status */
227 $result = $mockReport->_call('getMainRepositoryStatus');
228 $this->assertSame($statusMock, $result);
229 }
230
231 /**
232 * @test
233 */
234 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded() {
235 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
236 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
237 $mockTerObject
238 ->expects($this->any())
239 ->method('getVersion')
240 ->will($this->returnValue('1.0.6'));
241 $mockTerObject
242 ->expects($this->atLeastOnce())
243 ->method('getReviewState')
244 ->will($this->returnValue(0));
245 $mockExtensionList = array(
246 'enetcache' => array(
247 'installed' => TRUE,
248 'terObject' => $mockTerObject
249 ),
250 );
251 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
252 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
253 $mockListUtility
254 ->expects($this->once())
255 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
256 ->will($this->returnValue($mockExtensionList));
257
258 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
259 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
260 $mockReport->_set('objectManager', $this->mockObjectManager);
261 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
262 $this->mockObjectManager
263 ->expects($this->at(0))
264 ->method('get')
265 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
266 ->will($this->returnValue($statusMock));
267 $mockReport->_set('listUtility', $mockListUtility);
268 $mockReport->_set('languageService', $this->mockLanguageService);
269
270 $result = $mockReport->_call('getSecurityStatusOfExtensions');
271 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
272 $loadedResult = $result->loaded;
273 $this->assertSame($statusMock, $loadedResult);
274 }
275
276 /**
277 * @test
278 */
279 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded() {
280 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
281 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
282 $mockTerObject
283 ->expects($this->any())
284 ->method('getVersion')
285 ->will($this->returnValue('1.0.6'));
286 $mockTerObject
287 ->expects($this->atLeastOnce())
288 ->method('getReviewState')
289 ->will($this->returnValue(-1));
290 $mockExtensionList = array(
291 'enetcache' => array(
292 'installed' => TRUE,
293 'terObject' => $mockTerObject
294 ),
295 );
296 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
297 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
298 $mockListUtility
299 ->expects($this->once())
300 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
301 ->will($this->returnValue($mockExtensionList));
302
303 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
304 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
305 $mockReport->_set('objectManager', $this->mockObjectManager);
306 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
307 $this->mockObjectManager
308 ->expects($this->at(0))
309 ->method('get')
310 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::ERROR)
311 ->will($this->returnValue($statusMock));
312 $mockReport->_set('listUtility', $mockListUtility);
313 $mockReport->_set('languageService', $this->mockLanguageService);
314
315 $result = $mockReport->_call('getSecurityStatusOfExtensions');
316 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
317 $loadedResult = $result->loaded;
318 $this->assertSame($statusMock, $loadedResult);
319 }
320
321 /**
322 * @test
323 */
324 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoInsecureExtensionExists() {
325 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
326 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
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');
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', array('dummy'), array(), '', FALSE);
349 $mockReport->_set('objectManager', $this->mockObjectManager);
350 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', 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 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
370 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
371 $mockTerObject
372 ->expects($this->any())
373 ->method('getVersion')
374 ->will($this->returnValue('1.0.6'));
375 $mockTerObject
376 ->expects($this->atLeastOnce())
377 ->method('getReviewState')
378 ->will($this->returnValue(-1));
379 $mockExtensionList = array(
380 'enetcache' => array(
381 'terObject' => $mockTerObject
382 ),
383 );
384 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
385 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
386 $mockListUtility
387 ->expects($this->once())
388 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
389 ->will($this->returnValue($mockExtensionList));
390
391 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
392 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
393 $mockReport->_set('objectManager', $this->mockObjectManager);
394 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
395 $this->mockObjectManager
396 ->expects($this->at(1))
397 ->method('get')
398 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
399 ->will($this->returnValue($statusMock));
400 $mockReport->_set('listUtility', $mockListUtility);
401 $mockReport->_set('languageService', $this->mockLanguageService);
402
403 $result = $mockReport->_call('getSecurityStatusOfExtensions');
404 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
405 $loadedResult = $result->existing;
406 $this->assertSame($statusMock, $loadedResult);
407 }
408
409 /**
410 * @test
411 */
412 public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded() {
413 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
414 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
415 $mockTerObject
416 ->expects($this->any())
417 ->method('getVersion')
418 ->will($this->returnValue('1.0.6'));
419 $mockTerObject
420 ->expects($this->atLeastOnce())
421 ->method('getReviewState')
422 ->will($this->returnValue(0));
423 $mockExtensionList = array(
424 'enetcache' => array(
425 'installed' => TRUE,
426 'terObject' => $mockTerObject
427 ),
428 );
429 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
430 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
431 $mockListUtility
432 ->expects($this->once())
433 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
434 ->will($this->returnValue($mockExtensionList));
435
436 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
437 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
438 $mockReport->_set('objectManager', $this->mockObjectManager);
439 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
440 $this->mockObjectManager
441 ->expects($this->at(2))
442 ->method('get')
443 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
444 ->will($this->returnValue($statusMock));
445 $mockReport->_set('listUtility', $mockListUtility);
446 $mockReport->_set('languageService', $this->mockLanguageService);
447
448 $result = $mockReport->_call('getSecurityStatusOfExtensions');
449 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
450 $loadedResult = $result->loadedoutdated;
451 $this->assertSame($statusMock, $loadedResult);
452 }
453
454 /**
455 * @test
456 */
457 public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded() {
458 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
459 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
460 $mockTerObject
461 ->expects($this->any())
462 ->method('getVersion')
463 ->will($this->returnValue('1.0.6'));
464 $mockTerObject
465 ->expects($this->atLeastOnce())
466 ->method('getReviewState')
467 ->will($this->returnValue(-2));
468 $mockExtensionList = array(
469 'enetcache' => array(
470 'installed' => TRUE,
471 'terObject' => $mockTerObject
472 ),
473 );
474 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
475 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
476 $mockListUtility
477 ->expects($this->once())
478 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
479 ->will($this->returnValue($mockExtensionList));
480
481 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
482 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
483 $mockReport->_set('objectManager', $this->mockObjectManager);
484 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
485 $this->mockObjectManager
486 ->expects($this->at(2))
487 ->method('get')
488 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
489 ->will($this->returnValue($statusMock));
490 $mockReport->_set('listUtility', $mockListUtility);
491 $mockReport->_set('languageService', $this->mockLanguageService);
492
493 $result = $mockReport->_call('getSecurityStatusOfExtensions');
494 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
495 $loadedResult = $result->loadedoutdated;
496 $this->assertSame($statusMock, $loadedResult);
497 }
498
499 /**
500 * @test
501 */
502 public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists() {
503 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
504 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
505 $mockTerObject
506 ->expects($this->any())
507 ->method('getVersion')
508 ->will($this->returnValue('1.0.6'));
509 $mockTerObject
510 ->expects($this->atLeastOnce())
511 ->method('getReviewState')
512 ->will($this->returnValue(0));
513 $mockExtensionList = array(
514 'enetcache' => array(
515 'terObject' => $mockTerObject
516 ),
517 );
518 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
519 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
520 $mockListUtility
521 ->expects($this->once())
522 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
523 ->will($this->returnValue($mockExtensionList));
524
525 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
526 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
527 $mockReport->_set('objectManager', $this->mockObjectManager);
528 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
529 $this->mockObjectManager
530 ->expects($this->at(3))
531 ->method('get')
532 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::OK)
533 ->will($this->returnValue($statusMock));
534 $mockReport->_set('listUtility', $mockListUtility);
535 $mockReport->_set('languageService', $this->mockLanguageService);
536
537 $result = $mockReport->_call('getSecurityStatusOfExtensions');
538 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
539 $loadedResult = $result->existingoutdated;
540 $this->assertSame($statusMock, $loadedResult);
541 }
542
543 /**
544 * @test
545 */
546 public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists() {
547 /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
548 $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
549 $mockTerObject
550 ->expects($this->any())
551 ->method('getVersion')
552 ->will($this->returnValue('1.0.6'));
553 $mockTerObject
554 ->expects($this->atLeastOnce())
555 ->method('getReviewState')
556 ->will($this->returnValue(-2));
557 $mockExtensionList = array(
558 'enetcache' => array(
559 'terObject' => $mockTerObject
560 ),
561 );
562 /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
563 $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
564 $mockListUtility
565 ->expects($this->once())
566 ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
567 ->will($this->returnValue($mockExtensionList));
568
569 /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
570 $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE);
571 $mockReport->_set('objectManager', $this->mockObjectManager);
572 $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE);
573 $this->mockObjectManager
574 ->expects($this->at(3))
575 ->method('get')
576 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)
577 ->will($this->returnValue($statusMock));
578 $mockReport->_set('listUtility', $mockListUtility);
579 $mockReport->_set('languageService', $this->mockLanguageService);
580
581 $result = $mockReport->_call('getSecurityStatusOfExtensions');
582 /** @var $loadedResult \TYPO3\CMS\Reports\Status */
583 $loadedResult = $result->existingoutdated;
584 $this->assertSame($statusMock, $loadedResult);
585 }
586 }