summaryrefslogtreecommitdiff
path: root/tests/units/Validator/PasswordResetValidatorTest.php
blob: 4af6c75eb01e62d08c559f7e6fe34bfa3c629009 (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
64
<?php

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

use Kanboard\Model\User;
use Kanboard\Validator\PasswordResetValidator;

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

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

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

    public function testValidateCreation()
    {
        $this->container['sessionStorage']->captcha = 'test';

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

    public function testValidateCreationWithNoUsername()
    {
        $this->container['sessionStorage']->captcha = 'test';

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

    public function testValidateCreationWithWrongCaptcha()
    {
        $this->container['sessionStorage']->captcha = 'test123';

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

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