testKnockoutConfirmedPasswordField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 61
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 45
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 61
rs 9.2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace AntonyThorpe\Knockout\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use AntonyThorpe\Knockout\KnockoutConfirmedPasswordField;
7
8
/**
9
 * KnockoutConfirmedPasswordFieldTest
10
 */
11
class KnockoutConfirmedPasswordFieldTest extends SapphireTest
12
{
13
    public function testKnockoutConfirmedPasswordField()
14
    {
15
        $field = KnockoutConfirmedPasswordField::create("MyField", "My Field");
16
        $fields = $field->children;
17
        $password_field = $fields->fieldByName('MyField[_Password]');
18
        $password_confirmed_field = $fields->fieldByName('MyField[_ConfirmPassword]');
19
20
        $this->assertNotNull(
21
            $password_field,
22
            "password field is not null"
23
        );
24
        $this->assertNotNull(
25
            $password_confirmed_field,
26
            "password confirmed field is not null"
27
        );
28
        $this->assertEquals(
29
            "password",
30
            $password_field->getObservable(),
31
            "observable is set to password by default in the Password field"
32
        );
33
        $this->assertEquals(
34
            "confirmedPassword",
35
            $password_confirmed_field->getObservable(),
36
            "observable is set to confirmedPassword by default in the Confirmed Password field"
37
        );
38
        $this->assertEquals(
39
            ['password', 'confirmedPassword'],
40
            $field->getObservables(),
41
            "The function getObservables returns an array of the observables set on the child fields"
42
        );
43
        $this->assertStringContainsString(
44
            '<input data-bind="textInput: confirmedPassword" type="password"',
45
            $field->Field()
46
        );
47
48
49
        $field2 = KnockoutConfirmedPasswordField::create("MyField2", "My Field2")
50
            ->setObservables(['password2', 'confirmedPassword2']);
51
        $fields2 = $field2->children;
52
53
        $password_field2 = $fields2->fieldByName('MyField2[_Password]');
54
        $password_confirmed_field2 = $fields2->fieldByName('MyField2[_ConfirmPassword]');
55
56
        $this->assertEquals(
57
            "password2",
58
            $password_field2->getObservable(),
59
            "observable is set to password2 through the setObservables method"
60
        );
61
        $this->assertEquals(
62
            "confirmedPassword2",
63
            $password_confirmed_field2->getObservable(),
64
            "observable is set to confirmedPassword2 through the setObservables method"
65
        );
66
        $this->assertEquals(
67
            ['password2', 'confirmedPassword2'],
68
            $field2->getObservables(),
69
            "The function getObservables returns an array of the observables set on the child fields"
70
        );
71
        $this->assertStringContainsString(
72
            '<input data-bind="textInput: confirmedPassword2"',
73
            $field2->Field()
74
        );
75
    }
76
}
77