Completed
Push — 3.5 ( 1a9180...1bec8a )
by Daniel
24s
created

GroupedDropdownFieldTest::testRendering()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @package framework
5
 * @subpackage tests
6
 */
7
class GroupedDropdownFieldTest extends SapphireTest {
8
9
	public function testValidation() {
10
		$field = GroupedDropdownField::create('Test', 'Testing', array(
11
			"1" => "One",
12
			"Group One" => array(
13
				"2" => "Two",
14
				"3" => "Three"
15
			),
16
			"Group Two" => array(
17
				"4" => "Four"
18
			)
19
		));
20
21
		$validator = new RequiredFields();
22
23
		$field->setValue("1");
24
		$this->assertTrue($field->validate($validator));
25
26
		//test grouped values
27
		$field->setValue("3");
28
		$this->assertTrue($field->validate($validator));
29
30
		//non-existent value should make the field invalid
31
		$field->setValue("Over 9000");
32
		$this->assertFalse($field->validate($validator));
33
34
		//empty string shouldn't validate
35
		$field->setValue('');
36
		$this->assertFalse($field->validate($validator));
37
38
		//empty field should validate after being set
39
		$field->setEmptyString('Empty String');
40
		$field->setValue('');
41
		$this->assertTrue($field->validate($validator));
42
43
		//disabled items shouldn't validate
44
		$field->setDisabledItems(array('1'));
45
		$field->setValue('1');
46
		$this->assertFalse($field->validate($validator));
47
48
		//grouped disabled items shouldn't validate
49
		$field->setDisabledItems(array("Group One" => array("2")));
50
		$field->setValue('2');
51
		$this->assertFalse($field->validate($validator));
52
	}
53
54
}
55