35 $this->converter = new \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter();
42 $this->assertEquals(array(
'string',
'integer',
'array'), $this->converter->getSupportedSourceTypes(),
'Source types do not match');
43 $this->assertEquals(
'DateTime', $this->converter->getSupportedTargetType(),
'Target type does not match');
44 $this->assertEquals(1, $this->converter->getPriority(),
'Priority does not match');
54 $this->assertFalse($this->converter->canConvertFrom(
'Foo',
'SomeOtherType'));
61 $this->assertTrue($this->converter->canConvertFrom(
'Foo',
'DateTime'));
68 $this->assertTrue($this->converter->canConvertFrom(
'',
'DateTime'));
75 $error = $this->converter->convertFrom(
'1980-12-13',
'DateTime');
76 $this->assertInstanceOf(
'TYPO3\\CMS\\Extbase\\Error\\Error', $error);
83 $expectedResult =
'1980-12-13T20:15:07+01:23';
84 $date = $this->converter->convertFrom($expectedResult,
'DateTime');
85 $actualResult = $date->format(
'Y-m-d\\TH:i:sP');
86 $this->assertSame($expectedResult, $actualResult);
93 $expectedResult =
'1980-12-13T20:15:07+01:23';
94 $mockMappingConfiguration = $this->getMock(
'TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface');
95 $mockMappingConfiguration
96 ->expects($this->atLeastOnce())
97 ->method(
'getConfigurationValue')
98 ->with(
'TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter', \
TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT)
99 ->will($this->returnValue(NULL));
101 $date = $this->converter->convertFrom($expectedResult,
'DateTime', array(), $mockMappingConfiguration);
102 $actualResult = $date->format(\
TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::DEFAULT_DATE_FORMAT);
103 $this->assertSame($expectedResult, $actualResult);
110 $date = $this->converter->convertFrom(
'',
'DateTime', array(), NULL);
111 $this->assertNull($date);
120 array(
'1308174051',
'', FALSE),
121 array(
'13-12-1980',
'd.m.Y', FALSE),
122 array(
'1308174051',
'Y-m-d', FALSE),
123 array(
'12:13',
'H:i', TRUE),
124 array(
'13.12.1980',
'd.m.Y', TRUE),
125 array(
'2005-08-15T15:52:01+00:00', NULL, TRUE),
126 array(
'2005-08-15T15:52:01+0000', \DateTime::ISO8601, TRUE),
127 array(
'1308174051',
'U', TRUE),
139 if ($dateFormat !== NULL) {
140 $mockMappingConfiguration = $this->getMock(
'TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface');
141 $mockMappingConfiguration
142 ->expects($this->atLeastOnce())
143 ->method(
'getConfigurationValue')
144 ->with(
'TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter', \
TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT)
145 ->will($this->returnValue($dateFormat));
147 $mockMappingConfiguration = NULL;
149 $date = $this->converter->convertFrom($source,
'DateTime', array(), $mockMappingConfiguration);
150 if ($isValid !== TRUE) {
151 $this->assertInstanceOf(
'TYPO3\\CMS\\Extbase\\Error\\Error', $date);
154 $this->assertInstanceOf(
'DateTime', $date);
156 if ($dateFormat === NULL) {
159 $this->assertSame($source, $date->format($dateFormat));
180 $date = $this->converter->convertFrom($source,
'DateTime', array(), NULL);
181 $this->assertInstanceOf(
'DateTime', $date);
182 $this->assertSame(strval($source), $date->format(
'U'));
194 $date = $this->converter->convertFrom(array(
'date' => $source),
'DateTime', array(), NULL);
195 $this->assertInstanceOf(
'DateTime', $date);
196 $this->assertSame(strval($source), $date->format(
'U'));
204 $this->assertTrue($this->converter->canConvertFrom(array(),
'DateTime'));
211 $error = $this->converter->convertFrom(array(
'date' =>
'1980-12-13'),
'DateTime');
212 $this->assertInstanceOf(
'TYPO3\\CMS\\Extbase\\Error\\Error', $error);
220 $this->converter->convertFrom(array(
'hour' =>
'12',
'minute' =>
'30'),
'DateTime');
227 $expectedResult =
'1980-12-13T20:15:07+01:23';
228 $date = $this->converter->convertFrom(array(
'date' => $expectedResult),
'DateTime');
229 $actualResult = $date->format(
'Y-m-d\\TH:i:sP');
230 $this->assertSame($expectedResult, $actualResult);
239 array(array(
'day' =>
'13.0',
'month' =>
'10',
'year' =>
'2010')),
240 array(array(
'day' =>
'13',
'month' =>
'10.0',
'year' =>
'2010')),
241 array(array(
'day' =>
'13',
'month' =>
'10',
'year' =>
'2010.0')),
242 array(array(
'day' =>
'-13',
'month' =>
'10',
'year' =>
'2010')),
243 array(array(
'day' =>
'13',
'month' =>
'-10',
'year' =>
'2010')),
244 array(array(
'day' =>
'13',
'month' =>
'10',
'year' =>
'-2010')),
254 $this->converter->convertFrom($source,
'DateTime');
261 $source = array(
'day' =>
'13',
'month' =>
'10',
'year' =>
'2010');
262 $mappingConfiguration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
263 $mappingConfiguration->setTypeConverterOption(
264 'TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter',
265 \
TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
269 $date = $this->converter->convertFrom($source,
'DateTime', array(), $mappingConfiguration);
270 $actualResult = $date->format(
'Y-m-d');
271 $this->assertSame(
'2010-10-13', $actualResult);
279 'date' =>
'2011-06-16',
280 'dateFormat' =>
'Y-m-d',
285 $date = $this->converter->convertFrom($source,
'DateTime');
286 $this->assertSame(
'2011-06-16', $date->format(
'Y-m-d'));
287 $this->assertSame(
'12', $date->format(
'H'));
288 $this->assertSame(
'30', $date->format(
'i'));
289 $this->assertSame(
'59', $date->format(
's'));
297 'date' =>
'2011-06-16 12:30:59',
298 'dateFormat' =>
'Y-m-d H:i:s',
299 'timezone' =>
'Atlantic/Reykjavik',
301 $date = $this->converter->convertFrom($source,
'DateTime');
302 $this->assertSame(
'2011-06-16', $date->format(
'Y-m-d'));
303 $this->assertSame(
'12', $date->format(
'H'));
304 $this->assertSame(
'30', $date->format(
'i'));
305 $this->assertSame(
'59', $date->format(
's'));
306 $this->assertSame(
'Atlantic/Reykjavik', $date->getTimezone()->getName());
315 'date' =>
'2011-06-16',
316 'dateFormat' =>
'Y-m-d',
317 'timezone' =>
'Invalid/Timezone',
319 $this->converter->convertFrom($source,
'DateTime');
327 $this->converter->convertFrom(array(),
'DateTime', array(), NULL);
334 $this->assertNull($this->converter->convertFrom(array(
'date' =>
''),
'DateTime', array(), NULL));
343 array(array(
'date' =>
'2005-08-15T15:52:01+01:00'), TRUE),
344 array(array(
'date' =>
'1308174051',
'dateFormat' =>
''), FALSE),
345 array(array(
'date' =>
'13-12-1980',
'dateFormat' =>
'd.m.Y'), FALSE),
346 array(array(
'date' =>
'1308174051',
'dateFormat' =>
'Y-m-d'), FALSE),
347 array(array(
'date' =>
'12:13',
'dateFormat' =>
'H:i'), TRUE),
348 array(array(
'date' =>
'13.12.1980',
'dateFormat' =>
'd.m.Y'), TRUE),
349 array(array(
'date' =>
'2005-08-15T15:52:01+00:00',
'dateFormat' =>
''), TRUE),
350 array(array(
'date' =>
'2005-08-15T15:52:01+0000',
'dateFormat' => \DateTime::ISO8601), TRUE),
351 array(array(
'date' =>
'1308174051',
'dateFormat' =>
'U'), TRUE),
352 array(array(
'date' => 1308174051,
'dateFormat' =>
'U'), TRUE),
363 $dateFormat = isset($source[
'dateFormat']) && strlen($source[
'dateFormat']) > 0 ? $source[
'dateFormat'] : NULL;
364 if ($dateFormat !== NULL) {
365 $mockMappingConfiguration = $this->getMock(
'TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface');
366 $mockMappingConfiguration
367 ->expects($this->atLeastOnce())
368 ->method(
'getConfigurationValue')
369 ->with(
'TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter', \
TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT)
370 ->will($this->returnValue($dateFormat));
372 $mockMappingConfiguration = NULL;
374 $date = $this->converter->convertFrom($source,
'DateTime', array(), $mockMappingConfiguration);
376 if ($isValid !== TRUE) {
377 $this->assertInstanceOf(
'TYPO3\\CMS\\Extbase\\Error\\Error', $date);
381 $this->assertInstanceOf(
'DateTime', $date);
382 if ($dateFormat === NULL) {
385 $dateAsString = isset($source[
'date']) ? strval($source[
'date']) :
'';
386 $this->assertSame($dateAsString, $date->format($dateFormat));
393 $className = $this->
getUniqueId(
'DateTimeSubClass');
395 class ' . $className .
' extends \\DateTime { 396 public static function createFromFormat($format, $time, $timezone = NULL) { 397 return new ' . $className .
'(); 399 public function foo() { return "Bar"; } 402 $date = $this->converter->convertFrom(
'2005-08-15T15:52:01+00:00', $className);
404 $this->assertInstanceOf($className, $date);
405 $this->assertSame(
'Bar', $date->foo());
convertFromThrowsExceptionIfDatePartKeysHaveInvalidValuesSpecified($source)
convertFromEmptyStringReturnsNull()
convertFromArrayReturnsNullForEmptyDate()
canConvertFromReturnsTrueIfSourceTypeIsAnArray()
convertFromProperlyConvertsStringWithDefaultDateFormat()
convertFromProperlyConvertsArrayWithDefaultDateFormat()
convertFromArrayThrowsExceptionForEmptyArray()
convertFromReturnsErrorIfGivenStringCantBeConverted()
convertFromIntegerOrDigitStringsWithoutConfigurationDataProvider()
convertFromThrowsExceptionIfGivenArrayDoesNotSpecifyTheDate()
convertFromIntegerOrDigitStringInArrayWithoutConfigurationTests($source)
convertFromProperlyConvertsArrayWithDateAsArray()
const DEFAULT_DATE_FORMAT
convertFromAllowsToOverrideTheTime()
convertFromAllowsToOverrideTheTimezone()
canConvertFromReturnsTrueIfSourceTypeIsAString()
convertFromUsesDefaultDateFormatIfItIsNotConfigured()
convertFromArrayTests(array $source, $isValid)
convertFromIntegerOrDigitStringWithoutConfigurationTests($source)
convertFromStringTests($source, $dateFormat, $isValid)
convertFromArrayDataProvider()
canConvertFromReturnsFalseIfTargetTypeIsNotDateTime()
convertFromReturnsErrorIfGivenArrayCantBeConverted()
canConvertFromReturnsTrueIfSourceTypeIsAnEmptyString()
convertFromSupportsDateTimeSubClasses()
convertFromThrowsExceptionIfSpecifiedTimezoneIsInvalid()
invalidDatePartKeyValuesDataProvider()
convertFromStringDataProvider()