Fix for separate groups / all groups view MDL-8300
[moodle.git] / lib / simpletest / testmoodlelib.php
CommitLineData
d499142e 1<?php // $Id$
2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.org //
9// //
10// Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
7c9d46c9 26/**
27 * Unit tests for (some of) ../moodlelib.php.
28 *
29 * @copyright &copy; 2006 The Open University
30 * @author T.J.Hunt@open.ac.uk
d499142e 31 * @author nicolas@moodle.com
7c9d46c9 32 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
33 * @package moodlecore
34 */
35
239c1576 36/** $Id */
7c9d46c9 37require_once(dirname(__FILE__) . '/../../config.php');
38
39global $CFG;
40require_once($CFG->libdir . '/simpletestlib.php');
41require_once($CFG->libdir . '/moodlelib.php');
42
43class moodlelib_test extends UnitTestCase {
239c1576 44
7c9d46c9 45 function setUp() {
46 }
47
48 function tearDown() {
49 }
50
51 function test_address_in_subnet() {
52 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.1'));
53 $this->assertFalse(address_in_subnet('123.121.234.2', '123.121.234.1'));
54 $this->assertFalse(address_in_subnet('123.121.134.1', '123.121.234.1'));
55 $this->assertFalse(address_in_subnet('113.121.234.1', '123.121.234.1'));
56 $this->assertTrue(address_in_subnet('123.121.234.0', '123.121.234.2/28'));
57 $this->assertTrue(address_in_subnet('123.121.234.15', '123.121.234.2/28'));
58 $this->assertFalse(address_in_subnet('123.121.234.16', '123.121.234.2/28'));
59 $this->assertFalse(address_in_subnet('123.121.234.255', '123.121.234.2/28'));
60 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.'));
61 $this->assertFalse(address_in_subnet('123.122.234.1', '123.121.'));
62 $this->assertFalse(address_in_subnet('223.121.234.1', '123.121.'));
63 $this->assertFalse(address_in_subnet('123.121.234.9', '123.121.234.10-20'));
64 $this->assertTrue(address_in_subnet('123.121.234.10', '123.121.234.10-20'));
65 $this->assertTrue(address_in_subnet('123.121.234.15', '123.121.234.10-20'));
66 $this->assertTrue(address_in_subnet('123.121.234.20', '123.121.234.10-20'));
67 $this->assertFalse(address_in_subnet('123.121.234.21', '123.121.234.10-20'));
68 $this->assertTrue(address_in_subnet(' 123.121.234.1 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
69 $this->assertTrue(address_in_subnet(' 1.1.2.3 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
70 $this->assertTrue(address_in_subnet(' 2.2.234.1 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
71 $this->assertTrue(address_in_subnet(' 3.3.3.4 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
72 $this->assertFalse(address_in_subnet(' 123.121.234.2 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
73 $this->assertFalse(address_in_subnet(' 2.1.2.3 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
74 $this->assertFalse(address_in_subnet(' 2.3.234.1 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
75 $this->assertFalse(address_in_subnet(' 3.3.3.7 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 '));
76 }
77
239c1576 78 /**
79 * Modifies $_SERVER['HTTP_USER_AGENT'] manually to check if check_browser_version
80 * works as expected.
81 */
82 function test_check_browser_version()
83 {
d499142e 84 require_once($CFG->libdir . '/simpletest/fixtures/user_agents.php');
85
86 $_SERVER['HTTP_USER_AGENT'] = $user_agents['Safari']['2.0']['Mac OS X'];
87 var_dump($_SERVER['HTTP_USER_AGENT']);
239c1576 88 $this->assertTrue(check_browser_version('Safari', '312'));
89 $this->assertFalse(check_browser_version('Safari', '500'));
90
d499142e 91 $_SERVER['HTTP_USER_AGENT'] = $user_agents['Opera']['9.0']['Windows XP'];
239c1576 92 $this->assertTrue(check_browser_version('Opera', '8.0'));
93 $this->assertFalse(check_browser_version('Opera', '10.0'));
94
d499142e 95 $_SERVER['HTTP_USER_AGENT'] = $user_agents['MSIE']['6.0']['Windows XP SP2'];
239c1576 96 $this->assertTrue(check_browser_version('MSIE', '5.0'));
97 $this->assertFalse(check_browser_version('MSIE', '7.0'));
98
d499142e 99 $_SERVER['HTTP_USER_AGENT'] = $user_agents['Firefox']['2.0']['Windows XP'];
239c1576 100 $this->assertTrue(check_browser_version('Firefox', '1.5'));
101 $this->assertFalse(check_browser_version('Firefox', '3.0'));
d499142e 102 }
7c9d46c9 103}
104
105?>