Passed
Push — master ( e6982c...abc21e )
by Maurício
10:04
created

UserPasswordTest::testSetChangePasswordMsg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests;
6
7
use PhpMyAdmin\Message;
8
use PhpMyAdmin\Relation;
9
use PhpMyAdmin\RelationCleanup;
10
use PhpMyAdmin\Server\Plugins;
11
use PhpMyAdmin\Server\Privileges;
12
use PhpMyAdmin\Template;
13
use PhpMyAdmin\UserPassword;
14
15
use function str_repeat;
16
17
/**
18
 * @covers \PhpMyAdmin\UserPassword
19
 */
20
class UserPasswordTest extends AbstractTestCase
21
{
22
    /** @var UserPassword */
23
    private $object;
24
25
    protected function setUp(): void
26
    {
27
        parent::setUp();
28
29
        $relation = new Relation($GLOBALS['dbi']);
30
        $serverPrivileges = new Privileges(
31
            new Template(),
32
            $GLOBALS['dbi'],
33
            $relation,
34
            new RelationCleanup($GLOBALS['dbi'], $relation),
35
            new Plugins($GLOBALS['dbi'])
36
        );
37
        $this->object = new UserPassword($serverPrivileges);
38
    }
39
40
    /**
41
     * @dataProvider providerSetChangePasswordMsg
42
     */
43
    public function testSetChangePasswordMsg(
44
        bool $error,
45
        Message $message,
46
        string $noPassword,
47
        string $password,
48
        string $passwordConfirmation
49
    ): void {
50
        $_POST['nopass'] = $noPassword;
51
        $_POST['pma_pw'] = $password;
52
        $_POST['pma_pw2'] = $passwordConfirmation;
53
        $this->assertEquals(['error' => $error, 'msg' => $message], $this->object->setChangePasswordMsg());
54
    }
55
56
    /**
57
     * @psalm-return array{0: bool, 1: Message, 2: string, 3: string, 4: string}[]
58
     */
59
    public function providerSetChangePasswordMsg(): array
60
    {
61
        return [
62
            [false, Message::success('The profile has been updated.'), '1', '', ''],
63
            [true, Message::error('The password is empty!'), '0', '', ''],
64
            [true, Message::error('The password is empty!'), '0', 'a', ''],
65
            [true, Message::error('The password is empty!'), '0', '', 'a'],
66
            [true, Message::error('The passwords aren\'t the same!'), '0', 'a', 'b'],
67
            [true, Message::error('Password is too long!'), '0', str_repeat('a', 257), str_repeat('a', 257)],
68
            [
69
                false,
70
                Message::success('The profile has been updated.'),
71
                '0',
72
                str_repeat('a', 256),
73
                str_repeat('a', 256),
74
            ],
75
        ];
76
    }
77
}
78