Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This patch was originally inside of a really large patch, was suggested to split into smaller patches.
Tests needed: common.inc
http://drupal.org/node/276272
Comment | File | Size | Author |
---|---|---|---|
#11 | format_date_test.patch | 4.29 KB | mfb |
#10 | format_date_test.patch | 5 KB | mfb |
#8 | format_date_test.patch | 4.28 KB | mfb |
#7 | format_date_test.patch | 4.41 KB | mfb |
format_date_test_1.patch | 4.74 KB | grndlvl | |
Comments
Comment #1
grndlvl CreditAttribution: grndlvl commentedJust getting same priority as parent task.
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is not an unit test: a proper unit test assert that the result of a function call is identical to the known expected behavior. Comparing the result of format_date() (that uses gmdate() internally) to the result of gmdate() has no real purpose.
What you should do here is prepare an test case of some specific date values and their known text representations, and use that to verify that format_date() works correctly. Including some known corner-case values is of course better (leap years, days with leap seconds, negative timestamp values, etc.).
Comment #3
grndlvl CreditAttribution: grndlvl commentedI do not believe so that would be going through and testing out what gmdate() does internally to drupal, this is to check the 'Format of the date' based on drupal parameters such as localized time.
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis makes even less sense. In a nutshell you are currently doing (simplified version of your assertFormatDate):
So (1) you are assuming that the current language is english, and (2) you are basically testing only one line of
format_date()
, the one that does:Comment #5
grndlvl CreditAttribution: grndlvl commentedIt is the whole purpose of the function format_date to
Which I fell this unit test does test the functionality of format_date.
Also I feel your proposed solution would be the same other than the addition of checking gmmdate as well or am I overlooking something.
Comment #6
mfbHere's a fresh start on format_date() unit tests.
Comment #7
mfbdrupal.org ate my patch :(
Comment #8
mfbRemoved some debug code from the assertions.
Comment #9
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #10
mfbSome of these assertions fail if the test environment has spanish language installed. I modified it to create a custom language "xx".
Comment #11
mfbAdd a test for backslash followed by escaped format string.
Comment #12
jrchamp CreditAttribution: jrchamp commented@mfb: Thank you for pointing me in the right direction. That patch looks great and should be reasonably effective in identifying issues with the format_date function.
I think that it might be worthwhile to add an "every special format character" test condition, i.e:
That was the condition that resulted in my adding 0-9, + and : to the regex.
It occurred to me that numbers would be an issue when I visited the "List of Supported Timezones" "Others" page.
Comment #13
mfb@jrchamp: There shouldn't be any numbers colons or plus signs because Drupal doesn't allow the "Other" time zones to be configured. As it says, "Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons." The only way they would show up was someone manually hacking their database :)
Comment #14
jrchamp CreditAttribution: jrchamp commented@mfb: Nice catch! It turns out that if you don't call date_timezone_set(), it returns "July PM pm +00:00 Wed Wednesday Jul GMT+0000" instead of "July PM pm UTC Wed Wednesday Jul UTC". Thankfully this shouldn't happen.
Comment #15
Dries CreditAttribution: Dries commentedI committed the patch at #11 because it is an improvement. I'm _not_ marking this fix because we have follow-up patches to make.
Comment #17
Dries CreditAttribution: Dries commented