Skip to content

Commit

Permalink
unit tests MDL-22017 made test_usergetdate() work on machines in diff…
Browse files Browse the repository at this point in the history
…erent timezones
  • Loading branch information
Andrew Davis committed Apr 16, 2010
1 parent 192dcd8 commit a4bc969
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/simpletest/testmoodlelib.php
Expand Up @@ -263,9 +263,14 @@ function test_shorten_text() {
} }


function test_usergetdate() { function test_usergetdate() {
global $USER;

$userstimezone = $USER->timezone;
$USER->timezone = 2;//set the timezone to a known state

$ts = 1261540267; //the time this function was created $ts = 1261540267; //the time this function was created


$arr = usergetdate($ts,1); $arr = usergetdate($ts,1);//specify the timezone as an argument
$arr = array_values($arr); $arr = array_values($arr);


list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr; list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
Expand All @@ -280,20 +285,23 @@ function test_usergetdate() {
$this->assertEqual($weekday,'Wednesday'); $this->assertEqual($weekday,'Wednesday');
$this->assertEqual($month,'December'); $this->assertEqual($month,'December');


$arr = usergetdate($ts); $arr = usergetdate($ts);//gets the timezone from the $USER object
$arr = array_values($arr); $arr = array_values($arr);


list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr; list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
$this->assertEqual($seconds,7); $this->assertEqual($seconds,7);
$this->assertEqual($minutes,51); $this->assertEqual($minutes,51);
$this->assertEqual($hours,11); $this->assertEqual($hours,5);
$this->assertEqual($mday,23); $this->assertEqual($mday,23);
$this->assertEqual($wday,3); $this->assertEqual($wday,3);
$this->assertEqual($mon,12); $this->assertEqual($mon,12);
$this->assertEqual($year,2009); $this->assertEqual($year,2009);
$this->assertEqual($yday,356); $this->assertEqual($yday,357);
$this->assertEqual($weekday,'Wednesday'); $this->assertEqual($weekday,'Wednesday');
$this->assertEqual($month,'December'); $this->assertEqual($month,'December');

//set the timezone back to what it was
$USER->timezone = $userstimezone;
} }


} }
Expand Down

0 comments on commit a4bc969

Please sign in to comment.