Skip to content

Commit

Permalink
Merge branch 'MDL-50687-master' of git://github.com/danpoltawski/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Nov 16, 2015
2 parents fb680f7 + 9680529 commit 53f8e45
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions lib/phpunit/classes/util.php
Expand Up @@ -131,6 +131,7 @@ public static function reset_all_data($detectchanges = false) {
}

$resetdb = self::reset_database();
$localename = self::get_locale_name();
$warnings = array();

if ($detectchanges === true) {
Expand Down Expand Up @@ -163,14 +164,8 @@ public static function reset_all_data($detectchanges = false) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}

if ($CFG->ostype === 'WINDOWS') {
if (setlocale(LC_TIME, 0) !== 'English_Australia.1252') {
$warnings[] = 'Warning: unexpected change of locale';
}
} else {
if (setlocale(LC_TIME, 0) !== 'en_AU.UTF-8') {
$warnings[] = 'Warning: unexpected change of locale';
}
if (setlocale(LC_TIME, 0) !== $localename) {
$warnings[] = 'Warning: unexpected change of locale';
}
}

Expand Down Expand Up @@ -262,11 +257,7 @@ public static function reset_all_data($detectchanges = false) {
core_date::phpunit_reset();

// Make sure the time locale is consistent - that is Australian English.
if ($CFG->ostype === 'WINDOWS') {
setlocale(LC_TIME, 'English_Australia.1252');
} else {
setlocale(LC_TIME, 'en_AU.UTF-8');
}
setlocale(LC_TIME, $localename);

// verify db writes just in case something goes wrong in reset
if (self::$lastdbwrites != $DB->perf_get_writes()) {
Expand Down Expand Up @@ -362,6 +353,11 @@ public static function get_global_backup($name) {
public static function testing_ready_problem() {
global $DB;

$localename = self::get_locale_name();
if (setlocale(LC_TIME, $localename) === false) {
return array(PHPUNIT_EXITCODE_CONFIGERROR, "Required locale '$localename' is not installed.");
}

if (!self::is_test_site()) {
// dataroot was verified in bootstrap, so it must be DB
return array(PHPUNIT_EXITCODE_CONFIGERROR, 'Can not use database for testing, try different prefix');
Expand Down Expand Up @@ -798,4 +794,19 @@ public static function event_triggered(\core\event\base $event) {
self::$eventsink->add_event($event);
}
}

/**
* Gets the name of the locale for testing environment (Australian English)
* depending on platform environment.
*
* @return string the locale name.
*/
protected static function get_locale_name() {
global $CFG;
if ($CFG->ostype === 'WINDOWS') {
return 'English_Australia.1252';
} else {
return 'en_AU.UTF-8';
}
}
}

0 comments on commit 53f8e45

Please sign in to comment.