2018-04-20 00:29:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\SingleLookupField;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\DropdownField;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SingleLookupFieldTest
|
|
|
|
*
|
|
|
|
* @package SilverStripe\Forms\Tests
|
|
|
|
*/
|
|
|
|
class SingleLookupFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testValueFromSource()
|
|
|
|
{
|
|
|
|
/** @var SingleLookupField $testField */
|
|
|
|
$testField = DropdownField::create(
|
|
|
|
'FirstName',
|
|
|
|
'FirstName',
|
|
|
|
['member1' => 'Member 1', 'member2' => 'Member 2', 'member3' => 'Member 3']
|
|
|
|
)->performReadonlyTransformation();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(SingleLookupField::class, $testField);
|
|
|
|
|
|
|
|
$testField->setValue('member1');
|
2022-04-14 03:12:59 +02:00
|
|
|
preg_match('/Member 1/', $testField->Field() ?? '', $matches);
|
2018-04-20 00:29:45 +02:00
|
|
|
$this->assertEquals($matches[0], 'Member 1');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValueNotFromSource()
|
|
|
|
{
|
|
|
|
/** @var SingleLookupField $testField */
|
|
|
|
$testField = DropdownField::create(
|
|
|
|
'FirstName',
|
|
|
|
'FirstName',
|
|
|
|
['member1' => 'Member 1', 'member2' => 'Member 2', 'member3' => 'Member 3']
|
|
|
|
)->performReadonlyTransformation();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(SingleLookupField::class, $testField);
|
|
|
|
|
|
|
|
$testField->setValue('member123');
|
2022-04-14 03:12:59 +02:00
|
|
|
preg_match('/\(none\)/', $testField->Field() ?? '', $matches);
|
2018-04-20 00:29:45 +02:00
|
|
|
$this->assertEquals($matches[0], '(none)');
|
|
|
|
}
|
|
|
|
}
|