function EntityTestDatetimeTest::assertNormalizationEdgeCases
Same name in other branches
- 9 core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDatetimeTest.php \Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDatetimeTest::assertNormalizationEdgeCases()
- 10 core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDatetimeTest.php \Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDatetimeTest::assertNormalizationEdgeCases()
- 11.x core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDatetimeTest.php \Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDatetimeTest::assertNormalizationEdgeCases()
Overrides EntityResourceTestBase::assertNormalizationEdgeCases
File
-
core/
modules/ datetime/ tests/ src/ Functional/ EntityResource/ EntityTest/ EntityTestDatetimeTest.php, line 138
Class
- EntityTestDatetimeTest
- Tests the datetime field constraint with 'datetime' items.
Namespace
Drupal\Tests\datetime\Functional\EntityResource\EntityTestCode
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
parent::assertNormalizationEdgeCases($method, $url, $request_options);
if ($this->entity
->getEntityType()
->hasKey('bundle')) {
$fieldName = static::$fieldName;
// DX: 422 when date type is incorrect.
$normalization = $this->getNormalizedPostEntity();
$normalization[static::$fieldName][0]['value'] = [
'2017',
'03',
'01',
'21',
'53',
'00',
];
$request_options[RequestOptions::BODY] = $this->serializer
->encode($normalization, static::$format);
$response = $this->request($method, $url, $request_options);
$message = "Unprocessable Entity: validation failed.\n{$fieldName}.0: The datetime value must be a string.\n{$fieldName}.0.value: This value should be of the correct primitive type.\n";
$this->assertResourceErrorResponse(422, $message, $response);
// DX: 422 when date format is incorrect.
$normalization = $this->getNormalizedPostEntity();
$value = '2017-03-01';
$normalization[static::$fieldName][0]['value'] = $value;
$request_options[RequestOptions::BODY] = $this->serializer
->encode($normalization, static::$format);
$response = $this->request($method, $url, $request_options);
$message = "The specified date \"{$value}\" is not in an accepted format: \"Y-m-d\\TH:i:sP\" (RFC 3339), \"Y-m-d\\TH:i:sO\" (ISO 8601), \"Y-m-d\\TH:i:s\" (backward compatibility — deprecated).";
$this->assertResourceErrorResponse(422, $message, $response);
// DX: 422 when date format is incorrect.
$normalization = $this->getNormalizedPostEntity();
$value = '2017-13-55T20:02:00';
$normalization[static::$fieldName][0]['value'] = $value;
$request_options[RequestOptions::BODY] = $this->serializer
->encode($normalization, static::$format);
$response = $this->request($method, $url, $request_options);
$message = "The specified date \"{$value}\" is not in an accepted format: \"Y-m-d\\TH:i:sP\" (RFC 3339), \"Y-m-d\\TH:i:sO\" (ISO 8601), \"Y-m-d\\TH:i:s\" (backward compatibility — deprecated).";
$this->assertResourceErrorResponse(422, $message, $response);
// DX: 422 when date value is invalid.
$normalization = $this->getNormalizedPostEntity();
$value = '2017-13-55T20:02:00+00:00';
$normalization[static::$fieldName][0]['value'] = $value;
$request_options[RequestOptions::BODY] = $this->serializer
->encode($normalization, static::$format);
$response = $this->request($method, $url, $request_options);
$message = "The specified date \"{$value}\" is not in an accepted format: \"Y-m-d\\TH:i:sP\" (RFC 3339), \"Y-m-d\\TH:i:sO\" (ISO 8601), \"Y-m-d\\TH:i:s\" (backward compatibility — deprecated).";
$this->assertResourceErrorResponse(422, $message, $response);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.