mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Safari 2.0 and Opera 9.0 are now detected and supported for YUI. However, preliminary tests show that drag&drop behaviour is very slow on Opera and user-unfriendly on both browsers. A YUI debug window also pops up on Safari.
I added a unit test for ajaxlib.php Issue MDL-8417 Merged from MOODLE_18_STABLE
This commit is contained in:
parent
f155c563d8
commit
d499142e5a
@ -109,10 +109,15 @@ function ajax_get_lib($libname) {
|
||||
function ajaxenabled() {
|
||||
|
||||
global $CFG, $USER;
|
||||
|
||||
$ie = check_browser_version('MSIE', 6.0);
|
||||
$ff = check_browser_version('Gecko', 20051106);
|
||||
$op = check_browser_version('Opera', 9.0);
|
||||
$sa = check_browser_version('Safari', 412);
|
||||
|
||||
if (!check_browser_version('MSIE', 6.0)
|
||||
&& !check_browser_version('Gecko', 20051111)) {
|
||||
// Gecko build 20051111 is what is in Firefox 1.5.
|
||||
if (!$ie && !$ff && !$op && !$sa) {
|
||||
/** @see http://en.wikipedia.org/wiki/User_agent */
|
||||
// Gecko build 20051107 is what is in Firefox 1.5.
|
||||
// We still have issues with AJAX in other browsers.
|
||||
return false;
|
||||
}
|
||||
|
57
lib/simpletest/fixtures/user_agents.php
Normal file
57
lib/simpletest/fixtures/user_agents.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* An array of possible user_agent strings.
|
||||
*
|
||||
* @TODO Complete that list using http://www.pgts.com.au/pgtsj/pgtsj0208c.html
|
||||
* OR make this test function dynamic by pulling out strings from a server somewhere,
|
||||
* then testing each of them against the check_browser_version function.
|
||||
*/
|
||||
|
||||
$user_agents = array(
|
||||
'MSIE' => array(
|
||||
'5.5' => array('Windows 2000' => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'),
|
||||
'6.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'),
|
||||
'7.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)')
|
||||
),
|
||||
'Firefox' => array(
|
||||
'1.0.6' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6'),
|
||||
'1.5' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'),
|
||||
'1.5.0.1' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'),
|
||||
'2.0' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
|
||||
'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)')
|
||||
),
|
||||
'Safari' => array(
|
||||
'312' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'),
|
||||
'2.0' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412')
|
||||
),
|
||||
'Opera' => array(
|
||||
'8.51' => array('Windows XP' => 'Opera/8.51 (Windows NT 5.1; U; en)'),
|
||||
'9.0' => array('Windows XP' => 'Opera/9.0 (Windows NT 5.1; U; en)',
|
||||
'Debian Linux' => 'Opera/9.01 (X11; Linux i686; U; en)')
|
||||
)
|
||||
);
|
||||
?>
|
93
lib/simpletest/testajaxlib.php
Normal file
93
lib/simpletest/testajaxlib.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Unit tests for (some of) ../ajax/ajaxlib.php.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @author nicolas@moodle.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package moodlecore
|
||||
*/
|
||||
|
||||
/** $Id */
|
||||
require_once(dirname(__FILE__) . '/../../config.php');
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/simpletestlib.php');
|
||||
require_once($CFG->libdir . '/moodlelib.php');
|
||||
require_once($CFG->libdir . '/ajax/ajaxlib.php');
|
||||
|
||||
class ajaxlib_test extends UnitTestCase {
|
||||
|
||||
function setUp() {
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the array of user agents to test ajax_lib::ajaxenabled
|
||||
*/
|
||||
function test_ajaxenabled()
|
||||
{
|
||||
global $CFG, $USER;
|
||||
$CFG->enableajax = true;
|
||||
$USER->ajax = true;
|
||||
|
||||
require_once($CFG->libdir . '/simpletest/fixtures/user_agents.php');
|
||||
|
||||
// Should be true
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['2.0']['Windows XP'];
|
||||
$this->assertTrue(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['1.5']['Windows XP'];
|
||||
$this->assertTrue(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Safari']['2.0']['Mac OS X'];
|
||||
$this->assertTrue(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Opera']['9.0']['Windows XP'];
|
||||
$this->assertTrue(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['6.0']['Windows XP SP2'];
|
||||
$this->assertTrue(ajaxenabled());
|
||||
|
||||
// Should be false
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['1.0.6']['Windows XP'];
|
||||
$this->assertFalse(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Safari']['312']['Mac OS X'];
|
||||
$this->assertFalse(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Opera']['8.51']['Windows XP'];
|
||||
$this->assertFalse(ajaxenabled());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['5.5']['Windows 2000'];
|
||||
$this->assertFalse(ajaxenabled());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,9 +1,34 @@
|
||||
<?php
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Unit tests for (some of) ../moodlelib.php.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @author T.J.Hunt@open.ac.uk
|
||||
* @author nicolas@moodle.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package moodlecore
|
||||
*/
|
||||
@ -17,30 +42,6 @@ require_once($CFG->libdir . '/moodlelib.php');
|
||||
|
||||
class moodlelib_test extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* An array of possible user_agent strings
|
||||
*
|
||||
* @var array possible user_agent strings
|
||||
* @TODO Complete that list using http://www.pgts.com.au/pgtsj/pgtsj0208c.html
|
||||
*/
|
||||
var $user_agents = array(
|
||||
'MSIE' => array(
|
||||
'6.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'),
|
||||
'7.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)')
|
||||
),
|
||||
'Firefox' => array(
|
||||
'1.5' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'),
|
||||
'2.0' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1')
|
||||
),
|
||||
'Safari' => array(
|
||||
'2.0' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412'),
|
||||
'312' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312')
|
||||
),
|
||||
'Opera' => array(
|
||||
'9.0' => array('Windows XP' => 'Opera/9.0 (Windows NT 5.1; U; en)')
|
||||
)
|
||||
);
|
||||
|
||||
function setUp() {
|
||||
}
|
||||
|
||||
@ -80,22 +81,25 @@ class moodlelib_test extends UnitTestCase {
|
||||
*/
|
||||
function test_check_browser_version()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
|
||||
require_once($CFG->libdir . '/simpletest/fixtures/user_agents.php');
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Safari']['2.0']['Mac OS X'];
|
||||
var_dump($_SERVER['HTTP_USER_AGENT']);
|
||||
$this->assertTrue(check_browser_version('Safari', '312'));
|
||||
$this->assertFalse(check_browser_version('Safari', '500'));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Opera']['9.0']['Windows XP'];
|
||||
$this->assertTrue(check_browser_version('Opera', '8.0'));
|
||||
$this->assertFalse(check_browser_version('Opera', '10.0'));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['6.0']['Windows XP SP2'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['6.0']['Windows XP SP2'];
|
||||
$this->assertTrue(check_browser_version('MSIE', '5.0'));
|
||||
$this->assertFalse(check_browser_version('MSIE', '7.0'));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['2.0']['Windows XP'];
|
||||
$this->assertTrue(check_browser_version('Firefox', '1.5'));
|
||||
$this->assertFalse(check_browser_version('Firefox', '3.0'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user