]> src.bluestatic.org Git - isso.git/blob - docs/UnitTest/InputTest.php
Removing dead files that we no longer need
[isso.git] / docs / UnitTest / InputTest.php
1 <?php
2
3 require_once 'PHPUnit/Framework.php';
4
5 /**
6 * InputTest
7 *
8 * @author Blue Static
9 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
10 * @version $Revision$
11 * @package ISSO Tests
12 *
13 */
14 class InputTest extends PHPUnit_Framework_TestCase
15 {
16 private $fixture;
17
18 public function setUp()
19 {
20 $_GET = array(
21 '1' => 'moo',
22 '0' => 'foobar',
23 'abc' => '-1',
24 'ab"c"' => '2.0',
25 'ab"c"2' => 'k"lm"',
26 'ab\'c\'' => 'nop',
27 "ab\'c\'2" => "qr\'s\'"
28 );
29 $_COOKIE = array(
30 'somecookie' => '"a var"',
31 'another"value"' => "isn't it cool"
32 );
33 $_POST = array(
34 'nest' => array(
35 'foobar' => '"test"',
36 '"hi"' => 'test\'ing'
37 )
38 );
39
40 // simulate magic quotes GPC
41 /*foreach (array($_GET, $_COOKIE) AS $array)
42 {
43 foreach ($array AS $var => $value)
44 {
45 $array["$var"] = addslashes($value);
46 }
47 }*/
48
49 require_once 'ISSO/App.php';
50 $this->fixture = BSApp::LoadModule('Input');
51 }
52
53 public function testSanitizeInputData()
54 {
55 $this->assertEquals(10, sizeof($this->fixture->in));
56 $this->assertEquals(2, sizeof($this->fixture->in['nest']));
57 $this->assertEquals('&quot;a var&quot;', $this->fixture->in['somecookie']);
58 $this->assertEquals('test\'ing', $this->fixture->in['nest']['"hi"']);
59 }
60
61 public function testEntityEncode()
62 {
63 $this->assertEquals('&lt;a href=&quot;http://www.something.com/test.php?do=run&amp;moo=foo&quot;&gt;', $this->fixture->entityEncode('<a href="http://www.something.com/test.php?do=run&moo=foo">'));
64 }
65
66 public function testUnsanitize()
67 {
68 $this->assertEquals('<script type="text/javascript"> alert("XSS is fun!"); </script>', $this->fixture->unsanitize('<script type="text/javascript"> alert("XSS is fun!"); </script>'));
69 $this->assertEquals('<script type="text/javascript"> alert("XSS is fun!"); </script>', $this->fixture->unsanitize('&lt;script type=&quot;text/javascript&quot;&gt; alert(&quot;XSS is fun!&quot;); &lt;/script&gt;'));
70 $this->assertEquals('<script type="text/javascript"> alert("XSS is fun!"); </script>', $this->fixture->unsanitize($this->fixture->sanitize('<script type="text/javascript"> alert("XSS is fun!"); </script>')));
71 }
72
73 public function testClean()
74 {
75 $this->assertEquals(0, $this->fixture->clean('abc', TYPE_INT));
76 $this->assertEquals(-1, $this->fixture->clean('-1', TYPE_INT));
77 $this->assertEquals(4, $this->fixture->clean('4def', TYPE_INT));
78
79 $this->assertEquals(0, $this->fixture->clean('abc', TYPE_UINT));
80 $this->assertEquals(0, $this->fixture->clean(-100, TYPE_UINT));
81 $this->assertEquals(40, $this->fixture->clean('40.965', TYPE_UINT));
82
83 $this->assertEquals(0, $this->fixture->clean('0.0', TYPE_FLOAT));
84 $this->assertNotEquals(0, $this->fixture->clean('0.032', TYPE_FLOAT));
85
86 $this->assertEquals(true, $this->fixture->clean('aafsdfa', TYPE_BOOL));
87 $this->assertEquals(false, $this->fixture->clean('', TYPE_BOOL));
88 $this->assertEquals(false, $this->fixture->clean('0', TYPE_BOOL));
89 $this->assertEquals(true, $this->fixture->clean('0.0', TYPE_BOOL));
90
91 $this->assertEquals('<abc "def" gih>', $this->fixture->clean('<abc "def" gih>', TYPE_STR));
92
93 $this->assertEquals('<abc "def" gih>', $this->fixture->clean('<abc "def" gih>', TYPE_STRUN));
94 $this->assertEquals('<abc "def" gih>', $this->fixture->clean($this->fixture->sanitize('<abc "def" gih>'), TYPE_STRUN));
95
96 $this->assertEquals('<abc "def" gih>', $this->fixture->clean('<abc "def" gih>', TYPE_NONE));
97
98 $this->assertEquals('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', $this->fixture->clean('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', TYPE_BIN));
99
100 try
101 {
102 $this->fixture->clean('asdfa', TYPE_THIS_DOES_NOT_EXIST);
103 $this->fail('exception expected');
104 }
105 catch (Exception $e)
106 {}
107 }
108
109 public function testCleanArray()
110 {
111 $array = array(
112 'a' => '1',
113 'b' => '2.7',
114 'c' => 'adfasdf',
115 'd' => '-12'
116 );
117
118 $newarray = $this->fixture->clean($array, TYPE_UINT);
119
120 $this->assertEquals(4, sizeof($newarray));
121 $this->assertEquals(1, $newarray['a']);
122 $this->assertEquals(2, $newarray['b']);
123 $this->assertEquals(0, $newarray['c']);
124 $this->assertEquals(0, $newarray['d']);
125 }
126
127 public function testInputClean()
128 {
129 $this->assertEquals(-1.0, $this->fixture->inputClean('abc', TYPE_FLOAT));
130 $this->assertEquals(-1.0, $this->fixture->in['abc']);
131
132 $this->assertEquals('', $this->fixture->inputClean(':does:not:exist', TYPE_STR));
133 }
134
135 public function testInputCleanArray()
136 {
137 $this->fixture->inputCleanArray(array(
138 'abc' => TYPE_FLOAT,
139 'ab"c"' => TYPE_INT
140 ));
141
142 $this->assertEquals(-1.0, $this->fixture->in['abc']);
143 $this->assertEquals(2, $this->fixture->in['ab"c"']);
144 }
145
146 public function testEscape()
147 {
148 $this->assertEquals("this isn\'t a test", $this->fixture->escape("this isn't a test", true));
149 }
150
151 public function testInputEscape()
152 {
153 $this->assertEquals("isn\'t it cool", $this->fixture->inputEscape('another"value"'));
154 $this->assertEquals('', $this->fixture->inputEscape(':will:never:exist'));
155 }
156
157 public function testPostCheck()
158 {
159 }
160 }
161
162 ?>