Merge pull request #19012 from MauricioFauth/unit-tests
Add some unit tests
This commit is contained in:
commit
c84191a568
@ -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>
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
32
tests/unit/SessionTest.php
Normal file
32
tests/unit/SessionTest.php
Normal 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 ']);
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ use ReflectionProperty;
|
||||
use const MYSQLI_TYPE_STRING;
|
||||
|
||||
#[CoversClass(SystemDatabase::class)]
|
||||
#[CoversClass(SystemColumn::class)]
|
||||
class SystemDatabaseTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
|
||||
48
tests/unit/UrlRedirectorTest.php
Normal file
48
tests/unit/UrlRedirectorTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@ -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[] */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user