r107814 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107813‎ | r107814 | r107815 >
Date:10:41, 2 January 2012
Author:bawolff
Status:ok
Tags:
Comment:
Follow-up r107806 - More extensive tests for Language::sprintfDate. Including test to make sure not affected by php timezone.

Also adds a small test for converting numerals (formatNum) in Arabic.
Modified paths:
  • /trunk/phase3/tests/phpunit/languages/LanguageArTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/languages/LanguageTest.php
@@ -207,7 +207,26 @@
208208 "sprintfDate('$format', '$ts'): $msg"
209209 );
210210 }
 211+ /**
 212+ * bug 33454. sprintfDate should always use UTC.
 213+ * @dataProvider provideSprintfDateSamples
 214+ */
 215+ function testSprintfDateTZ( $format, $ts, $expected, $msg ) {
 216+ $oldTZ = date_default_timezone_get();
 217+ $res = date_default_timezone_set( 'Asia/Seoul' );
 218+ if ( !$res ) {
 219+ $this->markTestSkipped( "Error setting Timezone" );
 220+ }
211221
 222+ $this->assertEquals(
 223+ $expected,
 224+ $this->lang->sprintfDate( $format, $ts ),
 225+ "sprintfDate('$format', '$ts'): $msg"
 226+ );
 227+
 228+ date_default_timezone_set( $oldTZ );
 229+ }
 230+
212231 function provideSprintfDateSamples() {
213232 return array(
214233 array(
@@ -222,6 +241,284 @@
223242 '90',
224243 'Iranian calendar short year'
225244 ),
 245+ array(
 246+ 'o',
 247+ '20120101235000',
 248+ '2011',
 249+ 'ISO 8601 (week) year'
 250+ ),
 251+ array(
 252+ 'W',
 253+ '20120101235000',
 254+ '52',
 255+ 'Week number'
 256+ ),
 257+ array(
 258+ 'W',
 259+ '20120102235000',
 260+ '1',
 261+ 'Week number'
 262+ ),
 263+ array(
 264+ 'o-\\WW-N',
 265+ '20091231235000',
 266+ '2009-W53-4',
 267+ 'leap week'
 268+ ),
 269+ // What follows is mostly copied from http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time
 270+ array(
 271+ 'Y',
 272+ '20120102090705',
 273+ '2012',
 274+ 'Full year'
 275+ ),
 276+ array(
 277+ 'y',
 278+ '20120102090705',
 279+ '12',
 280+ '2 digit year'
 281+ ),
 282+ array(
 283+ 'L',
 284+ '20120102090705',
 285+ '1',
 286+ 'Leap year'
 287+ ),
 288+ array(
 289+ 'n',
 290+ '20120102090705',
 291+ '1',
 292+ 'Month index, not zero pad'
 293+ ),
 294+ array(
 295+ 'N',
 296+ '20120102090705',
 297+ '01',
 298+ 'Month index. Zero pad'
 299+ ),
 300+ array(
 301+ 'M',
 302+ '20120102090705',
 303+ 'Jan',
 304+ 'Month abbrev'
 305+ ),
 306+ array(
 307+ 'F',
 308+ '20120102090705',
 309+ 'January',
 310+ 'Full month'
 311+ ),
 312+ array(
 313+ 'xg',
 314+ '20120102090705',
 315+ 'January',
 316+ 'Genitive month name (same in EN)'
 317+ ),
 318+ array(
 319+ 'j',
 320+ '20120102090705',
 321+ '2',
 322+ 'Day of month (not zero pad)'
 323+ ),
 324+ array(
 325+ 'd',
 326+ '20120102090705',
 327+ '02',
 328+ 'Day of month (zero-pad)'
 329+ ),
 330+ array(
 331+ 'z',
 332+ '20120102090705',
 333+ '1',
 334+ 'Day of year (zero-indexed)'
 335+ ),
 336+ array(
 337+ 'D',
 338+ '20120102090705',
 339+ 'Mon',
 340+ 'Day of week (abbrev)'
 341+ ),
 342+ array(
 343+ 'l',
 344+ '20120102090705',
 345+ 'Monday',
 346+ 'Full day of week'
 347+ ),
 348+ array(
 349+ 'N',
 350+ '20120101090705',
 351+ '7',
 352+ 'Day of week (Mon=1, Sun=7)'
 353+ ),
 354+ array(
 355+ 'w',
 356+ '20120101090705',
 357+ '0',
 358+ 'Day of week (Sun=0, Sat=6)'
 359+ ),
 360+ array(
 361+ 'N',
 362+ '20120102090705',
 363+ '1',
 364+ 'Day of week'
 365+ ),
 366+ array(
 367+ 'a',
 368+ '20120102090705',
 369+ 'am',
 370+ 'am vs pm'
 371+ ),
 372+ array(
 373+ 'A',
 374+ '20120102120000',
 375+ 'PM',
 376+ 'AM vs PM'
 377+ ),
 378+ array(
 379+ 'a',
 380+ '20120102000000',
 381+ 'am',
 382+ 'AM vs PM'
 383+ ),
 384+ array(
 385+ 'g',
 386+ '20120102090705',
 387+ '9',
 388+ '12 hour, not Zero'
 389+ ),
 390+ array(
 391+ 'h',
 392+ '20120102090705',
 393+ '09',
 394+ '12 hour, zero padded'
 395+ ),
 396+ array(
 397+ 'G',
 398+ '20120102090705',
 399+ '9',
 400+ '24 hour, not zero'
 401+ ),
 402+ array(
 403+ 'H',
 404+ '20120102090705',
 405+ '09',
 406+ '24 hour, zero'
 407+ ),
 408+ array(
 409+ 'H',
 410+ '20120102110705',
 411+ '11',
 412+ '24 hour, zero'
 413+ ),
 414+ array(
 415+ 'i',
 416+ '20120102090705',
 417+ '07',
 418+ 'Minutes'
 419+ ),
 420+ array(
 421+ 's',
 422+ '20120102090705',
 423+ '05',
 424+ 'seconds'
 425+ ),
 426+ array(
 427+ 'U',
 428+ '20120102090705',
 429+ '1325495225',
 430+ 'unix time'
 431+ ),
 432+ array(
 433+ 't',
 434+ '20120102090705',
 435+ '31',
 436+ 'Days in current month'
 437+ ),
 438+ array(
 439+ 'c',
 440+ '20120102090705',
 441+ '2012-01-02T09:07:05+00:00',
 442+ 'ISO 8601 timestamp'
 443+ ),
 444+ array(
 445+ 'r',
 446+ '20120102090705',
 447+ 'Mon, 02 Jan 2012 09:07:05 +0000',
 448+ 'RFC 5322'
 449+ ),
 450+ array(
 451+ 'xmj xmF xmn xmY',
 452+ '20120102090705',
 453+ '7 Safar 2 1433',
 454+ 'Islamic'
 455+ ),
 456+ array(
 457+ 'xij xiF xin xiY',
 458+ '20120102090705',
 459+ '12 Dey 10 1390',
 460+ 'Iranian'
 461+ ),
 462+ array(
 463+ 'xjj xjF xjn xjY',
 464+ '20120102090705',
 465+ '7 Tevet 4 5772',
 466+ 'Hebrew'
 467+ ),
 468+ array(
 469+ 'xjt',
 470+ '20120102090705',
 471+ '29',
 472+ 'Hebrew number of days in month'
 473+ ),
 474+ array(
 475+ 'xjx',
 476+ '20120102090705',
 477+ 'Tevet',
 478+ 'Hebrew genitive month name (No difference in EN)'
 479+ ),
 480+ array(
 481+ 'xkY',
 482+ '20120102090705',
 483+ '2555',
 484+ 'Thai year'
 485+ ),
 486+ array(
 487+ 'xoY',
 488+ '20120102090705',
 489+ '101',
 490+ 'Minguo'
 491+ ),
 492+ array(
 493+ 'xtY',
 494+ '20120102090705',
 495+ '平成24',
 496+ 'nengo'
 497+ ),
 498+ array(
 499+ 'xrxkYY',
 500+ '20120102090705',
 501+ 'MMDLV2012',
 502+ 'Roman numerals'
 503+ ),
 504+ array(
 505+ 'xhxjYY',
 506+ '20120102090705',
 507+ 'ה\'תשע"ב2012',
 508+ 'Hebrew numberals'
 509+ ),
 510+ array(
 511+ 'xnY',
 512+ '20120102090705',
 513+ '2012',
 514+ 'Raw numerals (doesn\'t mean much in EN)'
 515+ ),
 516+ array(
 517+ '[[Y "(yea"\\r)]] \\"xx\\"',
 518+ '20120102090705',
 519+ '[[2012 (year)]] "x"',
 520+ 'Various escaping'
 521+ ),
 522+
226523 );
227524 }
228525
Index: trunk/phase3/tests/phpunit/languages/LanguageArTest.php
@@ -0,0 +1,55 @@
 2+<?php
 3+/**
 4+ * Based on LanguagMlTest
 5+ * @file
 6+ */
 7+
 8+/** Tests for MediaWiki languages/LanguageAr.php */
 9+class LanguageArTest extends MediaWikiTestCase {
 10+ private $lang;
 11+
 12+ function setUp() {
 13+ $this->lang = Language::factory( 'Ar' );
 14+ }
 15+ function tearDown() {
 16+ unset( $this->lang );
 17+ }
 18+
 19+ function testFormatNum() {
 20+ $this->assertEquals( '١٬٢٣٤٬٥٦٧', $this->lang->formatNum( '1234567' ) );
 21+ $this->assertEquals( '-١٢٫٨٩', $this->lang->formatNum( -12.89 ) );
 22+ }
 23+
 24+ /**
 25+ * Mostly to test the raw ascii feature.
 26+ * @dataProvider providerSprintfDate
 27+ */
 28+ function testSprintfDate( $format, $date, $expected ) {
 29+ $this->assertEquals( $expected, $this->lang->sprintfDate( $format, $date ) );
 30+ }
 31+
 32+ function providerSprintfDate() {
 33+ return array(
 34+ array(
 35+ 'xg "vs" g',
 36+ '20120102030410',
 37+ 'يناير vs ٣'
 38+ ),
 39+ array(
 40+ 'xmY',
 41+ '20120102030410',
 42+ '١٤٣٣'
 43+ ),
 44+ array(
 45+ 'xnxmY',
 46+ '20120102030410',
 47+ '1433'
 48+ ),
 49+ array(
 50+ 'xN xmj xmn xN xmY',
 51+ '20120102030410',
 52+ ' 7 2 ١٤٣٣'
 53+ ),
 54+ );
 55+ }
 56+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageArTest.php
___________________________________________________________________
Added: svn:eol-style
157 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107806(Half of bug 33454) The week based year number (format char 'o') was being ca...bawolff08:20, 2 January 2012

Status & tagging log