phpmyadmin/test/classes/Controllers/VersionCheckControllerTest.php
Maurício Meneghini Fauth acba6ed40f
Move VersionInformation to constructor in VersionCheckController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2022-03-31 17:58:37 -03:00

62 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers;
use PhpMyAdmin\Controllers\VersionCheckController;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\VersionInformation;
use function json_encode;
use function time;
use const PHP_VERSION_ID;
/**
* @covers \PhpMyAdmin\Controllers\VersionCheckController
*/
class VersionCheckControllerTest extends AbstractTestCase
{
public function testInvoke(): void
{
$_GET = [];
$GLOBALS['cfg']['VersionCheck'] = true;
$versionInfo = [
'date' => '2022-02-11',
'version' => '5.1.3',
'releases' => [
[
'date' => '2022-02-11',
'php_versions' => '>=7.1,<8.1',
'version' => '5.1.3',
'mysql_versions' => '>=5.5',
],
[
'date' => '2022-02-11',
'php_versions' => '>=5.5,<8.0',
'version' => '4.9.10',
'mysql_versions' => '>=5.5',
],
],
];
$_SESSION['cache'] = [];
$_SESSION['cache']['version_check'] = [
'response' => json_encode($versionInfo),
'timestamp' => time(),
];
(new VersionCheckController(new ResponseRenderer(), new Template(), new VersionInformation()))();
$output = $this->getActualOutputForAssertion();
$this->assertTrue(isset($_GET['ajax_request']));
if (PHP_VERSION_ID < 80100) {
$this->assertSame('{"version":"5.1.3","date":"2022-02-11"}', $output);
} else {
$this->assertSame('{"version":"","date":""}', $output);
}
}
}