1
0
mirror of https://github.com/phpmyadmin/phpmyadmin.git synced 2026-10-28 07:41:55 +03:00
Files
phpmyadmin/tests/unit/UserPasswordTest.php
Kamil Tekiela 82c85d26c0 Clean up of tests (#19067)
* Fix wrong type hint

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use $this instead of parent

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* setUp should be a protected method

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* onNotSuccessfulTest should be protected

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* $command doesn't need to be a property

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Give alertText() proper return type

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use null-safe operator

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Call Message static constructors statically

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Call StorageEngine methods statically

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Add better type hints in PrivilegesController

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use packed (without keys) arrays in tests

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use type casts instead of function casts

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use const instead of private property

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use const instead of private property

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Fix testAuthFailsTooLongPass()

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Replace loop with array_shift

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use ob_get_clean

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove duplicated code

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use assert instead of phpdoc

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

---------

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2024-03-20 13:34:55 -03:00

84 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationCleanup;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins\AuthenticationPluginFactory;
use PhpMyAdmin\Server\Plugins;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\UserPassword;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use function str_repeat;
#[CoversClass(UserPassword::class)]
class UserPasswordTest extends AbstractTestCase
{
private UserPassword $object;
protected function setUp(): void
{
parent::setUp();
$dbi = $this->createDatabaseInterface();
$relation = new Relation($dbi);
$serverPrivileges = new Privileges(
new Template(),
$dbi,
$relation,
new RelationCleanup($dbi, $relation),
new Plugins($dbi),
);
$this->object = new UserPassword(
$serverPrivileges,
self::createStub(AuthenticationPluginFactory::class),
$dbi,
);
}
#[DataProvider('providerSetChangePasswordMsg')]
public function testSetChangePasswordMsg(
bool $error,
Message $message,
bool $noPassword,
string $password,
string $passwordConfirmation,
): void {
self::assertEquals(
['error' => $error, 'msg' => $message],
$this->object->setChangePasswordMsg(
$password,
$passwordConfirmation,
$noPassword,
),
);
}
/** @psalm-return array{0: bool, 1: Message, 2: bool, 3: string, 4: string}[] */
public static function providerSetChangePasswordMsg(): array
{
return [
[false, Message::success('The profile has been updated.'), true, '', ''],
[true, Message::error('The password is empty!'), false, '', ''],
[true, Message::error('The password is empty!'), false, 'a', ''],
[true, Message::error('The password is empty!'), false, '', 'a'],
[true, Message::error('The passwords aren\'t the same!'), false, 'a', 'b'],
[true, Message::error('Password is too long!'), false, str_repeat('a', 257), str_repeat('a', 257)],
[
false,
Message::success('The profile has been updated.'),
false,
str_repeat('a', 256),
str_repeat('a', 256),
],
];
}
}