Passed
Push — 4 ( e6ea10...17f4cc )
by Garion
08:03 queued 10s
created

TextFieldTest::testTipIsIncludedInSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\Forms\TextField;
7
use SilverStripe\Forms\RequiredFields;
8
use SilverStripe\Forms\Tip;
9
10
class TextFieldTest extends SapphireTest
11
{
12
13
    /**
14
     * Tests the TextField Max Length Validation Failure
15
     */
16
    public function testMaxLengthValidationFail()
17
    {
18
        $textField = new TextField('TestField');
19
        $textField->setMaxLength(5);
20
        $textField->setValue("John Doe"); // 8 characters, so should fail
21
        $result = $textField->validate(new RequiredFields());
22
        $this->assertFalse($result);
23
    }
24
25
    /**
26
     * Tests the TextField Max Length Validation Success
27
     */
28
    public function testMaxLengthValidationSuccess()
29
    {
30
        $textField = new TextField('TestField');
31
        $textField->setMaxLength(5);
32
        $textField->setValue("John"); // 4 characters, so should pass
33
        $result = $textField->validate(new RequiredFields());
34
        $this->assertTrue($result);
35
    }
36
37
    /**
38
     * Ensures that when a Tip is applied to the field, it outputs it in the schema
39
     */
40
    public function testTipIsIncludedInSchema()
41
    {
42
        $textField = new TextField('TestField');
43
        $this->assertArrayNotHasKey('tip', $textField->getSchemaDataDefaults());
44
45
        $textField->setTip(new Tip('TestTip'));
46
        $this->assertArrayHasKey('tip', $textField->getSchemaDataDefaults());
47
    }
48
}
49