mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 02:46:40 +02:00
Merge branch 'wip-mdl-27759-integration-master' of git://github.com/rajeshtaneja/moodle
This commit is contained in:
commit
90333a972e
4 changed files with 47 additions and 4 deletions
|
@ -272,6 +272,13 @@ define('PARAM_FORMAT', 'alphanumext');
|
|||
*/
|
||||
define('PARAM_MULTILANG', 'text');
|
||||
|
||||
/**
|
||||
* PARAM_TIMEZONE - expected timezone. Timezone can be int +-(0-13) or float +-(0.5-12.5) or
|
||||
* string seperated by '/' and can have '-' &/ '_' (eg. America/North_Dakota/New_Salem
|
||||
* America/Port-au-Prince)
|
||||
*/
|
||||
define('PARAM_TIMEZONE', 'timezone');
|
||||
|
||||
/**
|
||||
* PARAM_CLEANFILE - deprecated alias of PARAM_FILE; originally was removing regional chars too
|
||||
*/
|
||||
|
@ -888,6 +895,14 @@ function clean_param($param, $type) {
|
|||
return '';
|
||||
}
|
||||
|
||||
case PARAM_TIMEZONE: //can be int, float(with .5 or .0) or string seperated by '/' and can have '-_'
|
||||
$timezonepattern = '/^(([+-]?(0?[0-9](\.[5|0])?|1[0-3]|1[0-2]\.5))|(99)|[[:alnum:]]+(\/?[[:alpha:]_-])+)$/';
|
||||
if (preg_match($timezonepattern, $param)) {
|
||||
return $param;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
default: // throw error, switched parameters in optional_param or another serious problem
|
||||
print_error("unknownparamtype", '', '', $type);
|
||||
}
|
||||
|
|
|
@ -444,6 +444,32 @@ class moodlelib_test extends UnitTestCase {
|
|||
$this->assertEqual(clean_param(' ', PARAM_STRINGID), '');
|
||||
}
|
||||
|
||||
function test_clean_param_timezone() {
|
||||
// Test timezone validation
|
||||
$testvalues = array (
|
||||
'America/Jamaica' => 'America/Jamaica',
|
||||
'America/Argentina/Cordoba' => 'America/Argentina/Cordoba',
|
||||
'America/Port-au-Prince' => 'America/Port-au-Prince',
|
||||
'America/Argentina/Buenos_Aires' => 'America/Argentina/Buenos_Aires',
|
||||
'PST8PDT' => 'PST8PDT',
|
||||
'Wrong.Value' => '',
|
||||
'Wrong/.Value' => '',
|
||||
'Wrong(Value)' => '',
|
||||
'0' => '0',
|
||||
'0.0' => '0.0',
|
||||
'0.5' => '0.5',
|
||||
'-12.5' => '-12.5',
|
||||
'+12.5' => '+12.5',
|
||||
'13.5' => '',
|
||||
'-13.5' => '',
|
||||
'0.2' => '');
|
||||
|
||||
foreach ($testvalues as $testvalue => $expectedvalue) {
|
||||
$actualvalue = clean_param($testvalue, PARAM_TIMEZONE);
|
||||
$this->assertEqual($actualvalue, $expectedvalue);
|
||||
}
|
||||
}
|
||||
|
||||
function test_validate_param() {
|
||||
try {
|
||||
$param = validate_param('11a', PARAM_INT);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue