[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Status / StatusUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\Status;
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 use TYPO3\CMS\Install\Status\Exception;
18 use TYPO3\CMS\Install\Status\StatusUtility;
19
20 /**
21 * Test case
22 */
23 class StatusUtilityTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function sortBySeveritySortsGivenStatusObjects()
29 {
30 $errorMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\ErrorStatus::class)
31 ->setMethods(['dummy'])
32 ->getMock();
33 $warningMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\WarningStatus::class)
34 ->setMethods(['dummy'])
35 ->getMock();
36 $okMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\OkStatus::class)
37 ->setMethods(['dummy'])
38 ->getMock();
39 $infoMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\InfoStatus::class)
40 ->setMethods(['dummy'])
41 ->getMock();
42 $noticeMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\NoticeStatus::class)
43 ->setMethods(['dummy'])
44 ->getMock();
45 $statusUtility = new StatusUtility();
46 $return = $statusUtility->sortBySeverity([$noticeMock, $infoMock, $okMock, $warningMock, $errorMock]);
47 $this->assertSame([$errorMock], $return['error']);
48 $this->assertSame([$warningMock], $return['warning']);
49 $this->assertSame([$okMock], $return['ok']);
50 $this->assertSame([$infoMock], $return['information']);
51 $this->assertSame([$noticeMock], $return['notice']);
52 }
53
54 /**
55 * @test
56 */
57 public function filterBySeverityThrowsExceptionIfObjectNotImplementingStatusInterfaceIsGiven()
58 {
59 $this->expectException(Exception::class);
60 $this->expectExceptionCode(1366919442);
61 $statusUtility = new StatusUtility();
62 $statusUtility->filterBySeverity([new \stdClass()]);
63 }
64
65 /**
66 * @test
67 */
68 public function filterBySeverityReturnsSpecificSeverityOnly()
69 {
70 $errorMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\ErrorStatus::class)
71 ->setMethods(['dummy'])
72 ->getMock();
73 $warningMock = $this->getMockBuilder(\TYPO3\CMS\Install\Status\WarningStatus::class)
74 ->setMethods(['dummy'])
75 ->getMock();
76 $statusUtility = new StatusUtility();
77 $return = $statusUtility->filterBySeverity([$errorMock, $warningMock], 'error');
78 $this->assertSame([$errorMock], $return);
79 }
80 }