0337d704 |
1 | <?php |
2 | require_once("__init__.php"); |
3 | require_once('include/platal/env.inc.php'); |
4 | |
5 | class TestOfEnv extends UnitTestCase { |
6 | function TestOfEnv() { |
7 | $this->UnitTestCase('Env access'); |
8 | } |
9 | |
10 | function test_get() { |
11 | $_REQUEST['foo'] = 'baz'; |
12 | $this->assertIdentical(Env::get('foo'), 'baz'); |
13 | |
14 | $_REQUEST['foo'] = 123; |
15 | $this->assertIdentical(Env::get('foo'), '123'); |
16 | |
17 | $_REQUEST['foo'] = '123'; |
18 | $this->assertIdentical(Env::get('foo'), '123'); |
19 | |
20 | $this->assertIdentical(Env::get('bar'), ''); |
21 | $this->assertIdentical(Env::get('bar', 'bar'), 'bar'); |
22 | } |
23 | |
24 | function test_getMixed() { |
25 | $_REQUEST['foo'] = 'baz'; |
26 | $this->assertIdentical(Env::getMixed('foo'), 'baz'); |
27 | |
28 | $_REQUEST['foo'] = 123; |
29 | $this->assertIdentical(Env::getMixed('foo'), 123); |
30 | |
31 | $_REQUEST['foo'] = Array(1,'a'); |
32 | $this->assertIdentical(Env::getMixed('foo'), Array(1,'a')); |
33 | |
34 | $this->assertIdentical(Env::getMixed('bar'), null); |
35 | $this->assertIdentical(Env::getMixed('bar', 'bar'), 'bar'); |
36 | } |
37 | |
38 | function test_getBool() { |
39 | $_REQUEST['foo'] = 'baz'; |
40 | $this->assertIdentical(Env::getBool('foo'), true); |
41 | |
42 | $_REQUEST['foo'] = 123; |
43 | $this->assertIdentical(Env::getBool('foo'), true); |
44 | |
45 | $_REQUEST['foo'] = '123'; |
46 | $this->assertIdentical(Env::getBool('foo'), true); |
47 | |
48 | $this->assertIdentical(Env::getBool('bar'), false); |
49 | $this->assertIdentical(Env::getBool('bar', true), true); |
50 | } |
51 | |
52 | function test_getInt() { |
53 | $_REQUEST['foo'] = 'baz'; |
54 | $this->assertIdentical(Env::getInt('foo'), 0); |
55 | $this->assertIdentical(Env::getInt('foo', 10), 10); |
56 | |
57 | $_REQUEST['foo'] = 123; |
58 | $this->assertIdentical(Env::getInt('foo'), 123); |
59 | |
60 | $_REQUEST['foo'] = '123'; |
61 | $this->assertIdentical(Env::getInt('foo'), 123); |
62 | |
63 | $this->assertIdentical(Env::getInt('bar'), 0); |
64 | $this->assertIdentical(Env::getInt('bar', 123), 123); |
65 | } |
66 | |
67 | function test_kill() { |
68 | $_REQUEST['foo'] = 'baz'; |
69 | Env::kill('foo'); |
70 | $this->assertFalse(isset($_REQUEST['foo'])); |
71 | } |
72 | |
73 | function test_other_class() { |
74 | $_POST['foo'] = 'baz'; |
75 | Post::kill('foo'); |
76 | $this->assertFalse(isset($_POST['foo'])); |
77 | |
78 | $_GET['foo'] = 'baz'; |
79 | Get::kill('foo'); |
80 | $this->assertFalse(isset($_GET['foo'])); |
81 | } |
82 | } |
83 | |
84 | $test = &new TestOfEnv(); |
85 | $test->run($reporter); |
86 | ?> |