summaryrefslogtreecommitdiff
path: root/tests/acceptance/UserAuthenticationTest.php
blob: 3313e05060330c1ad434e5b42bc7cc9145b14ec1 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

require_once __DIR__.'/Base.php';

class UserAuthenticationTest extends Base
{

    public function validLoginInputsProvider()
    {
        $inputs[] = [
            [
                'username' => 'admin',
                'password' => 'admin',
            ]
        ];

        return $inputs;
    }

    public function invalidLoginInputsProvider()
    {
        $inputs[] = [
            [
                'username' => 'wrong_username',
                'password' => 'wrong_password',
            ]
        ];

        return $inputs;
    }

    /**
     * @dataProvider validLoginInputsProvider
     */
    public function testValidLogin(array $inputs)
    {
        $this->url('/');
        $this->assertContains('Login', $this->title());

        $form = $this->byTag('form');
        foreach ($inputs as $input => $value) {
            $form->byName($input)->value($value);
        }
        $form->submit();

        $content = $this->byClassName('sidebar')->text();
        $this->assertContains($inputs['username'], $content);
    }

    /**
     * @dataProvider invalidLoginInputsProvider
     */
    public function testInvalidLogin(array $inputs)
    {
        $this->url('/');

        // Test wrong username with correct password
        $form = $this->byTag('form');
        $form->byName('username')->value($inputs['username']);
        $form->byName('password')->value('admin');
        $form->submit();

        $content = $this->byTag('body')->text();
        $this->assertContains('Bad username or password', $content);

        // Test wrong password with correct username
        $form = $this->byTag('form');
        $form->byName('username')->value('admin');
        $form->byName('password')->value($inputs['password']);
        $form->submit();

        $content = $this->byTag('body')->text();
        $this->assertContains('Bad username or password', $content);

        // Test wrong username and password
        $form = $this->byTag('form');
        $form->byName('username')->value($inputs['username']);
        $form->byName('password')->value($inputs['password']);
        $form->submit();

        $content = $this->byTag('body')->text();
        $this->assertContains('Bad username or password', $content);


    }
}