]> git.mjollnir.org Git - moodle.git/commitdiff
Safari 2.0 and Opera 9.0 are now detected and supported for YUI. However, preliminary...
authornicolasconnault <nicolasconnault>
Thu, 1 Mar 2007 01:31:37 +0000 (01:31 +0000)
committernicolasconnault <nicolasconnault>
Thu, 1 Mar 2007 01:31:37 +0000 (01:31 +0000)
I added a unit test for ajaxlib.php

Issue MDL-8417
Merged from MOODLE_18_STABLE

lib/ajax/ajaxlib.php
lib/simpletest/fixtures/user_agents.php [new file with mode: 0644]
lib/simpletest/testajaxlib.php [new file with mode: 0644]
lib/simpletest/testmoodlelib.php

index 22194c8cbdc9787fb54d6bb9af0165eae360d394..07bb5117ee3a701e0b087ae1926ecb18dd530b50 100644 (file)
@@ -109,10 +109,15 @@ function ajax_get_lib($libname) {
 function ajaxenabled() {
 
     global $CFG, $USER;
-
-    if (!check_browser_version('MSIE', 6.0)
-                && !check_browser_version('Gecko', 20051111)) {
-               // Gecko build 20051111 is what is in Firefox 1.5.
+    
+    $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 (!$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;
     }
diff --git a/lib/simpletest/fixtures/user_agents.php b/lib/simpletest/fixtures/user_agents.php
new file mode 100644 (file)
index 0000000..8280f57
--- /dev/null
@@ -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)')
+    )
+);
+?>
\ No newline at end of file
diff --git a/lib/simpletest/testajaxlib.php b/lib/simpletest/testajaxlib.php
new file mode 100644 (file)
index 0000000..19c05ba
--- /dev/null
@@ -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 &copy; 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());
+    }
+}
+
+?>
\ No newline at end of file
index 698be982c2c5db874c343614b167e5ac29307d61..c7b019297d63ceacfd0edac50a760110c0d064cd 100644 (file)
@@ -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 &copy; 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'));        
-    }    
+    }
 }
 
 ?>