| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/locale/locale.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 7 8 /** 9 * \ingroup Test 10 * 11 * Test cases for the Locale class. 12 */ 13 class Locale_Test extends LifeTypeTestCase 14 { 15 var $l; 16 17 function setUp() 18 { 19 // let's use the English locale as the base one 20 $this->l = new Locale( "en_UK" ); 21 } 22 23 /** 24 * test all the modifiers from the Locale::formatDate() method: 25 * 26 * <li>%a abbreviated weekday</li> 27 * <li>%A complete weekday</li> 28 * <li>%b abbreviated month</li> 29 * <li>%B long month</li> 30 * <li>%d day of the month, 2 digits with leading zero</li> 31 * <li>%j day of the month, numeric (without leading zero)</li> 32 * <li>%H hours, in 24-h format</li> 33 * <li>%I hours, in 12-h format (without leading zero)</li> 34 * <li>%p returns 'am' or 'pm'</li> 35 * <li>%P returns 'AM' or 'PM'</li> 36 * <li>%M minutes</li> 37 * <li>%m month number, from 00 to 12</li> 38 * <li>%S seconds</li> 39 * <li>%y 2-digit year representation</li> 40 * <li>%Y 4-digit year representation</li> 41 * <li>%O Difference to Greenwich time (GMT) in hours</li> 42 * <li>%% the '%' character 43 * </ul> 44 * (these have been added by myself and are therefore incompatible with php)<ul> 45 * <li>%T "_day_ of _month_", where the day is in ordinal form and 'month' is the name of the month</li> 46 * <li>%D cardinal representation of the day</li> 47 */ 48 function testFormatDate() 49 { 50 $d = new Timestamp( "20070205230000" ); 51 52 $this->assertEquals( "Mon", $this->l->formatDate( $d, "%a" )); 53 $this->assertEquals( "Monday", $this->l->formatDate( $d, "%A" )); 54 $this->assertEquals( "Feb", $this->l->formatDate( $d, "%b" )); 55 $this->assertEquals( "February", $this->l->formatDate( $d, "%B" )); 56 $this->assertEquals( "05", $this->l->formatDate( $d, "%d" )); 57 $this->assertEquals( "5", $this->l->formatDate( $d, "%j" )); 58 $this->assertEquals( "23", $this->l->formatDate( $d, "%H" )); 59 $this->assertEquals( "11", $this->l->formatDate( $d, "%I" )); 60 $this->assertEquals( "pm", $this->l->formatDate( $d, "%p" )); 61 $this->assertEquals( "PM", $this->l->formatDate( $d, "%P" )); 62 $this->assertEquals( "00", $this->l->formatDate( $d, "%M" )); 63 $this->assertEquals( "02", $this->l->formatDate( $d, "%m" )); 64 $this->assertEquals( "00", $this->l->formatDate( $d, "%S" )); 65 $this->assertEquals( "07", $this->l->formatDate( $d, "%y" )); 66 $this->assertEquals( "2007", $this->l->formatDate( $d, "%Y" )); 67 $this->assertEquals( "%", $this->l->formatDate( $d, "%%" )); 68 $this->assertEquals( "5th of February", $this->l->formatDate( $d, "%T" )); 69 $this->assertEquals( "5th", $this->l->formatDate( $d, "%D" )); 70 71 // a longer format test 72 $this->assertEquals( "Feb ", $this->l->formatDate( $d, "%b " )); 73 $this->assertEquals( "Feb 5", $this->l->formatDate( $d, "%b %j" )); 74 $this->assertEquals( "05/02/2007", $this->l->formatDate( $d, "%d/%m/%Y" )); 75 $this->assertEquals( "05 February, 2007 23:00", $this->l->formatDate( $d, "%d %B, %Y %H:%M" )); 76 } 77 78 /** 79 * Tests that the Locale::testFormatDateGMT() method also behaves 80 * as expected 81 */ 82 function testFormatDateGMT() 83 { 84 $d = new Timestamp( "20070205230000" ); 85 86 $this->assertEquals( "Mon", $this->l->formatDateGMT( $d, "%a" )); 87 $this->assertEquals( "Monday", $this->l->formatDateGMT( $d, "%A" )); 88 $this->assertEquals( "Feb", $this->l->formatDateGMT( $d, "%b" )); 89 $this->assertEquals( "February", $this->l->formatDateGMT( $d, "%B" )); 90 $this->assertEquals( "05", $this->l->formatDateGMT( $d, "%d" )); 91 $this->assertEquals( "5", $this->l->formatDateGMT( $d, "%j" )); 92 $this->assertEquals( "21", $this->l->formatDateGMT( $d, "%H" )); 93 $this->assertEquals( "9", $this->l->formatDateGMT( $d, "%I" )); 94 $this->assertEquals( "pm", $this->l->formatDateGMT( $d, "%p" )); 95 $this->assertEquals( "PM", $this->l->formatDateGMT( $d, "%P" )); 96 $this->assertEquals( "00", $this->l->formatDateGMT( $d, "%M" )); 97 $this->assertEquals( "02", $this->l->formatDateGMT( $d, "%m" )); 98 $this->assertEquals( "00", $this->l->formatDateGMT( $d, "%S" )); 99 $this->assertEquals( "07", $this->l->formatDateGMT( $d, "%y" )); 100 $this->assertEquals( "2007", $this->l->formatDateGMT( $d, "%Y" )); 101 $this->assertEquals( "%", $this->l->formatDateGMT( $d, "%%" )); 102 $this->assertEquals( "5th of February", $this->l->formatDateGMT( $d, "%T" )); 103 $this->assertEquals( "5th", $this->l->formatDateGMT( $d, "%D" )); 104 105 // a longer format test 106 $this->assertEquals( "Feb ", $this->l->formatDateGMT( $d, "%b " )); 107 $this->assertEquals( "Feb 5", $this->l->formatDateGMT( $d, "%b %j" )); 108 $this->assertEquals( "05/02/2007", $this->l->formatDateGMT( $d, "%d/%m/%Y" )); 109 $this->assertEquals( "05 February, 2007 21:00", $this->l->formatDateGMT( $d, "%d %B, %Y %H:%M" )); 110 } 111 } 112 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|