mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Issue 8417:
Added support for array of tested browsers to be passed to ajaxenabled() Merged in from MOODLE_18_STABLE
This commit is contained in:
parent
d499142e5a
commit
c2a9fc9166
@ -106,10 +106,23 @@ function ajax_get_lib($libname) {
|
||||
/**
|
||||
* Returns whether ajax is enabled/allowed or not.
|
||||
*/
|
||||
function ajaxenabled() {
|
||||
function ajaxenabled($browsers = array()) {
|
||||
|
||||
global $CFG, $USER;
|
||||
|
||||
if (!empty($browsers)) {
|
||||
$valid = false;
|
||||
foreach ($browsers as $brand => $version) {
|
||||
if (check_browser_version($brand, $version)) {
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ie = check_browser_version('MSIE', 6.0);
|
||||
$ff = check_browser_version('Gecko', 20051106);
|
||||
$op = check_browser_version('Opera', 9.0);
|
||||
|
@ -87,6 +87,33 @@ class ajaxlib_test extends UnitTestCase {
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['5.5']['Windows 2000'];
|
||||
$this->assertFalse(ajaxenabled());
|
||||
|
||||
// Test array of tested browsers
|
||||
$tested_browsers = array('MSIE' => 6.0, 'Gecko' => 20061111);
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['2.0']['Windows XP'];
|
||||
$this->assertTrue(ajaxenabled($tested_browsers));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['7.0']['Windows XP SP2'];
|
||||
$this->assertTrue(ajaxenabled($tested_browsers));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Safari']['2.0']['Mac OS X'];
|
||||
$this->assertFalse(ajaxenabled($tested_browsers));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Opera']['9.0']['Windows XP'];
|
||||
$this->assertFalse(ajaxenabled($tested_browsers));
|
||||
|
||||
$tested_browsers = array('Safari' => 412, 'Opera' => 9.0);
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['2.0']['Windows XP'];
|
||||
$this->assertFalse(ajaxenabled($tested_browsers));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['7.0']['Windows XP SP2'];
|
||||
$this->assertFalse(ajaxenabled($tested_browsers));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Safari']['2.0']['Mac OS X'];
|
||||
$this->assertTrue(ajaxenabled($tested_browsers));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Opera']['9.0']['Windows XP'];
|
||||
$this->assertTrue(ajaxenabled($tested_browsers));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user