Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443915
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443915
Commits
c2ad4bcd
Commit
c2ad4bcd
authored
7 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2865829
by mpdonadio: DateTimePlus test of validate_format = FALSE
parent
47d05218
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
+19
-0
19 additions, 0 deletions
...ests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
with
19 additions
and
0 deletions
core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
+
19
−
0
View file @
c2ad4bcd
...
...
@@ -759,4 +759,23 @@ public function providerTestInvalidConstructor() {
];
}
/**
* Tests the $settings['validate_format'] parameter in ::createFromFormat().
*/
public
function
testValidateFormat
()
{
// Check that an input that does not strictly follow the input format will
// produce the desired date. In this case the year string '11' doesn't
// precisely match the 'Y' formater parameter, but PHP will parse it
// regardless. However, when formatted with the same string, the year will
// be output with four digits. With the ['validate_format' => FALSE]
// $settings, this will not thrown an exception.
$date
=
DateTimePlus
::
createFromFormat
(
'Y-m-d H:i:s'
,
'11-03-31 17:44:00'
,
'UTC'
,
[
'validate_format'
=>
FALSE
]);
$this
->
assertEquals
(
'0011-03-31 17:44:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
// Parse the same date with ['validate_format' => TRUE] and make sure we
// get the expected exception.
$this
->
setExpectedException
(
\UnexpectedValueException
::
class
);
$date
=
DateTimePlus
::
createFromFormat
(
'Y-m-d H:i:s'
,
'11-03-31 17:44:00'
,
'UTC'
,
[
'validate_format'
=>
TRUE
]);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment