mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-07 18:21:23 +02:00
See https://github.com/silverstripe/silverstripe-framework/pull/7037 and https://github.com/silverstripe/silverstripe-framework/issues/6681 Squashed commit of the following: commit8f65e56532
Author: Ingo Schommer <me@chillu.com> Date: Thu Jun 22 22:25:50 2017 +1200 Fixed upgrade guide spelling commit76f95944fa
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 16:38:34 2017 +1200 BUG Fix non-test class manifest including sapphiretest / functionaltest commit9379834cb4
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 15:50:47 2017 +1200 BUG Fix nesting bug in Kernel commit188ce35d82
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 15:14:51 2017 +1200 BUG fix db bootstrapping issues commit7ed4660e7a
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 14:49:07 2017 +1200 BUG Fix issue in DetailedErrorFormatter commit738f50c497
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 11:49:19 2017 +1200 Upgrading notes on mysite/_config.php commit6279d28e5e
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 11:43:28 2017 +1200 Update developer documentation commit5c90d53a84
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 22 10:48:44 2017 +1200 Update installer to not use global databaseConfig commitf9b2ba4755
Author: Damian Mooyman <damian@silverstripe.com> Date: Wed Jun 21 21:04:39 2017 +1200 Fix behat issues commit5b59a912b6
Author: Damian Mooyman <damian@silverstripe.com> Date: Wed Jun 21 17:07:11 2017 +1200 Move HTTPApplication to SilverStripe\Control namespace commite2c4a18f63
Author: Damian Mooyman <damian@silverstripe.com> Date: Wed Jun 21 16:29:03 2017 +1200 More documentation Fix up remaining tests Refactor temp DB into TempDatabase class so it’s available outside of unit tests. commit5d235e64f3
Author: Damian Mooyman <damian@silverstripe.com> Date: Wed Jun 21 12:13:15 2017 +1200 API HTTPRequestBuilder::createFromEnvironment() now cleans up live globals BUG Fix issue with SSViewer Fix Security / View tests commitd88d4ed4e4
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 20 16:39:43 2017 +1200 API Refactor AppKernel into CoreKernel commitf7946aec33
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 20 16:00:40 2017 +1200 Docs and minor cleanup commit12bd31f936
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 20 15:34:34 2017 +1200 API Remove OutputMiddleware API Move environment / global / ini management into Environment class API Move getTempFolder into TempFolder class API Implement HTTPRequestBuilder / CLIRequestBuilder BUG Restore SS_ALLOWED_HOSTS check in original location API CoreKernel now requires $basePath to be passed in API Refactor installer.php to use application to bootstrap API move memstring conversion globals to Convert BUG Fix error in CoreKernel nesting not un-nesting itself properly. commitbba9791146
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 19 18:07:53 2017 +1200 API Create HTTPMiddleware and standardise middleware for request handling commit2a10c2397b
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 19 17:42:42 2017 +1200 Fixed ORM tests commitd75a8d1d93
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 19 17:15:07 2017 +1200 FIx i18n tests commit06364af3c3
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 19 16:59:34 2017 +1200 Fix controller namespace Move states to sub namespace commit2a278e2953
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 19 12:49:45 2017 +1200 Fix forms namespace commitb65c21241b
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 15 18:56:48 2017 +1200 Update API usages commitd1d4375c95
Author: Damian Mooyman <damian@silverstripe.com> Date: Thu Jun 15 18:41:44 2017 +1200 API Refactor $flush into HTPPApplication API Enforce health check in Controller::pushCurrent() API Better global backup / restore Updated Director::test() to use new API commitb220534f06
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 22:05:57 2017 +1200 Move app nesting to a test state helper commit603704165c
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 21:46:04 2017 +1200 Restore kernel stack to fix multi-level nesting commit2f6336a15b
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 17:23:21 2017 +1200 API Implement kernel nesting commitfc7188da7d
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 15:43:13 2017 +1200 Fix core tests commita0ae723514
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 15:23:52 2017 +1200 Fix manifest tests commitca03395251
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 15:00:00 2017 +1200 API Move extension management into test state commitc66d433977
Author: Damian Mooyman <damian@silverstripe.com> Date: Tue Jun 13 14:10:59 2017 +1200 API Refactor SapphireTest state management into SapphireTestState API Remove Injector::unregisterAllObjects() API Remove FakeController commitf26ae75c6e
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 12 18:04:34 2017 +1200 Implement basic CLI application object commit001d559662
Author: Damian Mooyman <damian@silverstripe.com> Date: Mon Jun 12 17:39:38 2017 +1200 Remove references to SapphireTest::is_running_test() Upgrade various code commitde079c041d
Author: Damian Mooyman <damian@silverstripe.com> Date: Wed Jun 7 18:07:33 2017 +1200 API Implement APP object API Refactor of Session
462 lines
18 KiB
PHP
462 lines
18 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Forms\DatetimeField;
|
|
use SilverStripe\Forms\FieldList;
|
|
use SilverStripe\Forms\Form;
|
|
use SilverStripe\Forms\FormAction;
|
|
use SilverStripe\Forms\RequiredFields;
|
|
use SilverStripe\Forms\Tests\DatetimeFieldTest\Model;
|
|
use SilverStripe\i18n\i18n;
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
class DatetimeFieldTest extends SapphireTest
|
|
{
|
|
protected $timezone = null;
|
|
|
|
protected function setUp()
|
|
{
|
|
parent::setUp();
|
|
i18n::set_locale('en_NZ');
|
|
// Fix now to prevent race conditions
|
|
DBDatetime::set_mock_now('2010-04-04');
|
|
$this->timezone = date_default_timezone_get();
|
|
}
|
|
|
|
protected function tearDown()
|
|
{
|
|
DBDatetime::clear_mock_now();
|
|
date_default_timezone_set($this->timezone);
|
|
parent::tearDown(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
public function testFormSaveInto()
|
|
{
|
|
$dateTimeField = new DatetimeField('MyDatetime');
|
|
$form = $this->getMockForm();
|
|
$form->Fields()->push($dateTimeField);
|
|
|
|
$dateTimeField->setSubmittedValue('2003-03-29T23:59:38');
|
|
$validator = new RequiredFields();
|
|
$this->assertTrue($dateTimeField->validate($validator));
|
|
$m = new Model();
|
|
$form->saveInto($m);
|
|
$this->assertEquals('2003-03-29 23:59:38', $m->MyDatetime);
|
|
}
|
|
|
|
public function testFormSaveIntoLocalised()
|
|
{
|
|
$dateTimeField = new DatetimeField('MyDatetime');
|
|
$dateTimeField
|
|
->setHTML5(false)
|
|
->setLocale('en_NZ');
|
|
|
|
$form = $this->getMockForm();
|
|
$form->Fields()->push($dateTimeField);
|
|
|
|
// en_NZ standard format
|
|
$dateTimeField->setSubmittedValue('29/03/2003 11:59:38 pm');
|
|
$validator = new RequiredFields();
|
|
$this->assertTrue($dateTimeField->validate($validator));
|
|
$m = new Model();
|
|
$form->saveInto($m);
|
|
$this->assertEquals('2003-03-29 23:59:38', $m->MyDatetime);
|
|
}
|
|
|
|
public function testDataValue()
|
|
{
|
|
$f = new DatetimeField('Datetime');
|
|
$this->assertEquals(null, $f->dataValue(), 'Empty field');
|
|
|
|
$f = new DatetimeField('Datetime', null, '2003-03-29 23:59:38');
|
|
$this->assertEquals('2003-03-29 23:59:38', $f->dataValue(), 'From date/time string');
|
|
}
|
|
|
|
public function testDataValueWithTimezone()
|
|
{
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere winter
|
|
date_default_timezone_set('Europe/Berlin');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setTimezone('Pacific/Auckland');
|
|
$f->setSubmittedValue('2003-01-30T23:59:38'); // frontend timezone (Auckland)
|
|
$this->assertEquals('2003-01-30 11:59:38', $f->dataValue()); // server timezone (Berlin)
|
|
}
|
|
|
|
public function testConstructorWithoutArgs()
|
|
{
|
|
$f = new DatetimeField('Datetime');
|
|
$this->assertEquals($f->dataValue(), null);
|
|
}
|
|
|
|
public function testConstructorWithLocalizedDateSetsNullValue()
|
|
{
|
|
$f = new DatetimeField('Datetime', 'Datetime', '29/03/2003 23:59:38');
|
|
$this->assertNull($f->Value());
|
|
}
|
|
|
|
public function testConstructorWithIsoDate()
|
|
{
|
|
// used by Form->loadDataFrom()
|
|
$f = new DatetimeField('Datetime', 'Datetime', '2003-03-29 23:59:38');
|
|
$this->assertEquals($f->dataValue(), '2003-03-29 23:59:38');
|
|
}
|
|
|
|
public function testSetValueWithDateTimeString()
|
|
{
|
|
$f = new DatetimeField('Datetime', 'Datetime');
|
|
$f->setValue('2003-03-29 23:59:38');
|
|
$this->assertEquals($f->dataValue(), '2003-03-29 23:59:38', 'Accepts ISO');
|
|
|
|
$f = new DatetimeField('Datetime', 'Datetime');
|
|
$f->setValue('2003-03-29T23:59:38');
|
|
$this->assertNull($f->dataValue(), 'Rejects normalised ISO');
|
|
}
|
|
|
|
public function testSubmittedValue()
|
|
{
|
|
$datetimeField = new DatetimeField('Datetime', 'Datetime');
|
|
$datetimeField->setSubmittedValue('2003-03-29 23:00:00');
|
|
$this->assertEquals($datetimeField->dataValue(), '2003-03-29 23:00:00');
|
|
|
|
$datetimeField = new DatetimeField('Datetime', 'Datetime');
|
|
$datetimeField->setSubmittedValue('2003-03-29T23:00:00');
|
|
$this->assertEquals($datetimeField->dataValue(), '2003-03-29 23:00:00', 'Normalised ISO');
|
|
}
|
|
|
|
public function testSetValueWithLocalised()
|
|
{
|
|
$datetimeField = new DatetimeField('Datetime', 'Datetime');
|
|
|
|
$datetimeField
|
|
->setHTML5(false)
|
|
->setLocale('en_NZ');
|
|
|
|
$datetimeField->setSubmittedValue('29/03/2003 11:00:00 pm');
|
|
$this->assertEquals($datetimeField->dataValue(), '2003-03-29 23:00:00');
|
|
|
|
// Some localisation packages exclude the ',' in default medium format
|
|
$this->assertRegExp(
|
|
'#29/03/2003(,)? 11:00:00 (PM|pm)#',
|
|
$datetimeField->Value(),
|
|
'User value is formatted, and in user timezone'
|
|
);
|
|
}
|
|
|
|
public function testValidate()
|
|
{
|
|
$f = new DatetimeField('Datetime', 'Datetime', '2003-03-29 23:59:38');
|
|
$this->assertTrue($f->validate(new RequiredFields()));
|
|
|
|
$f = new DatetimeField('Datetime', 'Datetime', '2003-03-29T23:59:38');
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Normalised ISO');
|
|
|
|
$f = new DatetimeField('Datetime', 'Datetime', '2003-03-29');
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Leaving out time');
|
|
|
|
$f = (new DatetimeField('Datetime', 'Datetime'))
|
|
->setSubmittedValue('2003-03-29T00:00');
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Leaving out seconds (like many browsers)');
|
|
|
|
$f = new DatetimeField('Datetime', 'Datetime', 'wrong');
|
|
$this->assertFalse($f->validate(new RequiredFields()));
|
|
}
|
|
|
|
public function testSetMinDate()
|
|
{
|
|
$f = (new DatetimeField('Datetime'))->setMinDatetime('2009-03-31T23:00:00');
|
|
$this->assertEquals($f->getMinDatetime(), '2009-03-31 23:00:00', 'Retains ISO');
|
|
|
|
$f = (new DatetimeField('Datetime'))->setMinDatetime('2009-03-31 23:00:00');
|
|
$this->assertEquals($f->getMinDatetime(), '2009-03-31 23:00:00', 'Converts normalised ISO to ISO');
|
|
|
|
$f = (new DatetimeField('Datetime'))->setMinDatetime('invalid');
|
|
$this->assertNull($f->getMinDatetime(), 'Ignores invalid values');
|
|
}
|
|
|
|
public function testSetMaxDate()
|
|
{
|
|
$f = (new DatetimeField('Datetime'))->setMaxDatetime('2009-03-31T23:00:00');
|
|
$this->assertEquals($f->getMaxDatetime(), '2009-03-31 23:00:00', 'Retains ISO');
|
|
|
|
$f = (new DatetimeField('Datetime'))->setMaxDatetime('2009-03-31 23:00:00');
|
|
$this->assertEquals($f->getMaxDatetime(), '2009-03-31 23:00:00', 'Converts normalised ISO to ISO');
|
|
|
|
$f = (new DatetimeField('Datetime'))->setMaxDatetime('invalid');
|
|
$this->assertNull($f->getMaxDatetime(), 'Ignores invalid values');
|
|
}
|
|
|
|
public function testValidateMinDate()
|
|
{
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setMinDatetime('2009-03-31 23:00:00');
|
|
$dateField->setValue('2009-03-31 23:00:01');
|
|
$this->assertTrue($dateField->validate(new RequiredFields()), 'Time above min datetime');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setMinDatetime('2009-03-31 23:00:00');
|
|
$dateField->setValue('2009-03-31 22:00:00');
|
|
$this->assertFalse($dateField->validate(new RequiredFields()), 'Time below min datetime');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setMinDatetime('2009-03-31 23:00:00');
|
|
$dateField->setValue('2009-03-31 23:00:00');
|
|
$this->assertTrue($dateField->validate(new RequiredFields()), 'Date and time matching min datetime');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setMinDatetime('2009-03-31 23:00:00');
|
|
$dateField->setValue('2008-03-31 23:00:00');
|
|
$this->assertFalse($dateField->validate(new RequiredFields()), 'Date below min datetime');
|
|
}
|
|
|
|
public function testValidateMinDateWithSubmittedValueAndTimezone()
|
|
{
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere winter
|
|
date_default_timezone_set('Europe/Berlin');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setTimezone('Pacific/Auckland');
|
|
$dateField->setMinDatetime('2009-01-30 23:00:00'); // server timezone (Berlin)
|
|
$dateField->setSubmittedValue('2009-01-31T11:00:01'); // frontend timezone (Auckland)
|
|
$this->assertTrue($dateField->validate(new RequiredFields()), 'Time above min datetime');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setTimezone('Pacific/Auckland');
|
|
$dateField->setMinDatetime('2009-01-30 23:00:00');
|
|
$dateField->setSubmittedValue('2009-01-31T10:00:00');
|
|
$this->assertFalse($dateField->validate(new RequiredFields()), 'Time below min datetime');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setTimezone('Pacific/Auckland');
|
|
$dateField->setMinDatetime('2009-01-30 23:00:00');
|
|
$dateField->setSubmittedValue('2009-01-31T11:00:00');
|
|
$this->assertTrue($dateField->validate(new RequiredFields()), 'Date and time matching min datetime');
|
|
|
|
$dateField = new DatetimeField('Datetime');
|
|
$dateField->setTimezone('Pacific/Auckland');
|
|
$dateField->setMinDatetime('2009-01-30 23:00:00');
|
|
$dateField->setSubmittedValue('2008-01-31T11:00:00');
|
|
$this->assertFalse($dateField->validate(new RequiredFields()), 'Date below min datetime');
|
|
}
|
|
|
|
public function testValidateMinDateStrtotime()
|
|
{
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMinDatetime('-7 days');
|
|
$f->setValue(strftime('%Y-%m-%d %T', strtotime('-8 days', DBDatetime::now()->getTimestamp())));
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Date below min datetime, with strtotime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMinDatetime('-7 days');
|
|
$f->setValue(strftime('%Y-%m-%d %T', strtotime('-7 days', DBDatetime::now()->getTimestamp())));
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Date matching min datetime, with strtotime');
|
|
}
|
|
|
|
public function testValidateMaxDateStrtotime()
|
|
{
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMaxDatetime('7 days');
|
|
$f->setValue(strftime('%Y-%m-%d %T', strtotime('8 days', DBDatetime::now()->getTimestamp())));
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Date above max date, with strtotime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMaxDatetime('7 days');
|
|
$f->setValue(strftime('%Y-%m-%d %T', strtotime('7 days', DBDatetime::now()->getTimestamp())));
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Date matching max date, with strtotime');
|
|
}
|
|
|
|
public function testValidateMaxDate()
|
|
{
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMaxDatetime('2009-03-31 23:00:00');
|
|
$f->setValue('2009-03-31 22:00:00');
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Time below max datetime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMaxDatetime('2009-03-31 23:00:00');
|
|
$f->setValue('2010-03-31 23:00:01');
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Time above max datetime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMaxDatetime('2009-03-31 23:00:00');
|
|
$f->setValue('2009-03-31 23:00:00');
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Date and time matching max datetime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setMaxDatetime('2009-03-31 23:00:00');
|
|
$f->setValue('2010-03-31 23:00:00');
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Date above max datetime');
|
|
}
|
|
|
|
public function testValidateMaxDateWithSubmittedValueAndTimezone()
|
|
{
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere winter
|
|
date_default_timezone_set('Europe/Berlin');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setTimezone('Pacific/Auckland');
|
|
$f->setMaxDatetime('2009-01-31 23:00:00'); // server timezone (Berlin)
|
|
$f->setSubmittedValue('2009-01-31T10:00:00'); // frontend timezone (Auckland)
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Time below max datetime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setTimezone('Pacific/Auckland');
|
|
$f->setMaxDatetime('2009-01-31 23:00:00');
|
|
$f->setSubmittedValue('2010-01-31T11:00:01');
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Time above max datetime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setTimezone('Pacific/Auckland');
|
|
$f->setMaxDatetime('2009-01-31 23:00:00');
|
|
$f->setSubmittedValue('2009-01-31T11:00:00');
|
|
$this->assertTrue($f->validate(new RequiredFields()), 'Date and time matching max datetime');
|
|
|
|
$f = new DatetimeField('Datetime');
|
|
$f->setTimezone('Pacific/Auckland');
|
|
$f->setMaxDatetime('2009-01-31 23:00:00');
|
|
$f->setSubmittedValue('2010-01-31T11:00:00');
|
|
$this->assertFalse($f->validate(new RequiredFields()), 'Date above max datetime');
|
|
}
|
|
|
|
public function testTimezoneSetValueLocalised()
|
|
{
|
|
date_default_timezone_set('Europe/Berlin');
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere winter
|
|
$datetimeField = new DatetimeField('Datetime', 'Datetime');
|
|
|
|
$datetimeField
|
|
->setHTML5(false)
|
|
->setDatetimeFormat('dd/MM/y HH:mm:ss');
|
|
|
|
$datetimeField->setTimezone('Pacific/Auckland');
|
|
$datetimeField->setValue('2003-12-24 23:59:59');
|
|
$this->assertEquals(
|
|
'25/12/2003 11:59:59',
|
|
$datetimeField->Value(),
|
|
'User value is formatted, and in user timezone'
|
|
);
|
|
|
|
$this->assertEquals(
|
|
'2003-12-24 23:59:59',
|
|
$datetimeField->dataValue(),
|
|
'Data value is in ISO format, and in server timezone'
|
|
);
|
|
}
|
|
|
|
public function testTimezoneSetValueWithHtml5()
|
|
{
|
|
date_default_timezone_set('Europe/Berlin');
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere winter
|
|
$datetimeField = new DatetimeField('Datetime', 'Datetime');
|
|
|
|
$datetimeField->setTimezone('Pacific/Auckland');
|
|
$datetimeField->setValue('2003-12-24 23:59:59');
|
|
$this->assertEquals(
|
|
'2003-12-25T11:59:59',
|
|
$datetimeField->Value(),
|
|
'User value is in normalised ISO format and in user timezone'
|
|
);
|
|
|
|
$this->assertEquals(
|
|
'2003-12-24 23:59:59',
|
|
$datetimeField->dataValue(),
|
|
'Data value is in ISO format, and in server timezone'
|
|
);
|
|
}
|
|
|
|
public function testTimezoneSetSubmittedValueLocalised()
|
|
{
|
|
date_default_timezone_set('Europe/Berlin');
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere summer, but Berlin and Moscow only 2h.
|
|
$datetimeField = new DatetimeField('Datetime', 'Datetime');
|
|
|
|
$datetimeField
|
|
->setHTML5(false)
|
|
->setLocale('en_NZ');
|
|
|
|
$datetimeField->setTimezone('Europe/Moscow');
|
|
// pass in default format, at user time (Moscow)
|
|
$datetimeField->setSubmittedValue('24/06/2003 11:59:59 pm');
|
|
$this->assertTrue($datetimeField->validate(new RequiredFields()));
|
|
$this->assertEquals('2003-06-24 21:59:59', $datetimeField->dataValue(), 'Data value matches server timezone');
|
|
}
|
|
|
|
public function testGetName()
|
|
{
|
|
$field = new DatetimeField('Datetime');
|
|
|
|
$this->assertEquals('Datetime', $field->getName());
|
|
}
|
|
|
|
public function testSetName()
|
|
{
|
|
$field = new DatetimeField('Datetime', 'Datetime');
|
|
$field->setName('CustomDatetime');
|
|
$this->assertEquals('CustomDatetime', $field->getName());
|
|
}
|
|
|
|
public function testSchemaDataDefaultsIncludesMinMax()
|
|
{
|
|
$field = new DatetimeField('Datetime');
|
|
$field->setMinDatetime('2009-03-31 23:00:00');
|
|
$field->setMaxDatetime('2010-03-31 23:00:00');
|
|
$defaults = $field->getSchemaDataDefaults();
|
|
$this->assertEquals($defaults['data']['min'], '2009-03-31T23:00:00');
|
|
$this->assertEquals($defaults['data']['max'], '2010-03-31T23:00:00');
|
|
}
|
|
|
|
public function testSchemaDataDefaultsAdjustsMinMaxToTimezone()
|
|
{
|
|
date_default_timezone_set('Europe/Berlin');
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere summer, but Berlin and Moscow only 2h.
|
|
|
|
$field = new DatetimeField('Datetime');
|
|
$field->setTimezone('Pacific/Auckland');
|
|
$field->setMinDatetime('2009-01-31 11:00:00'); // server timezone
|
|
$field->setMaxDatetime('2010-01-31 11:00:00'); // server timezone
|
|
$defaults = $field->getSchemaDataDefaults();
|
|
$this->assertEquals($defaults['data']['min'], '2009-01-31T23:00:00'); // frontend timezone
|
|
$this->assertEquals($defaults['data']['max'], '2010-01-31T23:00:00'); // frontend timezone
|
|
}
|
|
|
|
public function testAttributesIncludesMinMax()
|
|
{
|
|
$field = new DatetimeField('Datetime');
|
|
$field->setMinDatetime('2009-03-31 23:00:00');
|
|
$field->setMaxDatetime('2010-03-31 23:00:00');
|
|
$attrs = $field->getAttributes();
|
|
$this->assertEquals($attrs['min'], '2009-03-31T23:00:00');
|
|
$this->assertEquals($attrs['max'], '2010-03-31T23:00:00');
|
|
}
|
|
|
|
public function testAttributesAdjustsMinMaxToTimezone()
|
|
{
|
|
date_default_timezone_set('Europe/Berlin');
|
|
// Berlin and Auckland have 12h time difference in northern hemisphere summer, but Berlin and Moscow only 2h.
|
|
|
|
$field = new DatetimeField('Datetime');
|
|
$field->setTimezone('Pacific/Auckland');
|
|
$field->setMinDatetime('2009-01-31 11:00:00'); // server timezone
|
|
$field->setMaxDatetime('2010-01-31 11:00:00'); // server timezone
|
|
$attrs = $field->getAttributes();
|
|
$this->assertEquals($attrs['min'], '2009-01-31T23:00:00'); // frontend timezone
|
|
$this->assertEquals($attrs['max'], '2010-01-31T23:00:00'); // frontend timezone
|
|
}
|
|
|
|
protected function getMockForm()
|
|
{
|
|
/** @skipUpgrade */
|
|
return new Form(
|
|
Controller::curr(),
|
|
'Form',
|
|
new FieldList(),
|
|
new FieldList(
|
|
new FormAction('doSubmit')
|
|
)
|
|
);
|
|
}
|
|
}
|