From 7b1b3137c86b25db1c511bc7ecd6a97cba7b1938 Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Wed, 4 Jul 2012 23:40:22 +0530 Subject: [PATCH 01/11] Test cases for Script.class.php --- test/classes/PMA_Error_test.php | 2 +- test/classes/PMA_Scripts_test.php | 137 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 test/classes/PMA_Scripts_test.php diff --git a/test/classes/PMA_Error_test.php b/test/classes/PMA_Error_test.php index 518a4e369f..0965b90546 100644 --- a/test/classes/PMA_Error_test.php +++ b/test/classes/PMA_Error_test.php @@ -1,6 +1,6 @@ object = $this->getMockForAbstractClass('PMA_Scripts'); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + * + * @access protected + * @return void + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * Call private functions by making the visibitlity to public. + * + * @param string $name method name + * @param array $params parameters for the invocation + * + * @return the output from the private method. + */ + private function _callPrivateFunction($name, $params) + { + $class = new ReflectionClass('PMA_Scripts'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs($this->object, $params); + } + + /** + * Test for _includeFile + * + * @param tring $url Location of javascript, relative to js/ folder. + * @param int $timestamp The date when the file was last modified + * @param string $ie_conditional true - wrap with IE conditional comment + * 'lt 9' etc. - wrap for specific IE version + * @param $output output from the _includeFile method + * + * @dataProvider providerForTestIncludeFile + */ + public function testIncludeFile($url, $timestamp, $ie_conditional, $output){ + $this->assertEquals( + $this->_callPrivateFunction( + '_includeFile', + array($url, $timestamp, $ie_conditional) + ), + $output + ); + } + + /** + * @return array data for testIncludeFile + */ + public function providerForTestIncludeFile(){ + return array( + array( + 'common.js', + null, + true, + ' +' + ), + array( + 'common.js', + null, + false, + ' +' + ) + ); + } + + /** + * Test for getDisplay + */ + public function testGetDisplay(){ + + $this->object->addFile('common.js'); + $this->object->addEvent('onClick', 'doSomething'); + + $this->assertEquals( + $this->object->getDisplay(), + ' +' + ); + } + + /** + * test for addCode + */ + public function testAddCode(){ + + $this->object->addCode('alert(\'CodeAdded\')'); + + $this->assertEquals( + $this->object->getDisplay(), + '' + ); + } +} From ec4478b4585c9cc28fb00a80843354b1b8c5da5d Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Thu, 5 Jul 2012 00:19:49 +0530 Subject: [PATCH 02/11] Test cases for PMA_Types class --- test/classes/PMA_Types_test.php | 149 ++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/test/classes/PMA_Types_test.php b/test/classes/PMA_Types_test.php index 19f276ecbf..1481763690 100644 --- a/test/classes/PMA_Types_test.php +++ b/test/classes/PMA_Types_test.php @@ -22,10 +22,159 @@ class PMA_TypesTest extends PHPUnit_Framework_TestCase $this->object = new PMA_Types; } + /** + * Test for isUnaryOperator + */ public function testUnary() { $this->assertTrue($this->object->isUnaryOperator('IS NULL')); $this->assertFalse($this->object->isUnaryOperator('=')); } + + /** + * Test for getUnaryOperators + */ + public function testGetUnaryOperators(){ + $this->assertEquals($this->object->getUnaryOperators(), + array( + 'IS NULL', + 'IS NOT NULL', + "= ''", + "!= ''", + ) + ); + } + + /** + * Test for getNullOperators + */ + public function testGetNullOperators(){ + $this->assertEquals($this->object->getNullOperators(), + array( + 'IS NULL', + 'IS NOT NULL', + ) + ); + } + + /** + * Test for getEnumOperators + */ + public function testGetEnumOperators(){ + $this->assertEquals($this->object->getEnumOperators(), + array( + '=', + '!=', + ) + ); + } + + /** + * Test for getTextOperators + */ + public function testgetTextOperators(){ + $this->assertEquals($this->object->getTextOperators(), + array( + 'LIKE', + 'LIKE %...%', + 'NOT LIKE', + '=', + '!=', + 'REGEXP', + 'REGEXP ^...$', + 'NOT REGEXP', + "= ''", + "!= ''", + 'IN (...)', + 'NOT IN (...)', + 'BETWEEN', + 'NOT BETWEEN', + ) + ); + } + + /** + * Test for getNumberOperators + */ + public function testGetNumberOperators(){ + $this->assertEquals($this->object->getNumberOperators(), + array( + '=', + '>', + '>=', + '<', + '<=', + '!=', + 'LIKE', + 'NOT LIKE', + 'IN (...)', + 'NOT IN (...)', + 'BETWEEN', + 'NOT BETWEEN', + ) + ); + } + + /** + * @param string $type Type of field + * @param boolean $null Whether field can be NULL + * @param $output + * + * @dataProvider providerForGetTypeOperators + */ + public function testGetTypeOperators($type, $null, $output){ + $this->assertEquals( + $this->object->getTypeOperators($type, $null), + $output + ); + } + + /** + * data provider for testGetTypeOperators + */ + public function providerForGetTypeOperators(){ + return array( + array( + 'enum', + false, + array( + '=', + '!=', + ) + ), + array( + 'CHAR', + true, + array( + '=', + '>', + '>=', + '<', + '<=', + '!=', + 'LIKE', + 'NOT LIKE', + 'IN (...)', + 'NOT IN (...)', + 'BETWEEN', + 'NOT BETWEEN', + 'IS NULL', + 'IS NOT NULL', + ), + array( + 'int', + false, + array( + '=', + '!=', + ) + ), + ) + ); + } + + public function testGetTypeOperatorsHtml(){ + $this->assertTrue(true); + } } ?> From d956f18d35085d8223e8d499ab9b75e6025fee48 Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Thu, 5 Jul 2012 22:07:16 +0530 Subject: [PATCH 03/11] Test cases for PMA_Types_MySQL class --- test/classes/PMA_Types_MySQL_test.php | 500 ++++++++++++++++++++++++++ test/classes/PMA_Types_test.php | 106 +++++- 2 files changed, 603 insertions(+), 3 deletions(-) create mode 100644 test/classes/PMA_Types_MySQL_test.php diff --git a/test/classes/PMA_Types_MySQL_test.php b/test/classes/PMA_Types_MySQL_test.php new file mode 100644 index 0000000000..281598e53a --- /dev/null +++ b/test/classes/PMA_Types_MySQL_test.php @@ -0,0 +1,500 @@ +object = new PMA_Types_MySQL(); + } + + /** + * Test for getTypeDescription + * + * @param string $type The data type to get a description. + * @param $output string + * + * @dataProvider providerForTestGetTypeDescription + */ + public function testGetTypeDescription($type, $output){ + $this->assertEquals( + $this->object->getTypeDescription($type), + $output + ); + } + + /** + * Provider for testGetTypeDescription + * @return array + */ + public function providerForTestGetTypeDescription(){ + return array( + array( + 'TINYINT', + 'A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255' + ), + array( + 'SMALLINT', + 'A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535' + ), + array( + 'MEDIUMINT', + 'A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215' + ), + array( + 'INT', + 'A 4-byte integer, signed range is -2,147,483,648 to 2,147,483,647, unsigned range is 0 to 4,294,967,295.' + ), + array( + 'BIGINT', + 'An 8-byte integer, signed range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, unsigned range is 0 to 18,446,744,073,709,551,615' + ), + array( + 'DECIMAL', + 'A fixed-point number (M, D) - the maximum number of digits (M) is 65 (default 10), the maximum number of decimals (D) is 30 (default 0)' + ), + array( + 'FLOAT', + 'A small floating-point number, allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38' + ), + array( + 'DOUBLE', + 'A double-precision floating-point number, allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308' + ), + array( + 'REAL', + 'Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)' + ), + array( + 'BIT', + 'A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)' + ), + array( + 'BOOLEAN', + 'A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true' + ), + array( + 'SERIAL', + 'An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE' + ), + array( + 'DATE', + 'A date, supported range is 1000-01-01 to 9999-12-31' + ), + array( + 'DATETIME', + 'A date and time combination, supported range is 1000-01-01 00:00:00 to 9999-12-31 23:59:59' + ), + array( + 'TIMESTAMP', + 'A timestamp, range is 1970-01-01 00:00:01 UTC to 2038-01-09 03:14:07 UTC, stored as the number of seconds since the epoch (1970-01-01 00:00:00 UTC)' + ), + array( + 'TIME', + 'A time, range is -838:59:59 to 838:59:59' + ), + array( + 'YEAR', + 'A year in four-digit (4, default) or two-digit (2) format, the allowable values are 70 (1970) to 69 (2069) or 1901 to 2155 and 0000' + ), + array( + 'CHAR', + 'A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored' + ), + array( + 'VARCHAR', + 'A variable-length (0-65,535) string, the effective maximum length is subject to the maximum row size' + ), + array( + 'TINYTEXT', + 'A TEXT column with a maximum length of 255 (2^8 - 1) characters, stored with a one-byte prefix indicating the length of the value in bytes' + ), + array( + 'TEXT', + 'A TEXT column with a maximum length of 65,535 (2^16 - 1) characters, stored with a two-byte prefix indicating the length of the value in bytes' + ), + array( + 'MEDIUMTEXT', + 'A TEXT column with a maximum length of 16,777,215 (2^24 - 1) characters, stored with a three-byte prefix indicating the length of the value in bytes' + ), + array( + 'LONGTEXT', + 'A TEXT column with a maximum length of 4,294,967,295 or 4GiB (2^32 - 1) characters, stored with a four-byte prefix indicating the length of the value in bytes' + ), + array( + 'BINARY', + 'Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings' + ), + array( + 'VARBINARY', + 'Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings' + ), + array( + 'TINYBLOB', + 'A BLOB column with a maximum length of 255 (2^8 - 1) bytes, stored with a one-byte prefix indicating the length of the value' + ), + array( + 'MEDIUMBLOB', + 'A BLOB column with a maximum length of 16,777,215 (2^24 - 1) bytes, stored with a three-byte prefix indicating the length of the value' + ), + array( + 'BLOB', + 'A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a two-byte prefix indicating the length of the value' + ), + array( + 'LONGBLOB', + 'A BLOB column with a maximum length of 4,294,967,295 or 4GiB (2^32 - 1) bytes, stored with a four-byte prefix indicating the length of the value' + ), + array( + 'ENUM', + 'An enumeration, chosen from the list of up to 65,535 values or the special \'\' error value' + ), + array( + 'SET', + 'A single value chosen from a set of up to 64 members' + ), + array( + 'GEOMETRY', + 'A type that can store a geometry of any type' + ), + array( + 'POINT', + 'A point in 2-dimensional space' + ), + array( + 'LINESTRING', + 'A curve with linear interpolation between points' + ), + array( + 'POLYGON', + 'A polygon' + ), + array( + 'MULTIPOINT', + 'A collection of points' + ), + array( + 'MULTILINESTRING', + 'A collection of curves with linear interpolation between points' + ), + array( + 'MULTIPOLYGON', + 'A collection of polygons' + ), + array( + 'GEOMETRYCOLLECTION', + 'A collection of geometry objects of any type' + ), + array( + 'UNKNOWN', + '' + ) + ); + } + + /** + * Test for getTypeClass + * + * @param $type + * @param $output + * + * @dataProvider providerFortTestGetTypeClass + */ + public function testGetTypeClass($type, $output){ + $this->assertEquals( + $this->object->getTypeClass($type), + $output + ); + } + + public function providerFortTestGetTypeClass(){ + return array( + array( + 'SERIAL', + 'NUMBER' + ), + array( + 'YEAR', + 'DATE' + ), + array( + 'GEOMETRYCOLLECTION', + 'SPATIAL' + ), + array( + 'SET', + 'CHAR' + ), + array( + 'UNKNOWN', + '' + ) + ); + } + + /** + * Test for getFunctionsClass + * + * @param string $class The class to get function list. + * @param $output array + * + * @dataProvider providerFortTestGetFunctionsClass + */ + public function testGetFunctionsClass($class, $output){ + + if (! defined('PMA_MYSQL_INT_VERSION')) { + define('PMA_MYSQL_INT_VERSION', 50000); + } + + $this->assertEquals( + $this->object->getFunctionsClass($class), + $output + ); + } + + public function providerFortTestGetFunctionsClass(){ + return array( + array( + 'CHAR', + array( + 'BIN', + 'CHAR', + 'CURRENT_USER', + 'COMPRESS', + 'DATABASE', + 'DAYNAME', + 'DES_DECRYPT', + 'DES_ENCRYPT', + 'ENCRYPT', + 'HEX', + 'INET_NTOA', + 'LOAD_FILE', + 'LOWER', + 'LTRIM', + 'MD5', + 'MONTHNAME', + 'OLD_PASSWORD', + 'PASSWORD', + 'QUOTE', + 'REVERSE', + 'RTRIM', + 'SHA1', + 'SOUNDEX', + 'SPACE', + 'TRIM', + 'UNCOMPRESS', + 'UNHEX', + 'UPPER', + 'USER', + 'UUID', + 'VERSION', + ) + ), + array( + 'DATE', + array( + 'CURRENT_DATE', + 'CURRENT_TIME', + 'DATE', + 'FROM_DAYS', + 'FROM_UNIXTIME', + 'LAST_DAY', + 'NOW', + 'SEC_TO_TIME', + 'SYSDATE', + 'TIME', + 'TIMESTAMP', + 'UTC_DATE', + 'UTC_TIME', + 'UTC_TIMESTAMP', + 'YEAR', + ) + ), + array( + 'SPATIAL', + array( + 'GeomFromText', + 'GeomFromWKB', + + 'GeomCollFromText', + 'LineFromText', + 'MLineFromText', + 'PointFromText', + 'MPointFromText', + 'PolyFromText', + 'MPolyFromText', + + 'GeomCollFromWKB', + 'LineFromWKB', + 'MLineFromWKB', + 'PointFromWKB', + 'MPointFromWKB', + 'PolyFromWKB', + 'MPolyFromWKB', + ) + ), + array( + 'NUMBER', + array( + '0' => 'ABS', + '1' => 'ACOS', + '2' => 'ASCII', + '3' => 'ASIN', + '4' => 'ATAN', + '5' => 'BIT_LENGTH', + '6' => 'BIT_COUNT', + '7' => 'CEILING', + '8' => 'CHAR_LENGTH', + '9' => 'CONNECTION_ID', + '10' => 'COS', + '11' => 'COT', + '12' => 'CRC32', + '13' => 'DAYOFMONTH', + '14' => 'DAYOFWEEK', + '15' => 'DAYOFYEAR', + '16' => 'DEGREES', + '17' => 'EXP', + '18' => 'FLOOR', + '19' => 'HOUR', + '20' => 'INET_ATON', + '21' => 'LENGTH', + '22' => 'LN', + '23' => 'LOG', + '24' => 'LOG2', + '25' => 'LOG10', + '26' => 'MICROSECOND', + '27' => 'MINUTE', + '28' => 'MONTH', + '29' => 'OCT', + '30' => 'ORD', + '31' => 'PI', + '32' => 'QUARTER', + '33' => 'RADIANS', + '34' => 'RAND', + '35' => 'ROUND', + '36' => 'SECOND', + '37' => 'SIGN', + '38' => 'SIN', + '39' => 'SQRT', + '40' => 'TAN', + '41' => 'TO_DAYS', + '43' => 'TIME_TO_SEC', + '44' => 'UNCOMPRESSED_LENGTH', + '45' => 'UNIX_TIMESTAMP', + '47' => 'WEEK', + '48' => 'WEEKDAY', + '49' => 'WEEKOFYEAR', + '50' => 'YEARWEEK' + ) + ), + array( + 'UNKNOWN', + array() + ) + ); + } + + /** + * Test for getAttributes + */ + public function testGetAttributes(){ + $this->assertEquals( + $this->object->getAttributes(), + array( + '', + 'BINARY', + 'UNSIGNED', + 'UNSIGNED ZEROFILL', + 'on update CURRENT_TIMESTAMP', + ) + ); + } + + /** + * Test for getColumns + */ + public function testGetColumns(){ + $this->assertEquals( + $this->object->getColumns(), + array( + 0 => 'INT', + 1 => 'VARCHAR', + 2 => 'TEXT', + 3 => 'DATE', + 'Numeric' => array ( + 'TINYINT', + 'SMALLINT', + 'MEDIUMINT', + 'INT', + 'BIGINT', + '-', + 'DECIMAL', + 'FLOAT', + 'DOUBLE', + 'REAL', + '-', + 'BIT', + 'BOOLEAN', + 'SERIAL', + ), + 'Date and time' => array ( + 'DATE', + 'DATETIME', + 'TIMESTAMP', + 'TIME', + 'YEAR', + ), + 'String' => array ( + 'CHAR', + 'VARCHAR', + '-', + 'TINYTEXT', + 'TEXT', + 'MEDIUMTEXT', + 'LONGTEXT', + '-', + 'BINARY', + 'VARBINARY', + '-', + 'TINYBLOB', + 'MEDIUMBLOB', + 'BLOB', + 'LONGBLOB', + '-', + 'ENUM', + 'SET', + ), + 'Spatial' => array ( + 'GEOMETRY', + 'POINT', + 'LINESTRING', + 'POLYGON', + 'MULTIPOINT', + 'MULTILINESTRING', + 'MULTIPOLYGON', + 'GEOMETRYCOLLECTION', + ) + ) + ); + } +} diff --git a/test/classes/PMA_Types_test.php b/test/classes/PMA_Types_test.php index 1481763690..4875211d52 100644 --- a/test/classes/PMA_Types_test.php +++ b/test/classes/PMA_Types_test.php @@ -1,5 +1,13 @@ assertTrue(true); + /** + * Test for getTypeOperatorsHtml + * + * @param string $type Type of field + * @param boolean $null Whether field can be NULL + * @param string $selectedOperator Option to be selected + * @param $output + * + * @dataProvider providerForTestGetTypeOperatorsHtml + */ + public function testGetTypeOperatorsHtml($type, $null, $selectedOperator, $output){ + $this->assertEquals( + $this->object->getTypeOperatorsHtml($type, $null, $selectedOperator), + $output + ); + } + + /** + * Provider for testGetTypeOperatorsHtml + */ + public function providerForTestGetTypeOperatorsHtml(){ + return array( + array( + 'enum', + false, + '=', + '' + ) + ); + } + + /** + * Test for getTypeDescription + */ + public function testGetTypeDescription(){ + $this->assertEquals( + $this->object->getTypeDescription('enum'), + '' + ); + } + + /** + * Test for getFunctionsClass + */ + public function testGetFunctionsClass(){ + $this->assertEquals( + $this->object->getFunctionsClass('enum'), + array() + ); + } + + /** + * Test for getFunctions + */ + public function testGetFunctions(){ + $this->assertEquals( + $this->object->getFunctions('enum'), + array() + ); + } + + /** + * Test for getAllFunctions + */ + public function testGetAllFunctions(){ + $this->assertEquals( + $this->object->getAllFunctions(), + array() + ); + } + + /** + * Test for getAttributes + */ + public function testGetAttributes(){ + $this->assertEquals( + $this->object->getAttributes(), + array() + ); + } + + /** + * Test for getColumns + */ + public function testGetColumns(){ + $this->assertEquals( + $this->object->getColumns(), + array( + 'INT', + 'VARCHAR', + 'TEXT', + 'DATE', + ) + ); } } ?> From ded761f64e0363cf3fce5278778594fc183b63d0 Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Thu, 5 Jul 2012 23:51:35 +0530 Subject: [PATCH 04/11] Test cases for PMA_Types_Drizzle class --- test/classes/PMA_Types_Drizzle_test.php | 366 ++++++++++++++++++++++++ test/classes/PMA_Types_test.php | 2 +- 2 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 test/classes/PMA_Types_Drizzle_test.php diff --git a/test/classes/PMA_Types_Drizzle_test.php b/test/classes/PMA_Types_Drizzle_test.php new file mode 100644 index 0000000000..a6b93fa519 --- /dev/null +++ b/test/classes/PMA_Types_Drizzle_test.php @@ -0,0 +1,366 @@ +object = new PMA_Types_Drizzle(); + } + + /** + * Test for getTypeDescription + * + * @param string $type The data type to get a description. + * @param $output string + * + * @dataProvider providerForTestGetTypeDescription + */ + public function testGetTypeDescription($type, $output){ + $this->assertEquals( + $this->object->getTypeDescription($type), + $output + ); + } + + /** + * Provider for testGetTypeDescription + * @return array + */ + public function providerForTestGetTypeDescription(){ + return array( + array( + 'INTEGER', + 'A 4-byte integer, range is -2,147,483,648 to 2,147,483,647' + ), + array( + 'BIGINT', + 'An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807' + ), + array( + 'DECIMAL', + 'A fixed-point number (M, D) - the maximum number of digits (M) is 65 (default 10), the maximum number of decimals (D) is 30 (default 0)' + ), + array( + 'DOUBLE', + 'A system\'s default double-precision floating-point number' + ), + array( + 'BOOLEAN', + 'True or false' + ), + array( + 'SERIAL', + 'An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE' + ), + array( + 'UUID', + 'Stores a Universally Unique Identifier (UUID)' + ), + array( + 'DATE', + 'A date, supported range is 0001-01-01 to 9999-12-31' + ), + array( + 'DATETIME', + 'A date and time combination, supported range is 0001-01-01 00:00:0 to 9999-12-31 23:59:59' + ), + array( + 'TIMESTAMP', + 'A timestamp, range is \'0001-01-01 00:00:00\' UTC to \'9999-12-31 23:59:59\' UTC; TIMESTAMP(6) can store microseconds' + ), + array( + 'TIME', + 'A time, range is 00:00:00 to 23:59:59' + ), + array( + 'VARCHAR', + 'A variable-length (0-16,383) string, the effective maximum length is subject to the maximum row size' + ), + array( + 'TEXT', + 'A TEXT column with a maximum length of 65,535 (2^16 - 1) characters, stored with a two-byte prefix indicating the length of the value in bytes' + ), + array( + 'VARBINARY', + 'A variable-length (0-65,535) string, uses binary collation for all comparisons' + ), + array( + 'BLOB', + 'A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a four-byte prefix indicating the length of the value' + ), + array( + 'ENUM', + 'An enumeration, chosen from the list of defined values' + ), + array( + 'UNKNOWN', + '' + ) + ); + } + + /** + * Test for getTypeClass + * + * @param $type + * @param $output + * + * @dataProvider providerFortTestGetTypeClass + */ + public function testGetTypeClass($type, $output){ + $this->assertEquals( + $this->object->getTypeClass($type), + $output + ); + } + + public function providerFortTestGetTypeClass(){ + return array( + array( + 'SERIAL', + 'NUMBER' + ), + array( + 'TIME', + 'DATE' + ), + array( + 'ENUM', + 'CHAR' + ), + array( + 'UUID', + 'UUID' + ), + array( + 'UNKNOWN', + '' + ) + ); + } + + /** + * Test for getFunctionsClass + * + * @param string $class The class to get function list. + * @param $output array + * + * @dataProvider providerFortTestGetFunctionsClass + */ + public function testGetFunctionsClass($class, $output){ + + if (! function_exists('PMA_DBI_fetch_result')) { + function PMA_DBI_fetch_result($query) + { + return array('table1', 'table`2'); + } + } + + $this->assertEquals( + $this->object->getFunctionsClass($class), + $output + ); + } + + /** + * Provider for testGetFunctionsClass + * @return array + */ + public function providerFortTestGetFunctionsClass(){ + return array( + array( + 'UUID', + array( + 'UUID' + ) + ), + array( + 'DATE', + array( + 'CURRENT_DATE', + 'CURRENT_TIME', + 'DATE', + 'FROM_DAYS', + 'FROM_UNIXTIME', + 'LAST_DAY', + 'NOW', + 'SYSDATE', + 'TIMESTAMP', + 'UTC_DATE', + 'UTC_TIME', + 'UTC_TIMESTAMP', + 'YEAR', + ) + ), + array( + 'NUMBER', + array( + 'ABS', + 'ACOS', + 'ASCII', + 'ASIN', + 'ATAN', + 'BIT_COUNT', + 'CEILING', + 'CHAR_LENGTH', + 'CONNECTION_ID', + 'COS', + 'COT', + 'CRC32', + 'DAYOFMONTH', + 'DAYOFWEEK', + 'DAYOFYEAR', + 'DEGREES', + 'EXP', + 'FLOOR', + 'HOUR', + 'LENGTH', + 'LN', + 'LOG', + 'LOG2', + 'LOG10', + 'MICROSECOND', + 'MINUTE', + 'MONTH', + 'OCT', + 'ORD', + 'PI', + 'QUARTER', + 'RADIANS', + 'RAND', + 'ROUND', + 'SECOND', + 'SIGN', + 'SIN', + 'SQRT', + 'TAN', + 'TO_DAYS', + 'TIME_TO_SEC', + 'UNCOMPRESSED_LENGTH', + 'UNIX_TIMESTAMP', + //'WEEK', // same as TIME + 'WEEKDAY', + 'WEEKOFYEAR', + 'YEARWEEK', + ) + ), + array( + 'CHAR', + array( + 0 => 'BIN', + 1 => 'CHAR', + 2 => 'COMPRESS', + 3 => 'CURRENT_USER', + 4 => 'DATABASE', + 5 => 'DAYNAME', + 6 => 'HEX', + 7 => 'LOAD_FILE', + 8 => 'LOWER', + 9 => 'LTRIM', + 10 => 'MD5', + 11 => 'MONTHNAME', + 12 => 'QUOTE', + 13 => 'REVERSE', + 14 => 'RTRIM', + 15 => 'SCHEMA', + 16 => 'SPACE', + 17 => 'TRIM', + 18 => 'UNCOMPRESS', + 19 => 'UNHEX', + 20 => 'UPPER', + 21 => 'USER', + 22 => 'UUID', + 23 => 'VERSION', + 24 => 'table1', + 25 => 'table`2' + ) + ), + array( + 'UNKNOWN', + array() + ) + ); + } + + /** + * Test for getAttributes + */ + public function testGetAttributes(){ + $this->assertEquals( + $this->object->getAttributes(), + array( + '', + 'on update CURRENT_TIMESTAMP', + ) + ); + } + + /** + * Test for getColumns + */ + public function testGetColumns(){ + + if (! defined('PMA_MYSQL_INT_VERSION')) { + define('PMA_MYSQL_INT_VERSION', 20120130); + } + + $this->assertEquals( + $this->object->getColumns(), + array( + 0 => 'INT', + 1 => 'VARCHAR', + 2 => 'TEXT', + 3 => 'DATE', + 'Numeric' => array ( + 'INTEGER', + 'BIGINT', + '-', + 'DECIMAL', + 'DOUBLE', + '-', + 'BOOLEAN', + 'SERIAL', + 'UUID', + ), + 'Date and time' => array ( + 'DATE', + 'DATETIME', + 'TIMESTAMP', + 'TIME', + ), + 'String' => array ( + 'VARCHAR', + 'TEXT', + '-', + 'VARBINARY', + 'BLOB', + '-', + 'ENUM', + '-', + 'IPV6' + ), + ) + ); + } +} diff --git a/test/classes/PMA_Types_test.php b/test/classes/PMA_Types_test.php index 4875211d52..35f340b1d1 100644 --- a/test/classes/PMA_Types_test.php +++ b/test/classes/PMA_Types_test.php @@ -27,7 +27,7 @@ class PMA_TypesTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->object = new PMA_Types; + $this->object = new PMA_Types(); } /** From 15ca02031f4a43016c4f7109a4f2b3a8e2ccc887 Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Fri, 6 Jul 2012 10:48:55 +0530 Subject: [PATCH 05/11] Improve test cases for PMA_Theme_test.php --- test/classes/PMA_Theme_test.php | 208 +++++++++++++++++++++++++++++--- 1 file changed, 188 insertions(+), 20 deletions(-) diff --git a/test/classes/PMA_Theme_test.php b/test/classes/PMA_Theme_test.php index 51369ba7a7..d65f2a0e6c 100644 --- a/test/classes/PMA_Theme_test.php +++ b/test/classes/PMA_Theme_test.php @@ -8,6 +8,7 @@ require_once 'libraries/Config.class.php'; require_once 'libraries/Theme_Manager.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/sqlparser.lib.php'; +require_once 'libraries/url_generating.lib.php'; /** * Test class for PMA_Theme. @@ -214,30 +215,197 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase } /** - * Test for loading CSS files. * - * @return nothing - * - * @todo Needs to be revisited as original test is somehow broken. - */ - public function testLoadCss() - { - $this->markTestIncomplete( - 'This test seems to cause some problems in output buffering handling' - ); - //$this->expectOutputRegex('/.*FILE: codemirror.css.php.*/'); - //$this->assertTrue($this->object->loadCss()); - } - - /** - * - * @todo Implement testPrintPreview(). + * Test for getPrintPreview(). */ public function testPrintPreview() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + $this->assertEquals( + $this->object->getPrintPreview(), + '' + ); + } + + /** + * Test for getCssIEClearFilter + */ + public function testGetCssIEClearFilter(){ + $this->assertEquals( + $this->object->getCssIEClearFilter(), + '' + ); + } + + /** + * Test for getFontSize + */ + public function testGetFontSize(){ + $this->assertEquals( + $this->object->getFontSize(), + '82%' + ); + + $_COOKIE['pma_fontsize'] = '14px'; + $this->assertEquals( + $this->object->getFontSize(), + '14px' + ); + + $GLOBALS['PMA_Config']->set('fontsize','12px'); + $this->assertEquals( + $this->object->getFontSize(), + '12px' + ); + + } + + /** + * Test for getCssGradient + */ + public function testgetCssGradient(){ + $this->assertEquals( + $this->object->getCssGradient('12345', '54321'), + 'background-image: url(./themes/svg_gradient.php?from=12345&to=54321); +background-size: 100% 100%; +background: -webkit-gradient(linear, left top, left bottom, from(#12345), to(#54321)); +background: -webkit-linear-gradient(top, #12345, #54321); +background: -moz-linear-gradient(top, #12345, #54321); +background: -ms-linear-gradient(top, #12345, #54321); +background: -o-linear-gradient(top, #12345, #54321);' + ); + } + + /** + * Test for getCssCodeMirror + */ + public function testGetCssCodeMirror(){ + $this->assertEquals( + $this->object->getCssCodeMirror(), + 'span.cm-keyword, span.cm-statement-verb { + color: #909; +} +span.cm-variable { + color: black; +} +span.cm-comment { + color: #808000; +} +span.cm-mysql-string { + color: #008000; +} +span.cm-operator { + color: fuchsia; +} +span.cm-mysql-word { + color: black; +} +span.cm-builtin { + color: #f00; +} +span.cm-variable-2 { + color: #f90; +} +span.cm-variable-3 { + color: #00f; +} +span.cm-separator { + color: fuchsia; +} +span.cm-number { + color: teal; +}' + ); + + $GLOBALS['cfg']['CodemirrorEnable'] = false; + $this->assertEquals( + $this->object->getCssCodeMirror(), + '' + ); + } + + /** + * Test for getImgPath + * @param string $file file name for image + * @param $output + * + * @dataProvider providerForGetImgPath + */ + public function testGetImgPath($file, $output){ + $this->assertEquals( + $this->object->getImgPath($file), + $output + ); + } + + /** + * Provider for testGetImgPath + * @return array + */ + public function providerForGetImgPath(){ + return array( + array( + null, + '' + ), + array( + 'screen.png', + './themes/pmahomme/img/screen.png' + ), + array( + 'arrow_ltr.png', + './themes/pmahomme/img/arrow_ltr.png' + ) + + ); + } + + /** + * Test for buildSQPCssRule + */ + public function testBuildSQPCssRule(){ + $this->assertEquals( + $this->object->buildSQPCssRule('PMA_Config', 'fontSize', '12px'), + '.PMA_Config {fontSize: 12px;} +' + ); + } + + /** + * Test for buildSQPCssData + */ + public function testBuildSQPCssData(){ + $this->assertEquals( + $this->object->buildSQPCssData(), + '.syntax_comment {color: #808000;} +.syntax_comment_mysql {} +.syntax_comment_ansi {} +.syntax_comment_c {} +.syntax_digit {} +.syntax_digit_hex {color: teal;} +.syntax_digit_integer {color: teal;} +.syntax_digit_float {color: aqua;} +.syntax_punct {color: fuchsia;} +.syntax_alpha {} +.syntax_alpha_columnType {color: #f90;} +.syntax_alpha_columnAttrib {color: #00f;} +.syntax_alpha_reservedWord {color: #909;} +.syntax_alpha_functionName {color: #f00;} +.syntax_alpha_identifier {color: black;} +.syntax_alpha_charset {color: #6495ed;} +.syntax_alpha_variable {color: #800000;} +.syntax_quote {color: #008000;} +.syntax_quote_double {} +.syntax_quote_single {} +.syntax_quote_backtick {} +.syntax_indent0 {margin-left: 0em;} +.syntax_indent1 {margin-left: 1em;} +.syntax_indent2 {margin-left: 2em;} +.syntax_indent3 {margin-left: 3em;} +.syntax_indent4 {margin-left: 4em;} +.syntax_indent5 {margin-left: 5em;} +.syntax_indent6 {margin-left: 6em;} +.syntax_indent7 {margin-left: 7em;} +' ); } } From 51a232cf7d4094cf81ae0eee3e77d1cefdd4d617 Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Fri, 6 Jul 2012 11:20:43 +0530 Subject: [PATCH 06/11] Improve test cases for PMA_Theme_Manager --- test/classes/PMA_Theme_Manager_test.php | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/classes/PMA_Theme_Manager_test.php b/test/classes/PMA_Theme_Manager_test.php index ad8bdd818b..d9c7bfbec1 100644 --- a/test/classes/PMA_Theme_Manager_test.php +++ b/test/classes/PMA_Theme_Manager_test.php @@ -14,6 +14,8 @@ require_once 'libraries/url_generating.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Theme.class.php'; require_once 'libraries/Theme_Manager.class.php'; +require_once 'libraries/Config.class.php'; +require_once 'libraries/core.lib.php'; class PMA_Theme_Manager_test extends PHPUnit_Framework_TestCase { @@ -25,6 +27,7 @@ class PMA_Theme_Manager_test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['ServerDefault'] = 0; $GLOBALS['server'] = 99; $_SESSION[' PMA_token '] = 'token'; + $GLOBALS['PMA_Config'] = new PMA_Config(); } public function testCookieName() @@ -46,5 +49,58 @@ class PMA_Theme_Manager_test extends PHPUnit_Framework_TestCase $this->assertContains('