Advisor: mark that 'Rate of reading fixed position' may be wrong, requires further...
[phpmyadmin/thilanka.git] / test / libraries / core / PMA_isValid_test.php
blob5bd33675d454c76b07965e59475da021252f7f98
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Tests for PMA_isValid() from libraries/core.lib.php
6 * @package phpMyAdmin-test
7 */
9 /*
10 * Include to test.
12 require_once 'libraries/core.lib.php';
14 class PMA_isValid_test extends PHPUnit_Framework_TestCase
16 public static function providerNoVarTypeProvider()
18 return array(
19 array(0, false, 0),
20 array(0, false, 1),
21 array(1, false, null),
22 array(1.1, false, null),
23 array('', false, null),
24 array(' ', false, null),
25 array('0', false, null),
26 array('string', false, null),
27 array(array(), false, null),
28 array(array(1, 2, 3), false, null),
29 array(true, false, null),
30 array(false, false, null));
33 /**
34 * @dataProvider providerNoVarTypeProvider
35 * @param mixed $var
36 * @param mixed $type
37 * @param mixed $compare
39 public function testNoVarType($var, $type, $compare)
41 $this->assertTrue(PMA_isValid($var, $type, $compare));
44 public function testVarNotSetAfterTest()
46 PMA_isValid($var);
47 $this->assertFalse(isset($var));
50 public function testNotSet()
52 $this->assertFalse(PMA_isValid($var));
55 public function testEmptyString()
57 $var = '';
58 $this->assertFalse(PMA_isValid($var));
61 public function testNotEmptyString()
63 $var = '0';
64 $this->assertTrue(PMA_isValid($var));
67 public function testZero()
69 $var = 0;
70 $this->assertTrue(PMA_isValid($var));
71 $this->assertTrue(PMA_isValid($var, 'int'));
74 public function testNullFail()
76 $var = null;
77 $this->assertFalse(PMA_isValid($var));
79 $var = 'null_text';
80 $this->assertFalse(PMA_isValid($var, 'null'));
83 public function testNotSetArray()
85 /** @var $array undefined array */
86 $this->assertFalse(PMA_isValid($array['x']));
89 public function testScalarString()
91 $var = 'string';
92 $this->assertTrue(PMA_isValid($var, 'len'));
93 $this->assertTrue(PMA_isValid($var, 'scalar'));
94 $this->assertTrue(PMA_isValid($var));
97 public function testScalarInt()
99 $var = 1;
100 $this->assertTrue(PMA_isValid($var, 'int'));
101 $this->assertTrue(PMA_isValid($var, 'scalar'));
104 public function testScalarFloat()
106 $var = 1.1;
107 $this->assertTrue(PMA_isValid($var, 'float'));
108 $this->assertTrue(PMA_isValid($var, 'double'));
109 $this->assertTrue(PMA_isValid($var, 'scalar'));
112 public function testScalarBool()
114 $var = true;
115 $this->assertTrue(PMA_isValid($var, 'scalar'));
116 $this->assertTrue(PMA_isValid($var, 'bool'));
117 $this->assertTrue(PMA_isValid($var, 'boolean'));
120 public function testNotScalarArray()
122 $var = array('test');
123 $this->assertFalse(PMA_isValid($var, 'scalar'));
126 public function testNotScalarNull()
128 $var = null;
129 $this->assertFalse(PMA_isValid($var, 'scalar'));
132 public function testNumericInt()
134 $var = 1;
135 $this->assertTrue(PMA_isValid($var, 'numeric'));
138 public function testNumericFloat()
140 $var = 1.1;
141 $this->assertTrue(PMA_isValid($var, 'numeric'));
144 public function testNumericZero()
146 $var = 0;
147 $this->assertTrue(PMA_isValid($var, 'numeric'));
150 public function testNumericString()
152 $var = '+0.1';
153 $this->assertTrue(PMA_isValid($var, 'numeric'));
156 public function testValueInArray()
158 $var = 'a';
159 $this->assertTrue(PMA_isValid($var, array('a', 'b',)));
162 public function testValueNotInArray()
164 $var = 'c';
165 $this->assertFalse(PMA_isValid($var, array('a', 'b',)));
168 public function testNumericIdentical()
170 $var = 1;
171 $compare = 1;
172 $this->assertTrue(PMA_isValid($var, 'identic', $compare));
174 $var = 1;
175 $compare += 2;
176 $this->assertFalse(PMA_isValid($var, 'identic', $compare));
178 $var = 1;
179 $compare = '1';
180 $this->assertFalse(PMA_isValid($var, 'identic', $compare));
183 public function providerSimilarType()
185 return array(
186 array(1, 1),
187 array(1.5, 1.5),
188 array(true, true),
189 array('string', "string"),
190 array(array(1, 2, 3.4), array(1, 2, 3.4)),
191 array(array(1, '2', '3.4', 5, 'text'), array('1', '2', 3.4,'5'))
196 * @dataProvider providerSimilarType
197 * @param mixed $var
198 * @param mixed $compare
200 public function testSimilarType($var, $compare)
202 $this->assertTrue(PMA_isValid($var, 'similar', $compare));
203 $this->assertTrue(PMA_isValid($var, 'equal', $compare));
204 $this->assertTrue(PMA_isValid($compare, 'similar', $var));
205 $this->assertTrue(PMA_isValid($compare, 'equal', $var));
209 public function testOtherTypes()
211 $var = new PMA_isValid_test();
212 $this->assertFalse(PMA_isValid($var, 'class'));