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

PasswordFieldTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boolDataProvider() 0 6 1
A testAutocomplete() 0 8 2
A testValuePostback() 0 8 2
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