Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/ajax/simpletest/testajaxlib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00026 if (!defined('MOODLE_INTERNAL')) {
00027     die('Direct access to this script is forbidden.');    
00028 }
00029 require_once($CFG->libdir . '/ajax/ajaxlib.php');
00030 
00031 
00038 class ajax_test extends UnitTestCase {
00039 
00040     var $user_agents = array(
00041             'MSIE' => array(
00042                 '5.5' => array('Windows 2000' => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'),
00043                 '6.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'),
00044                 '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)')
00045             ),
00046             'Firefox' => array(
00047                 '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'),
00048                 '1.5'     => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'),
00049                 '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'),
00050                 '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',
00051                                    'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)')
00052             ),
00053             'Safari' => array(
00054                 '312' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'),
00055                 '2.0' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412')
00056             ),
00057             'Opera' => array(
00058                 '8.51' => array('Windows XP' => 'Opera/8.51 (Windows NT 5.1; U; en)'),
00059                 '9.0'  => array('Windows XP' => 'Opera/9.0 (Windows NT 5.1; U; en)',
00060                                 'Debian Linux' => 'Opera/9.01 (X11; Linux i686; U; en)')
00061             )
00062         );
00063 
00067     function test_ajaxenabled()
00068     {
00069         global $CFG, $USER;
00070         $CFG->enableajax = true;
00071         $USER->ajax      = true;
00072 
00073         // Should be true
00074         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
00075         $this->assertTrue(ajaxenabled());
00076 
00077         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.5']['Windows XP'];
00078         $this->assertTrue(ajaxenabled());
00079 
00080         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
00081         $this->assertTrue(ajaxenabled());
00082 
00083         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
00084         $this->assertTrue(ajaxenabled());
00085 
00086         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['6.0']['Windows XP SP2'];
00087         $this->assertTrue(ajaxenabled());
00088 
00089         // Should be false
00090         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.0.6']['Windows XP'];
00091         $this->assertFalse(ajaxenabled());
00092 
00093         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['312']['Mac OS X'];
00094         $this->assertFalse(ajaxenabled());
00095 
00096         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['8.51']['Windows XP'];
00097         $this->assertFalse(ajaxenabled());
00098 
00099         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['5.5']['Windows 2000'];
00100         $this->assertFalse(ajaxenabled());
00101 
00102         // Test array of tested browsers
00103         $tested_browsers = array('MSIE' => 6.0, 'Gecko' => 20061111);
00104         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
00105         $this->assertTrue(ajaxenabled($tested_browsers));
00106 
00107         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2'];
00108         $this->assertTrue(ajaxenabled($tested_browsers));
00109 
00110         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
00111         $this->assertFalse(ajaxenabled($tested_browsers));
00112 
00113         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
00114         $this->assertFalse(ajaxenabled($tested_browsers));
00115 
00116         $tested_browsers = array('Safari' => 412, 'Opera' => 9.0);
00117         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
00118         $this->assertFalse(ajaxenabled($tested_browsers));
00119 
00120         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2'];
00121         $this->assertFalse(ajaxenabled($tested_browsers));
00122 
00123         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
00124         $this->assertTrue(ajaxenabled($tested_browsers));
00125 
00126         $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
00127         $this->assertTrue(ajaxenabled($tested_browsers));
00128     }
00129 }
 All Data Structures Namespaces Files Functions Variables Enumerations