summaryrefslogtreecommitdiff
path: root/tests/units/Validator/PasswordResetValidatorTest.php
blob: a2647d2d9883f544a810d1784f24cc9c7333f238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Validator\PasswordResetValidator;

class PasswordResetValidatorTest extends Base
{
    public function testValidateModification()
    {
        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
        $this->assertTrue($valid);
    }

    public function testValidateModificationWithWrongPasswords()
    {
        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test123', 'confirmation' => 'test456'));
        $this->assertFalse($valid);
    }

    public function testValidateModificationWithPasswordTooShort()
    {
        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
        $this->assertFalse($valid);
    }

    public function testValidateCreation()
    {
        $_SESSION['captcha'] = 'test';

        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
        $this->assertTrue($valid);
    }

    public function testValidateCreationWithNoUsername()
    {
        $_SESSION['captcha'] = 'test';

        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid,) = $passwordResetValidator->validateCreation(array('captcha' => 'test'));
        $this->assertFalse($valid);
    }

    public function testValidateCreationWithWrongCaptcha()
    {
        $_SESSION['captcha'] = 'test123';

        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
        $this->assertFalse($valid);
    }

    public function testValidateCreationWithMissingCaptcha()
    {
        $passwordResetValidator = new PasswordResetValidator($this->container);
        list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
        $this->assertFalse($valid);
    }
}