Completed
Push — master ( 305cf3...b2101c )
by Robbie
22s queued 10s
created

EditableNumericFieldTest::testValidate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\UserForms\Model\EditableFormField\EditableNumericField;
7
8
class EditableNumericFieldTest extends SapphireTest
9
{
10
    public function testAllowEmptyTitle()
11
    {
12
        /** @var EditableNumericField $field */
13
        $field = EditableNumericField::create();
14
        $field->Name = 'EditableFormField_123456';
15
        $this->assertEmpty($field->getFormField()->Title());
16
    }
17
18
    public function testValidateAddsErrorWhenMinValueIsGreaterThanMaxValue()
19
    {
20
        /** @var EditableNumericField $field */
21
        $field = EditableNumericField::create();
22
        $field->MinValue = 10;
0 ignored issues
show
Bug Best Practice introduced by
The property MinValue does not exist on SilverStripe\UserForms\M...ld\EditableNumericField. Since you implemented __set, consider adding a @property annotation.
Loading history...
23
        $field->MaxValue = 5;
0 ignored issues
show
Bug Best Practice introduced by
The property MaxValue does not exist on SilverStripe\UserForms\M...ld\EditableNumericField. Since you implemented __set, consider adding a @property annotation.
Loading history...
24
25
        $result = $field->validate();
26
        $this->assertFalse($result->isValid(), 'Validation should fail when min is greater than max');
27
        $this->assertContains('Minimum length should be less than the maximum length', $result->serialize());
28
    }
29
30
    public function testValidate()
31
    {
32
        /** @var EditableNumericField $field */
33
        $field = EditableNumericField::create();
34
        $field->MinValue = 5;
0 ignored issues
show
Bug Best Practice introduced by
The property MinValue does not exist on SilverStripe\UserForms\M...ld\EditableNumericField. Since you implemented __set, consider adding a @property annotation.
Loading history...
35
        $field->MaxValue = 10;
0 ignored issues
show
Bug Best Practice introduced by
The property MaxValue does not exist on SilverStripe\UserForms\M...ld\EditableNumericField. Since you implemented __set, consider adding a @property annotation.
Loading history...
36
37
        $result = $field->validate();
38
        $this->assertTrue($result->isValid());
39
    }
40
}
41