From a73abbfcb834dc740207d86bab20d7009ee60beb Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 27 Apr 2017 09:18:38 +1200 Subject: [PATCH] unit test cleanup --- docs/en/04_Changelogs/4.0.0.md | 1 + tests/php/Forms/DatetimeFieldTest.php | 31 ++++++++++++--------------- tests/php/ORM/DBDatetimeTest.php | 8 +++---- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 32549d376..ea1a357bc 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -1679,6 +1679,7 @@ The `DatetimeField` has changed behaviour: by default in `Value()`, which include a "T" separator between date and time. This is required to allow HTML5 input. Either use `setHTML5(false)` to set your custom format, or use `dataValue()` to retrieve a whitespace separated representation. +* It no longer accepts `setValue()` as an array with 'date' and 'time' keys * Added `getHTML5()` / `setHTML5()` New `DateField` methods replace `getConfig()` / `setConfig()`: diff --git a/tests/php/Forms/DatetimeFieldTest.php b/tests/php/Forms/DatetimeFieldTest.php index df4e517f8..08dfdab88 100644 --- a/tests/php/Forms/DatetimeFieldTest.php +++ b/tests/php/Forms/DatetimeFieldTest.php @@ -80,12 +80,11 @@ class DatetimeFieldTest extends SapphireTest $this->assertEquals($f->dataValue(), null); } - // /** - // * @expectedException InvalidArgumentException - // */ - // public function testConstructorWithLocalizedDateString() { - // $f = new DatetimeField('Datetime', 'Datetime', '29/03/2003 23:59:38'); - // } + public function testConstructorWithLocalizedDateSetsNullValue() + { + $f = new DatetimeField('Datetime', 'Datetime', '29/03/2003 23:59:38'); + $this->assertNull($f->Value()); + } public function testConstructorWithIsoDate() { @@ -94,14 +93,6 @@ class DatetimeFieldTest extends SapphireTest $this->assertEquals($f->dataValue(), '2003-03-29 23:59:38'); } - // /** - // * @expectedException InvalidArgumentException - // */ - // public function testSetValueWithDateString() { - // $f = new DatetimeField('Datetime', 'Datetime'); - // $f->setValue('29/03/2003'); - // } - public function testSetValueWithDateTimeString() { $f = new DatetimeField('Datetime', 'Datetime'); @@ -132,9 +123,15 @@ class DatetimeFieldTest extends SapphireTest ->setHTML5(false) ->setLocale('en_NZ'); - // Values can only be localized (= non-ISO) in array notation $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 (AM|am)#', + $datetimeField->Value(), + 'User value is formatted, and in user timezone' + ); } public function testValidate() @@ -246,12 +243,12 @@ class DatetimeFieldTest extends SapphireTest $datetimeField ->setHTML5(false) - ->setLocale('en_NZ'); + ->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 AM', + '25/12/2003 11:59:59', $datetimeField->Value(), 'User value is formatted, and in user timezone' ); diff --git a/tests/php/ORM/DBDatetimeTest.php b/tests/php/ORM/DBDatetimeTest.php index bfb2ab032..428e56b03 100644 --- a/tests/php/ORM/DBDatetimeTest.php +++ b/tests/php/ORM/DBDatetimeTest.php @@ -29,7 +29,7 @@ class DBDatetimeTest extends SapphireTest public function testNowWithMockDate() { // Test setting - $mockDate = '2001-12-31T22:10:59'; + $mockDate = '2001-12-31 22:10:59'; DBDatetime::set_mock_now($mockDate); $systemDatetime = DBDatetime::create_field('Datetime', date('Y-m-d H:i:s')); $nowDatetime = DBDatetime::now(); @@ -55,10 +55,10 @@ class DBDatetimeTest extends SapphireTest $this->assertNull($date->getValue(), 'Boolean FALSE evaluates to NULL'); $date = DBDatetime::create_field('Datetime', '0'); - $this->assertEquals('1970-01-01T00:00:00', $date->getValue(), 'String zero is UNIX epoch time'); + $this->assertEquals('1970-01-01 00:00:00', $date->getValue(), 'String zero is UNIX epoch time'); $date = DBDatetime::create_field('Datetime', 0); - $this->assertEquals('1970-01-01T00:00:00', $date->getValue(), 'Numeric zero is UNIX epoch time'); + $this->assertEquals('1970-01-01 00:00:00', $date->getValue(), 'Numeric zero is UNIX epoch time'); } public function testExtendedDateTimes() @@ -98,7 +98,7 @@ class DBDatetimeTest extends SapphireTest public function testURLDateTime() { $date = DBDatetime::create_field('Datetime', '2001-12-31 22:10:59'); - $this->assertEquals('2001-12-31T22%3A10%3A59', $date->URLDateTime()); + $this->assertEquals('2001-12-31%2022%3A10%3A59', $date->URLDateTime()); } public function testAgoInPast()