Merged extension to check_browser_version from MDL-8417 (Nick)
[moodle.git] / lib / simpletest / testmoodlelib.php
CommitLineData
7c9d46c9 1<?php
2/**
3 * Unit tests for (some of) ../moodlelib.php.
4 *
5 * @copyright &copy; 2006 The Open University
6 * @author T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package moodlecore
9 */
10
11/** */
12require_once(dirname(__FILE__) . '/../../config.php');
13
14global $CFG;
15require_once($CFG->libdir . '/simpletestlib.php');
16require_once($CFG->libdir . '/moodlelib.php');
17
18class moodlelib_test extends UnitTestCase {
19
20 function setUp() {
21 }
22
23 function tearDown() {
24 }
25
26 function test_address_in_subnet() {
27 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.1'));
28 $this->assertFalse(address_in_subnet('123.121.234.2', '123.121.234.1'));
29 $this->assertFalse(address_in_subnet('123.121.134.1', '123.121.234.1'));
30 $this->assertFalse(address_in_subnet('113.121.234.1', '123.121.234.1'));
31 $this->assertTrue(address_in_subnet('123.121.234.0', '123.121.234.2/28'));
32 $this->assertTrue(address_in_subnet('123.121.234.15', '123.121.234.2/28'));
33 $this->assertFalse(address_in_subnet('123.121.234.16', '123.121.234.2/28'));
34 $this->assertFalse(address_in_subnet('123.121.234.255', '123.121.234.2/28'));
35 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.'));
36 $this->assertFalse(address_in_subnet('123.122.234.1', '123.121.'));
37 $this->assertFalse(address_in_subnet('223.121.234.1', '123.121.'));
38 $this->assertFalse(address_in_subnet('123.121.234.9', '123.121.234.10-20'));
39 $this->assertTrue(address_in_subnet('123.121.234.10', '123.121.234.10-20'));
40 $this->assertTrue(address_in_subnet('123.121.234.15', '123.121.234.10-20'));
41 $this->assertTrue(address_in_subnet('123.121.234.20', '123.121.234.10-20'));
42 $this->assertFalse(address_in_subnet('123.121.234.21', '123.121.234.10-20'));
43 $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 '));
44 $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 '));
45 $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 '));
46 $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 '));
47 $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 '));
48 $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 '));
49 $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 '));
50 $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 '));
51 }
52
53}
54
55?>