Completed
Push — 3 ( 4a9e99...f688bc )
by Robbie
11:41
created

PasswordFieldTest::testValuePostback()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
class PasswordFieldTest extends SapphireTest
5
{
6
    public function boolDataProvider() {
7
        return array(
8
            array(false),
9
            array(true)
10
        );
11
    }
12
13
    /**
14
     * @dataProvider boolDataProvider
15
     * @param bool $bool
16
     */
17
    public function testAutocomplete($bool) {
18
        Config::inst()->update('PasswordField', 'autocomplete', $bool);
19
        $field = new PasswordField('test');
20
        $attrs = $field->getAttributes();
21
22
        $this->assertArrayHasKey('autocomplete', $attrs);
23
        $this->assertEquals($bool ? 'on' : 'off', $attrs['autocomplete']);
24
    }
25
26
    /**
27
     * @dataProvider boolDataProvider
28
     * @param bool $bool
29
     */
30
    public function testValuePostback($bool) {        
31
        $field = PasswordField::create('test', 'test', 'password')
32
        	->setAllowValuePostback($bool);
33
        $attrs = $field->getAttributes();
34
35
        $this->assertArrayHasKey('value', $attrs);
36
        $this->assertEquals($bool ? 'password' : '', $attrs['value']);
37
    }
38
}
39