2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tests for PMA_isValid() from libraries/core.lib.php
6 * @package phpMyAdmin-test
12 require_once 'libraries/core.lib.php';
14 class PMA_isValid_test
extends PHPUnit_Framework_TestCase
16 public static function providerNoVarTypeProvider()
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));
34 * @dataProvider providerNoVarTypeProvider
37 * @param mixed $compare
39 public function testNoVarType($var, $type, $compare)
41 $this->assertTrue(PMA_isValid($var, $type, $compare));
44 public function testVarNotSetAfterTest()
47 $this->assertFalse(isset($var));
50 public function testNotSet()
52 $this->assertFalse(PMA_isValid($var));
55 public function testEmptyString()
58 $this->assertFalse(PMA_isValid($var));
61 public function testNotEmptyString()
64 $this->assertTrue(PMA_isValid($var));
67 public function testZero()
70 $this->assertTrue(PMA_isValid($var));
71 $this->assertTrue(PMA_isValid($var, 'int'));
74 public function testNullFail()
77 $this->assertFalse(PMA_isValid($var));
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()
92 $this->assertTrue(PMA_isValid($var, 'len'));
93 $this->assertTrue(PMA_isValid($var, 'scalar'));
94 $this->assertTrue(PMA_isValid($var));
97 public function testScalarInt()
100 $this->assertTrue(PMA_isValid($var, 'int'));
101 $this->assertTrue(PMA_isValid($var, 'scalar'));
104 public function testScalarFloat()
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()
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()
129 $this->assertFalse(PMA_isValid($var, 'scalar'));
132 public function testNumericInt()
135 $this->assertTrue(PMA_isValid($var, 'numeric'));
138 public function testNumericFloat()
141 $this->assertTrue(PMA_isValid($var, 'numeric'));
144 public function testNumericZero()
147 $this->assertTrue(PMA_isValid($var, 'numeric'));
150 public function testNumericString()
153 $this->assertTrue(PMA_isValid($var, 'numeric'));
156 public function testValueInArray()
159 $this->assertTrue(PMA_isValid($var, array('a', 'b',)));
162 public function testValueNotInArray()
165 $this->assertFalse(PMA_isValid($var, array('a', 'b',)));
168 public function testNumericIdentical()
172 $this->assertTrue(PMA_isValid($var, 'identic', $compare));
176 $this->assertFalse(PMA_isValid($var, 'identic', $compare));
180 $this->assertFalse(PMA_isValid($var, 'identic', $compare));
183 public function providerSimilarType()
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
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'));