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

48 lines
1.4 KiB
PHP
Raw Normal View History

<?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);
$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);
$this->assertEquals($matches[0], '(none)');
}
}