Skip to content

Commit

Permalink
MDL-27863 moodlelib - fixed testcase faliure in MDL-27577
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Jun 15, 2011
1 parent 1de5024 commit de5da04
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions lib/simpletest/testmoodlelib.php
Expand Up @@ -371,19 +371,7 @@ public function test_userdate() {
'usertimezone' => '-10', 'usertimezone' => '-10',
'timezone' => '-2', //take this timezone 'timezone' => '-2', //take this timezone
'expectedoutput' => 'Saturday, 1 January 2011, 08:00 AM' 'expectedoutput' => 'Saturday, 1 January 2011, 08:00 AM'
), )
array(
'time' => '1293876000 ',
'usertimezone' => '-10',
'timezone' => 'random/time', //this should show server time
'expectedoutput' => 'Saturday, 1 January 2011, 06:00 PM'
),
array(
'time' => '1293876000 ',
'usertimezone' => '14', //server time zone
'timezone' => '99', //this should show user time
'expectedoutput' => 'Saturday, 1 January 2011, 06:00 PM'
),
); );


//Check if forcetimezone is set then save it and set it to use user timezone //Check if forcetimezone is set then save it and set it to use user timezone
Expand All @@ -400,9 +388,16 @@ public function test_userdate() {
$oldlocale = setlocale(LC_TIME, '0'); $oldlocale = setlocale(LC_TIME, '0');
setlocale(LC_TIME, 'en_AU.UTF-8'); setlocale(LC_TIME, 'en_AU.UTF-8');


//get instance of textlib for strtolower
$textlib = textlib_get_instance();
foreach ($testvalues as $vals) { foreach ($testvalues as $vals) {
$USER->timezone = $vals['usertimezone']; $USER->timezone = $vals['usertimezone'];
$actualoutput = userdate($vals['time'], '%A, %d %B %Y, %I:%M %p', $vals['timezone']); $actualoutput = userdate($vals['time'], '%A, %d %B %Y, %I:%M %p', $vals['timezone']);

//On different systems case of AM PM changes so compare case insenitive
$vals['expectedoutput'] = $textlib->strtolower($vals['expectedoutput']);
$actualoutput = $textlib->strtolower($actualoutput);

$this->assertEqual($vals['expectedoutput'], $actualoutput, $this->assertEqual($vals['expectedoutput'], $actualoutput,
"Expected: {$vals['expectedoutput']} => Actual: {$actualoutput}, "Expected: {$vals['expectedoutput']} => Actual: {$actualoutput},
Please check if timezones are updated (Site adminstration -> location -> update timezone)"); Please check if timezones are updated (Site adminstration -> location -> update timezone)");
Expand All @@ -416,6 +411,7 @@ public function test_userdate() {
$CFG->forcetimezone = $cfgforcetimezone; $CFG->forcetimezone = $cfgforcetimezone;
} }


//restore system default values.
setlocale(LC_TIME, $oldlocale); setlocale(LC_TIME, $oldlocale);
} }


Expand Down Expand Up @@ -518,30 +514,6 @@ public function test_make_timestamp() {
'timezone' => '-2', //take this timezone 'timezone' => '-2', //take this timezone
'applydst' => true, //apply dst, 'applydst' => true, //apply dst,
'expectedoutput' => '1309521600' 'expectedoutput' => '1309521600'
),
array(
'usertimezone' => '-10',//no dst applyed
'year' => '2011',
'month' => '7',
'day' => '1',
'hour' => '10',
'minutes' => '00',
'seconds' => '00',
'timezone' => 'random/time', //This should show server time
'applydst' => true, //apply dst,
'expectedoutput' => '1309485600'
),
array(
'usertimezone' => '14',//server time
'year' => '2011',
'month' => '7',
'day' => '1',
'hour' => '10',
'minutes' => '00',
'seconds' => '00',
'timezone' => '99', //get user time
'applydst' => true, //apply dst,
'expectedoutput' => '1309485600'
) )
); );


Expand All @@ -560,6 +532,8 @@ public function test_make_timestamp() {
$oldlocale = setlocale(LC_TIME, '0'); $oldlocale = setlocale(LC_TIME, '0');
setlocale(LC_TIME, 'en_AU.UTF-8'); setlocale(LC_TIME, 'en_AU.UTF-8');


//get instance of textlib for strtolower
$textlib = textlib_get_instance();
//Test make_timestamp with all testvals and assert if anything wrong. //Test make_timestamp with all testvals and assert if anything wrong.
foreach ($testvalues as $vals) { foreach ($testvalues as $vals) {
$USER->timezone = $vals['usertimezone']; $USER->timezone = $vals['usertimezone'];
Expand All @@ -574,6 +548,10 @@ public function test_make_timestamp() {
$vals['applydst'] $vals['applydst']
); );


//On different systems case of AM PM changes so compare case insenitive
$vals['expectedoutput'] = $textlib->strtolower($vals['expectedoutput']);
$actualoutput = $textlib->strtolower($actualoutput);

$this->assertEqual($vals['expectedoutput'], $actualoutput, $this->assertEqual($vals['expectedoutput'], $actualoutput,
"Expected: {$vals['expectedoutput']} => Actual: {$actualoutput}, "Expected: {$vals['expectedoutput']} => Actual: {$actualoutput},
Please check if timezones are updated (Site adminstration -> location -> update timezone)"); Please check if timezones are updated (Site adminstration -> location -> update timezone)");
Expand All @@ -587,7 +565,8 @@ public function test_make_timestamp() {
$CFG->forcetimezone = $cfgforcetimezone; $CFG->forcetimezone = $cfgforcetimezone;
} }


//restore system default values.
setlocale(LC_TIME, $oldlocale); setlocale(LC_TIME, $oldlocale);
} }
} }
?> ?>

0 comments on commit de5da04

Please sign in to comment.