Merge pull request #19012 from MauricioFauth/unit-tests

Add some unit tests
This commit is contained in:
Maurício Meneghini Fauth 2024-02-26 11:37:27 -03:00 committed by GitHub
commit c84191a568
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 89 additions and 0 deletions

View File

@ -14972,6 +14972,11 @@
<code><![CDATA[providerGetUniqueConditionForGroupFlag]]></code>
</PossiblyUnusedMethod>
</file>
<file src="tests/unit/UrlRedirectorTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
</file>
<file src="tests/unit/UrlTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>

View File

@ -42,6 +42,8 @@ use const MYSQLI_TYPE_TIMESTAMP;
use const MYSQLI_TYPE_TINY;
#[CoversClass(InsertEdit::class)]
#[CoversClass(EditField::class)]
#[CoversClass(InsertEditColumn::class)]
#[Group('medium')]
class InsertEditTest extends AbstractTestCase
{

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Session;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
#[CoversClass(Session::class)]
final class SessionTest extends TestCase
{
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testSecure(): void
{
$_SESSION[' PMA_token '] = null;
$_SESSION[' HMAC_secret '] = null;
Session::secure();
/** @psalm-suppress TypeDoesNotContainType */
self::assertIsString($_SESSION[' PMA_token ']);
self::assertNotEmpty($_SESSION[' PMA_token ']);
/** @psalm-suppress TypeDoesNotContainType */
self::assertIsString($_SESSION[' HMAC_secret ']);
self::assertNotEmpty($_SESSION[' HMAC_secret ']);
}
}

View File

@ -17,6 +17,7 @@ use ReflectionProperty;
use const MYSQLI_TYPE_STRING;
#[CoversClass(SystemDatabase::class)]
#[CoversClass(SystemColumn::class)]
class SystemDatabaseTest extends AbstractTestCase
{
/**

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\UrlRedirector;
use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionProperty;
#[CoversClass(UrlRedirector::class)]
final class UrlRedirectorTest extends AbstractTestCase
{
public function testRedirectWithDisallowedUrl(): void
{
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
$GLOBALS['lang'] = 'en';
$config = Config::getInstance();
$config->settings['PmaAbsoluteUri'] = 'http://localhost/phpmyadmin';
$response = UrlRedirector::redirect('https://user:pass@example.com/');
self::assertSame('/phpmyadmin/', $response->getHeaderLine('Location'));
self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
}
public function testRedirectWithAllowedUrl(): void
{
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
$GLOBALS['lang'] = 'en';
$_SERVER['SERVER_NAME'] = 'localhost';
UrlRedirector::redirect('https://phpmyadmin.net/');
$output = self::getActualOutputForAssertion();
$expected = <<<'HTML'
<script>
window.onload = function () {
window.location = 'https\u003A\/\/phpmyadmin.net\/';
};
</script>
Taking you to the target site.
HTML;
self::assertSame($expected, $output);
}
}

View File

@ -12,6 +12,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
#[CoversClass(VersionInformation::class)]
#[CoversClass(Release::class)]
class VersionInformationTest extends AbstractTestCase
{
/** @var Release[] */