Completed
Pull Request — master (#5408)
by Damian
23:40 queued 12:41
created

EnumFieldTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAnyFieldIsPresentInSearchField() 0 12 1
B testEnumParsing() 0 25 1
1
<?php
2
3
use SilverStripe\Model\FieldType\DBEnum;
4
5
/**
6
 * @package framework
7
 * @subpackage tests
8
 */
9
class EnumFieldTest extends SapphireTest {
10
	public function testAnyFieldIsPresentInSearchField() {
11
		$values = array (
12
				'Key' => 'Value'
13
		);
14
		$enumField = new DBEnum('testField', $values);
15
16
		$searchField = $enumField->scaffoldSearchField();
17
18
		$anyText = "(" . _t('Enum.ANY', 'Any') . ")";
19
		$this->assertEquals(true, $searchField->getHasEmptyDefault());
20
		$this->assertEquals($anyText, $searchField->getEmptyString());
21
	}
22
23
	public function testEnumParsing() {
24
		$enum = new DBEnum('testField', "
25
			,
26
			0,
27
			Item1,
28
			Item2,
29
			Item 3,
30
			Item-4,
31
			item 5
32
			still 5,
33
			trailing comma,
34
		");
35
36
		$this->assertEquals(ArrayLib::valuekey(array(
37
			'',
38
			'0',
39
			'Item1',
40
			'Item2',
41
			'Item 3',
42
		    'Item-4',
43
			'item 5
44
			still 5',
45
			'trailing comma'
46
		)), $enum->enumValues());
47
	}
48
}
49