From a4bc9693af8afa1847d1e776558074eb9fa3dc3c Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 16 Apr 2010 07:48:15 +0000 Subject: [PATCH] unit tests MDL-22017 made test_usergetdate() work on machines in different timezones --- lib/simpletest/testmoodlelib.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/simpletest/testmoodlelib.php b/lib/simpletest/testmoodlelib.php index dd498bd0c8e67..28b37ffca9c59 100644 --- a/lib/simpletest/testmoodlelib.php +++ b/lib/simpletest/testmoodlelib.php @@ -263,9 +263,14 @@ function test_shorten_text() { } 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 - $arr = usergetdate($ts,1); + $arr = usergetdate($ts,1);//specify the timezone as an argument $arr = array_values($arr); list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr; @@ -280,20 +285,23 @@ function test_usergetdate() { $this->assertEqual($weekday,'Wednesday'); $this->assertEqual($month,'December'); - $arr = usergetdate($ts); + $arr = usergetdate($ts);//gets the timezone from the $USER object $arr = array_values($arr); list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr; $this->assertEqual($seconds,7); $this->assertEqual($minutes,51); - $this->assertEqual($hours,11); + $this->assertEqual($hours,5); $this->assertEqual($mday,23); $this->assertEqual($wday,3); $this->assertEqual($mon,12); $this->assertEqual($year,2009); - $this->assertEqual($yday,356); + $this->assertEqual($yday,357); $this->assertEqual($weekday,'Wednesday'); $this->assertEqual($month,'December'); + + //set the timezone back to what it was + $USER->timezone = $userstimezone; } }