unit tests MDL-22017 made test_usergetdate() work on machines in different timezones
authorAndrew Davis <andrew@affinitysoftware.net>
Fri, 16 Apr 2010 07:47:39 +0000 (07:47 +0000)
committerAndrew Davis <andrew@affinitysoftware.net>
Fri, 16 Apr 2010 07:47:39 +0000 (07:47 +0000)
lib/simpletest/testmoodlelib.php

index 8ee0c2c..152d56f 100644 (file)
@@ -417,9 +417,14 @@ class moodlelib_test extends UnitTestCase {
     }
 
     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);
 
         list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
         $arr = array_values($arr);
 
         list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
@@ -434,19 +439,22 @@ class moodlelib_test extends UnitTestCase {
         $this->assertEqual($weekday,'Wednesday');
         $this->assertEqual($month,'December');
 
         $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);
         $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($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');
         $this->assertEqual($weekday,'Wednesday');
         $this->assertEqual($month,'December');
+
+        //set the timezone back to what it was
+        $USER->timezone = $userstimezone;
     }
 }
     }
 }