silverstripe-framework/tests/php/Forms/EnumFieldTest.php

49 lines
947 B
PHP
Raw Normal View History

2014-03-30 08:51:38 +02:00
<?php
2016-10-14 03:30:05 +02:00
namespace SilverStripe\Forms\Tests;
use SilverStripe\ORM\ArrayLib;
use SilverStripe\ORM\FieldType\DBEnum;
use SilverStripe\Dev\SapphireTest;
2014-03-30 08:51:38 +02:00
class EnumFieldTest extends SapphireTest {
public function testAnyFieldIsPresentInSearchField() {
$values = array (
2014-08-15 08:53:05 +02:00
'Key' => 'Value'
2014-03-30 08:51:38 +02:00
);
$enumField = new DBEnum('testField', $values);
2014-08-15 08:53:05 +02:00
2014-03-30 08:51:38 +02:00
$searchField = $enumField->scaffoldSearchField();
2014-08-15 08:53:05 +02:00
2014-03-30 08:51:38 +02:00
$anyText = "(" . _t('Enum.ANY', 'Any') . ")";
$this->assertEquals(true, $searchField->getHasEmptyDefault());
$this->assertEquals($anyText, $searchField->getEmptyString());
}
2015-10-15 16:18:32 +02:00
public function testEnumParsing() {
$enum = new DBEnum('testField', "
2016-03-17 22:43:26 +01:00
,
0,
2015-10-15 16:18:32 +02:00
Item1,
Item2,
Item 3,
Item-4,
item 5
still 5,
trailing comma,
");
$this->assertEquals(ArrayLib::valuekey(array(
2016-03-17 22:43:26 +01:00
'',
'0',
2015-10-15 16:18:32 +02:00
'Item1',
'Item2',
'Item 3',
'Item-4',
'item 5
still 5',
'trailing comma'
)), $enum->enumValues());
}
2014-03-30 08:51:38 +02:00
}