Passed
Push — 4.0.4 ( fe4f6f )
by Robbie
09:31
created

PasswordFieldTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boolDataProvider() 0 5 1
A testValuePostback() 0 8 2
A testAutocomplete() 0 8 2
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\PasswordField;
8
9
class PasswordFieldTest extends SapphireTest
10
{
11
    public function boolDataProvider()
12
    {
13
        return [
14
            [false],
15
            [true]
16
        ];
17
    }
18
19
    /**
20
     * @dataProvider boolDataProvider
21
     * @param bool $bool
22
     */
23
    public function testAutocomplete($bool)
24
    {
25
        Config::modify()->set(PasswordField::class, 'autocomplete', $bool);
26
        $field = new PasswordField('test');
27
        $attrs = $field->getAttributes();
28
29
        $this->assertArrayHasKey('autocomplete', $attrs);
30
        $this->assertEquals($bool ? 'on' : 'off', $attrs['autocomplete']);
31
    }
32
33
    /**
34
     * @dataProvider boolDataProvider
35
     * @param bool $bool
36
     */
37
    public function testValuePostback($bool)
38
    {
39
        $field = (new PasswordField('test', 'test', 'password'))
40
            ->setAllowValuePostback($bool);
41
        $attrs = $field->getAttributes();
42
43
        $this->assertArrayHasKey('value', $attrs);
44
        $this->assertEquals($bool ? 'password' : '', $attrs['value']);
45
    }
46
}
47