|
10 | 10 | use PhpMyAdmin\Tests\Stubs\ResponseRenderer; |
11 | 11 | use PhpMyAdmin\VersionInformation; |
12 | 12 |
|
13 | | -use function json_encode; |
14 | | -use function time; |
15 | | - |
16 | | -use const PHP_VERSION_ID; |
17 | | - |
18 | 13 | /** |
19 | 14 | * @covers \PhpMyAdmin\Controllers\VersionCheckController |
20 | 15 | */ |
21 | 16 | class VersionCheckControllerTest extends AbstractTestCase |
22 | 17 | { |
23 | | - public function testInvoke(): void |
| 18 | + public function testWithLatestCompatibleVersion(): void |
24 | 19 | { |
25 | 20 | $_GET = []; |
26 | | - $GLOBALS['cfg']['VersionCheck'] = true; |
27 | | - $versionInfo = [ |
| 21 | + $versionInfo = (object) [ |
28 | 22 | 'date' => '2022-02-11', |
29 | 23 | 'version' => '5.1.3', |
30 | 24 | 'releases' => [ |
31 | | - [ |
| 25 | + (object) [ |
32 | 26 | 'date' => '2022-02-11', |
33 | 27 | 'php_versions' => '>=7.1,<8.1', |
34 | 28 | 'version' => '5.1.3', |
35 | 29 | 'mysql_versions' => '>=5.5', |
36 | 30 | ], |
37 | | - [ |
| 31 | + (object) [ |
38 | 32 | 'date' => '2022-02-11', |
39 | 33 | 'php_versions' => '>=5.5,<8.0', |
40 | 34 | 'version' => '4.9.10', |
41 | 35 | 'mysql_versions' => '>=5.5', |
42 | 36 | ], |
43 | 37 | ], |
44 | 38 | ]; |
45 | | - $_SESSION['cache'] = []; |
46 | | - $_SESSION['cache']['version_check'] = [ |
47 | | - 'response' => json_encode($versionInfo), |
48 | | - 'timestamp' => time(), |
| 39 | + |
| 40 | + $versionInformation = $this->createMock(VersionInformation::class); |
| 41 | + $versionInformation->expects($this->once())->method('getLatestVersion')->willReturn($versionInfo); |
| 42 | + $versionInformation->expects($this->once())->method('getLatestCompatibleVersion') |
| 43 | + ->with($this->equalTo($versionInfo->releases)) |
| 44 | + ->willReturn(['version' => '5.1.3', 'date' => '2022-02-11']); |
| 45 | + |
| 46 | + (new VersionCheckController(new ResponseRenderer(), new Template(), $versionInformation))(); |
| 47 | + |
| 48 | + $output = $this->getActualOutputForAssertion(); |
| 49 | + $this->assertTrue(isset($_GET['ajax_request'])); |
| 50 | + $this->assertSame('{"version":"5.1.3","date":"2022-02-11"}', $output); |
| 51 | + } |
| 52 | + |
| 53 | + public function testWithoutLatestCompatibleVersion(): void |
| 54 | + { |
| 55 | + $_GET = []; |
| 56 | + $versionInfo = (object) [ |
| 57 | + 'date' => '2022-02-11', |
| 58 | + 'version' => '5.1.3', |
| 59 | + 'releases' => [ |
| 60 | + (object) [ |
| 61 | + 'date' => '2022-02-11', |
| 62 | + 'php_versions' => '>=7.1,<8.1', |
| 63 | + 'version' => '5.1.3', |
| 64 | + 'mysql_versions' => '>=5.5', |
| 65 | + ], |
| 66 | + (object) [ |
| 67 | + 'date' => '2022-02-11', |
| 68 | + 'php_versions' => '>=5.5,<8.0', |
| 69 | + 'version' => '4.9.10', |
| 70 | + 'mysql_versions' => '>=5.5', |
| 71 | + ], |
| 72 | + ], |
49 | 73 | ]; |
50 | 74 |
|
51 | | - (new VersionCheckController(new ResponseRenderer(), new Template(), new VersionInformation()))(); |
| 75 | + $versionInformation = $this->createMock(VersionInformation::class); |
| 76 | + $versionInformation->expects($this->once())->method('getLatestVersion')->willReturn($versionInfo); |
| 77 | + $versionInformation->expects($this->once())->method('getLatestCompatibleVersion') |
| 78 | + ->with($this->equalTo($versionInfo->releases)) |
| 79 | + ->willReturn(null); |
| 80 | + |
| 81 | + (new VersionCheckController(new ResponseRenderer(), new Template(), $versionInformation))(); |
| 82 | + |
| 83 | + $output = $this->getActualOutputForAssertion(); |
| 84 | + $this->assertTrue(isset($_GET['ajax_request'])); |
| 85 | + $this->assertSame('{"version":"","date":""}', $output); |
| 86 | + } |
| 87 | + |
| 88 | + public function testWithoutLatestVersion(): void |
| 89 | + { |
| 90 | + $_GET = []; |
| 91 | + |
| 92 | + $versionInformation = $this->createMock(VersionInformation::class); |
| 93 | + $versionInformation->expects($this->once())->method('getLatestVersion')->willReturn(null); |
| 94 | + $versionInformation->expects($this->never())->method('getLatestCompatibleVersion'); |
| 95 | + |
| 96 | + (new VersionCheckController(new ResponseRenderer(), new Template(), $versionInformation))(); |
52 | 97 |
|
53 | 98 | $output = $this->getActualOutputForAssertion(); |
54 | 99 | $this->assertTrue(isset($_GET['ajax_request'])); |
55 | | - if (PHP_VERSION_ID < 80100) { |
56 | | - $this->assertSame('{"version":"5.1.3","date":"2022-02-11"}', $output); |
57 | | - } else { |
58 | | - $this->assertSame('{"version":"","date":""}', $output); |
59 | | - } |
| 100 | + $this->assertSame('[]', $output); |
60 | 101 | } |
61 | 102 | } |
0 commit comments