2014-03-30 08:51:38 +02:00
|
|
|
<?php
|
2015-08-30 07:02:55 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests;
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\ORM\ArrayLib;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBEnum;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class EnumFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testAnyFieldIsPresentInSearchField()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
$values = [
|
2016-12-16 05:34:21 +01:00
|
|
|
'Key' => 'Value'
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
$enumField = new DBEnum('testField', $values);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$searchField = $enumField->scaffoldSearchField();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2017-04-20 03:59:51 +02:00
|
|
|
$anyText = "(" . _t('SilverStripe\\ORM\\FieldType\\DBEnum.ANY', 'Any') . ")";
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(true, $searchField->getHasEmptyDefault());
|
|
|
|
$this->assertEquals($anyText, $searchField->getEmptyString());
|
|
|
|
}
|
2015-10-15 16:18:32 +02:00
|
|
|
|
2016-12-16 05:34:21 +01: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,
|
2016-12-16 05:34:21 +01:00
|
|
|
"
|
|
|
|
);
|
2015-10-15 16:18:32 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
ArrayLib::valuekey(
|
2020-04-20 19:58:09 +02:00
|
|
|
[
|
2016-12-16 05:34:21 +01:00
|
|
|
'',
|
|
|
|
'0',
|
|
|
|
'Item1',
|
|
|
|
'Item2',
|
|
|
|
'Item 3',
|
|
|
|
'Item-4',
|
|
|
|
'item 5
|
2015-10-15 16:18:32 +02:00
|
|
|
still 5',
|
2016-12-16 05:34:21 +01:00
|
|
|
'trailing comma'
|
2020-04-20 19:58:09 +02:00
|
|
|
]
|
2016-12-16 05:34:21 +01:00
|
|
|
),
|
|
|
|
$enum->enumValues()
|
|
|
|
);
|
|
|
|
}
|
2014-03-30 08:51:38 +02:00
|
|
|
}
|