diff --git a/test/libraries/PMA_import_test.php b/test/libraries/PMA_import_test.php new file mode 100644 index 0000000000..ec82e56e59 --- /dev/null +++ b/test/libraries/PMA_import_test.php @@ -0,0 +1,228 @@ +assertFalse(PMA_checkTimeout()); + + //Reinit values. + $timestamp = time(); + $maximum_time = 0; + $timeout_passed = true; + + $this->assertFalse(PMA_checkTimeout()); + + //Reinit values. + $timestamp = time(); + $maximum_time = 30; + $timeout_passed = true; + + $this->assertTrue(PMA_checkTimeout()); + + //Reinit values. + $timestamp = time()-15; + $maximum_time = 30; + $timeout_passed = false; + + $this->assertFalse(PMA_checkTimeout()); + + //Reinit values. + $timestamp = time()-60; + $maximum_time = 30; + $timeout_passed = false; + + $this->assertTrue(PMA_checkTimeout()); + } + + function testLookForUse() + { + $this->assertEquals( + array(null, null), + PMA_lookForUse(null, null, null) + ); + + $this->assertEquals( + array('myDb', null), + PMA_lookForUse(null, 'myDb', null) + ); + + $this->assertEquals( + array('myDb', true), + PMA_lookForUse(null, 'myDb', true) + ); + + $this->assertEquals( + array('myDb', true), + PMA_lookForUse('select 1 from myTable', 'myDb', true) + ); + + $this->assertEquals( + array('anotherDb', true), + PMA_lookForUse('use anotherDb', 'myDb', false) + ); + + $this->assertEquals( + array('anotherDb', true), + PMA_lookForUse('use anotherDb', 'myDb', true) + ); + + $this->assertEquals( + array('anotherDb', true), + PMA_lookForUse('use `anotherDb`;', 'myDb', true) + ); + } + + /** + * @dataProvider prov_getColumnAlphaName + */ + function testGetColumnAlphaName($expected, $num) + { + $this->assertEquals($expected, PMA_getColumnAlphaName($num)); + } + + function prov_getColumnAlphaName() + { + return array( + array('A', 1), + array('Z', 0), + array('AA', 27), + array('AZ', 52), + array('BA', 53), + array('BB', 54), + ); + } + + /** + * @dataProvider prov_getColumnNumberFromNamee + */ + function testGetColumnNumberFromName($expected, $name) + { + $this->assertEquals($expected, PMA_getColumnNumberFromName($name)); + } + + function prov_getColumnNumberFromNamee() + { + return array( + array(1, 'A'), + array(26, 'Z'), + array(27, 'AA'), + array(52, 'AZ'), + array(53, 'BA'), + array(54, 'BB'), + ); + } + + /** + * @dataProvider prov_getM + */ + function testGetM($expected, $size) + { + $this->assertEquals($expected, PMA_getM($size)); + } + + function prov_getM() + { + return array( + array(2, '2,1'), + array(6, '6,2'), + array(6, '6,0'), + array(16, '16,2'), + ); + } + + /** + * @dataProvider prov_getD + */ + function testGetD($expected, $size) + { + $this->assertEquals($expected, PMA_getD($size)); + } + + function prov_getD() + { + return array( + array(1, '2,1'), + array(2, '6,2'), + array(0, '6,0'), + array(20, '30,20'), + ); + } + + /** + * @dataProvider prov_getDecimalSize + */ + function testGetDecimalSize($expected, $size) + { + $this->assertEquals($expected, PMA_getDecimalSize($size)); + } + + function prov_getDecimalSize() + { + return array( + array(array(2, 1, '2,1'), '2.1'), + array(array(2, 1, '2,1'), '6.2'), + array(array(3, 1, '3,1'), '10.0'), + array(array(4, 2, '4,2'), '30.20'), + ); + } + + /** + * @dataProvider prov_detectType + */ + function testDetectType($expected, $type, $cell) + { + $this->assertEquals($expected, PMA_detectType($type, $cell)); + } + + function prov_detectType() + { + return array( + array(NONE, null, 'NULL'), + array(NONE, NONE, 'NULL'), + array(INT, INT, 'NULL'), + array(VARCHAR, VARCHAR, 'NULL'), + array(VARCHAR, null, null), + array(VARCHAR, INT, null), + array(INT, INT, '10'), + array(DECIMAL, DECIMAL, '10.2'), + array(DECIMAL, INT, '10.2'), + array(BIGINT, BIGINT, '2147483648'), + array(BIGINT, INT, '2147483648'), + array(VARCHAR, VARCHAR, 'test'), + array(VARCHAR, INT, 'test'), + ); + } +} \ No newline at end of file diff --git a/test/libraries/core/PMA_array_test.php b/test/libraries/core/PMA_array_test.php index 6209587bf7..43bcc0641c 100644 --- a/test/libraries/core/PMA_array_test.php +++ b/test/libraries/core/PMA_array_test.php @@ -326,4 +326,30 @@ class PMA_Array_Test extends PHPUnit_Framework_TestCase PMA_arrayWalkRecursive($arr, 'stripslashes', true); $this->assertEquals($arr, $target); } + + /** + * @dataProvider prov_arrayKeyExists + */ + function testArrayKeyExists($expected, $path, $array) + { + $this->assertEquals($expected, PMA_arrayKeyExists($path, $array)); + } + + function prov_arrayKeyExists() + { + return array( + array(true, 'k1', array('k1' => array())), + array(true, 'k1/k2', array('k1' => array('k2' => array()))), + array(true, 'k1/k2', array('k1' => array('k3' => array(), 'k2' => array()))), + array(true, 'k1/k2', array('k1' => array('k2' => array('k3' => array())))), + array( + true, 'k1/k2/k3', array('k1' => array('k2' => array('k3' => array()))) + ), + array(false, '', array('k1' => array())), + array(false, 'k1/k2', array('k1' => array())), + array(false, 'k1/k2', array('k1' => array(), 'k2' => array())), + array(false, 'k1/k3', array('k1' => array('k2' => array()))), + array(false, 'k2', array('k1' => array('k2' => array()))), + ); + } }