Merge branch '4.5' into 4

This commit is contained in:
Steve Boyd 2020-03-06 10:53:28 +13:00
commit 667495eaf9
3 changed files with 58 additions and 11 deletions

View File

@ -373,6 +373,14 @@ class TimeField extends TextField
{
/** @var TimeField_Readonly $result */
$result = $this->castedCopy(TimeField_Readonly::class);
$result
->setValue(false)
->setHTML5($this->html5)
->setTimeFormat($this->timeFormat)
->setTimezone($this->getTimezone())
->setLocale($this->locale)
->setTimeLength($this->timeLength)
->setValue($this->value);
return $result;
}

View File

@ -9,18 +9,11 @@ use SilverStripe\Core\Convert;
*/
class TimeField_Readonly extends TimeField
{
protected $readonly = true;
public function Field($properties = array())
protected $disabled = true;
public function Type()
{
if ($this->valueObj) {
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('timeformat')));
} else {
// TODO Localization
$val = '<i>(not set)</i>';
}
return "<span class=\"readonly\" id=\"" . $this->ID() . "\">$val</span>";
return 'readonly';
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace SilverStripe\Forms;
use IntlDateFormatter;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\TimeField;
use SilverStripe\Forms\TimeField_Readonly;
use SilverStripe\i18n\i18n;
class TimeFieldReadonlyTest extends SapphireTest
{
protected function setUp()
{
parent::setUp();
i18n::set_locale('en_NZ');
}
public function testPerformReadonly()
{
$field = new TimeField('Time', 'Time', '23:00:00');
$roField = $field->performReadonlyTransformation();
$this->assertInstanceOf(TimeField_Readonly::class, $roField);
$this->assertTrue($roField->isReadonly());
$this->assertEquals($roField->dataValue(), '23:00:00');
}
public function testSettingsCarryOver()
{
$field = new TimeField('Time', 'Time');
$field
->setHTML5(false)
->setTimeFormat('KK:mma')
->setTimezone('America/Halifax')
->setLocale('en_US')
->setTimeLength(IntlDateFormatter::SHORT)
->setValue('23:00:00');
$roField = $field->performReadonlyTransformation();
$this->assertFalse($roField->getHTML5());
$this->assertEquals($roField->getTimeFormat(), 'KK:mma');
$this->assertEquals($roField->getTimezone(), 'America/Halifax');
$this->assertEquals($roField->getLocale(), 'en_US');
$this->assertEquals($roField->getTimeLength(), IntlDateFormatter::SHORT);
}
}