diff --git a/test/classes/Advisor_test.php b/test/classes/PMA_Advisor_test.php similarity index 100% rename from test/classes/Advisor_test.php rename to test/classes/PMA_Advisor_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_List_Database'); + } + + /** + * Call protected functions by making the visibitlity to public. + * + * @param string $name method name + * @param array $params parameters for the invocation + * + * @return the output from the protected method. + */ + private function _callProtectedFunction($name, $params) + { + $class = new ReflectionClass('PMA_List_Database'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs($this->object, $params); } public function testEmpty() @@ -54,5 +72,73 @@ class PMA_List_Database_test extends PHPUnit_Framework_TestCase $arr = new PMA_List_Database; $this->assertEquals('' . "\n", $arr->getHtmlOptions()); } + + /** + * Test for checkHideDatabase + */ + public function testCheckHideDatabase() + { + $GLOBALS['cfg']['Server']['hide_db'] = array('single\\_db'); + $this->assertEquals( + $this->_callProtectedFunction( + 'checkHideDatabase', + array() + ), + '' + ); + } + + /** + * Test for getDefault + */ + public function testGetDefault() + { + $GLOBALS['db'] = ''; + $this->assertEquals( + $this->object->getDefault(), + '' + ); + + $GLOBALS['db'] = 'mysql'; + $this->assertEquals( + $this->object->getDefault(), + 'mysql' + ); + } + + /** + * Test for getGroupedDetails + */ + public function testGetGroupedDetails() + { + $GLOBALS['cfg']['ShowTooltip'] = true; + $GLOBALS['cfgRelation']['commwork'] = true; + $GLOBALS['server'] = 1; + $GLOBALS['cfg']['LeftFrameDBTree'] = true; + $GLOBALS['cfg']['LeftFrameDBSeparator'] = array('|',','); + + $this->assertEquals( + $this->object->getGroupedDetails(10, 100), + array() + ); + } + + /** + * Test for getHtmlListGrouped + */ + public function testGetHtmlListGrouped() + { + $GLOBALS['cfg']['ShowTooltip'] = true; + $GLOBALS['cfgRelation']['commwork'] = true; + $GLOBALS['server'] = 1; + $GLOBALS['cfg']['LeftFrameDBTree'] = true; + $GLOBALS['cfg']['LeftFrameDBSeparator'] = array('|',','); + + $this->assertEquals( + $this->object->getHtmlListGrouped(true,5,5), + '' + ); + } } ?> diff --git a/test/classes/PMA_Scripts_test.php b/test/classes/PMA_Scripts_test.php new file mode 100644 index 0000000000..ef26ed54e3 --- /dev/null +++ b/test/classes/PMA_Scripts_test.php @@ -0,0 +1,137 @@ +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(), + '' + ); + } +} diff --git a/test/classes/PMA_StorageEngine_test.php b/test/classes/PMA_StorageEngine_test.php new file mode 100644 index 0000000000..db587918f2 --- /dev/null +++ b/test/classes/PMA_StorageEngine_test.php @@ -0,0 +1,240 @@ +'table1', + 'table`2'); + } + } + $this->object = $this->getMockForAbstractClass('PMA_StorageEngine', array('dummy')); + } + + /** + * 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); + } + + /** + * Test for getStorageEngines + */ + public function testGetStorageEngines(){ + + $this->assertEquals( + $this->object->getStorageEngines(), + array( + 'dummy' => 'table1', + 0 => 'table`2' + ) + ); + } + + /** + * Test for getHtmlSelect + */ + public function testGetHtmlSelect(){ + + $this->assertEquals( + $this->object->getHtmlSelect(), + ' +' + ); + } + + /** + * Test for getEngine + */ + public function testGetEngine(){ + + $this->assertTrue( + $this->object->getEngine('dummy') instanceof PMA_StorageEngine + ); + } + + /** + * Test for isValid + */ + public function testIsValid(){ + + $this->assertTrue( + $this->object->isValid('PBMS') + ); + $this->assertTrue( + $this->object->isValid('dummy') + ); + } + + /** + * Test for getPage + */ + public function testGetPage(){ + + $this->assertFalse( + $this->object->getPage(1) + ); + } + + /** + * Test for getInfoPages + */ + public function testGetInfoPages(){ + + $this->assertEquals( + $this->object->getInfoPages(), + array() + ); + } + + /** + * Test for getVariablesLikePattern + */ + public function testGetVariablesLikePattern(){ + + $this->assertFalse( + $this->object->getVariablesLikePattern() + ); + } + + /** + * Test for getMysqlHelpPage + */ + public function testGetMysqlHelpPage(){ + + $this->assertEquals( + $this->object->getMysqlHelpPage(), + 'dummy-storage-engine' + ); + } + + /** + * Test for getVariables + */ + public function testGetVariables(){ + + $this->assertEquals( + $this->object->getVariables(), + array() + ); + } + + /** + * Test for getSupportInformationMessage + */ + public function testGetSupportInformationMessage(){ + $this->assertEquals( + $this->object->getSupportInformationMessage(), + 'This MySQL server does not support the t storage engine.' + ); + + $this->object->support = 1; + $this->assertEquals( + $this->object->getSupportInformationMessage(), + 't has been disabled for this MySQL server.' + ); + + $this->object->support = 2; + $this->assertEquals( + $this->object->getSupportInformationMessage(), + 't is available on this MySQL server.' + ); + + $this->object->support = 3; + $this->assertEquals( + $this->object->getSupportInformationMessage(), + 't is the default storage engine on this MySQL server.' + ); + } + + /** + * Test for getComment + */ + public function testGetComment(){ + + $this->assertEquals( + $this->object->getComment(), + 't' + ); + } + + /** + * Test for getTitle + */ + public function testGetTitle(){ + + $this->assertEquals( + $this->object->getTitle(), + 't' + ); + } + + /** + * Test for engine_init + */ + public function testEngine_init(){ + + $this->assertNull( + $this->object->engine_init() + ); + } + + /** + * Test for resolveTypeSize + */ + public function testResolveTypeSize(){ + + $this->assertEquals( + $this->object->resolveTypeSize(12), + array( + 0 => 12, + 1 => 'B' + ) + ); + } +} 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('' + ) + ); + } + + /** + * 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', + ) + ); + } } ?> diff --git a/test/classes/gis/PMA_GIS_Geom_test.php b/test/classes/gis/PMA_GIS_Geom_test.php index 963a243a57..f0c67eb420 100644 --- a/test/classes/gis/PMA_GIS_Geom_test.php +++ b/test/classes/gis/PMA_GIS_Geom_test.php @@ -15,28 +15,6 @@ require_once 'libraries/gis/pma_gis_geometry.php'; */ abstract class PMA_GIS_GeomTest extends PHPUnit_Framework_TestCase { - /** - * test generateWkt method - * - * @param array $gis_data array of GIS data - * @param int $index index - * @param string $empty string to be insterted in place of missing values - * @param string $wkt expected WKT - * - * @return void - * @dataProvider providerForTestGenerateWkt - */ - public function testGenerateWkt($gis_data, $index, $empty, $wkt) - { - if ($empty == null) { - $this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt); - } else { - $this->assertEquals( - $this->object->generateWkt($gis_data, $index, $empty), - $wkt - ); - } - } /** * test generateParams method diff --git a/test/libraries/PMA_bookmark_test.php b/test/libraries/PMA_bookmark_test.php new file mode 100644 index 0000000000..7454299905 --- /dev/null +++ b/test/libraries/PMA_bookmark_test.php @@ -0,0 +1,125 @@ + 'id', + 'label' => 'label' + ); + } + } + + if (! defined('PMA_DBI_QUERY_STORE')) { + define('PMA_DBI_QUERY_STORE', 1); + } + + $GLOBALS['cfg']['Server']['user'] = 'root'; + $GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin'; + $GLOBALS['cfg']['Server']['bookmarktable'] = 'pma_bookmark'; + $GLOBALS['server'] = 1; + + require_once 'libraries/bookmark.lib.php'; + } + /** + * Test for PMA_Bookmark_getParams + */ + public function testPMA_Bookmark_getParams(){ + + $this->assertEquals( + PMA_Bookmark_getParams(), + array( + 'user' => 'root', + 'db' => 'phpmyadmin', + 'table'=> 'pma_bookmark' + ) + ); + } + + /** + * Test for PMA_Bookmark_getList + */ + public function testPMA_Bookmark_getList(){ + $this->assertEquals( + PMA_Bookmark_getList('phpmyadmin'), + array( + 'id' => 'id (shared)', + 'label' => 'label (shared)' + ) + ); + } + + /** + * Test for PMA_Bookmark_get + */ + public function testPMA_Bookmark_get(){ + if (! function_exists('PMA_DBI_fetch_value')) { + function PMA_DBI_fetch_value() + { + return "SELECT query FROM `phpmyadmin`.`pma_bookmark` WHERE dbase = 'phpmyadmin' AND (user = 'root' OR user = '') AND `id` = 1"; + } + } + $this->assertEquals( + PMA_Bookmark_get('phpmyadmin', '1'), + "SELECT query FROM `phpmyadmin`.`pma_bookmark` WHERE dbase = 'phpmyadmin' AND (user = 'root' OR user = '') AND `id` = 1" + ); + } + + /** + * Test for PMA_Bookmark_save + */ + public function testPMA_Bookmark_save(){ + if (! function_exists('PMA_DBI_query')) { + function PMA_DBI_query() + { + return true; + } + } + $this->assertEquals( + PMA_Bookmark_save('phpmyadmin'), + true + ); + } + + /** + * Test for PMA_Bookmark_delete + */ + public function testPMA_Bookmark_delete(){ + if (! function_exists('PMA_DBI_try_query')) { + function PMA_DBI_try_query() + { + return true; + } + } + $this->assertEquals( + PMA_Bookmark_delete('phpmyadmin', '1'), + true + ); + } +} diff --git a/test/libraries/PMA_build_html_for_db_test.php b/test/libraries/PMA_build_html_for_db_test.php new file mode 100644 index 0000000000..c05d5b4352 --- /dev/null +++ b/test/libraries/PMA_build_html_for_db_test.php @@ -0,0 +1,155 @@ +assertEquals( + PMA_getColumnOrder(), + array( + 'DEFAULT_COLLATION_NAME' => array( + 'disp_name' => __('Collation'), + 'description_function' => 'PMA_getCollationDescr', + 'format' => 'string', + 'footer' => 'footer' + ), + 'SCHEMA_TABLES' => array( + 'disp_name' => __('Tables'), + 'format' => 'number', + 'footer' => 0 + ), + 'SCHEMA_TABLE_ROWS' => array( + 'disp_name' => __('Rows'), + 'format' => 'number', + 'footer' => 0 + ), + 'SCHEMA_DATA_LENGTH' => array( + 'disp_name' => __('Data'), + 'format' => 'byte', + 'footer' => 0 + ), + 'SCHEMA_INDEX_LENGTH' => array( + 'disp_name' => __('Indexes'), + 'format' => 'byte', + 'footer' => 0 + ), + 'SCHEMA_LENGTH' => array( + 'disp_name' => __('Total'), + 'format' => 'byte', + 'footer' => 0 + ), + 'SCHEMA_DATA_FREE' => array( + 'disp_name' => __('Overhead'), + 'format' => 'byte', + 'footer' => 0 + ) + ) + ); + } + + /** + * Test for PMA_buildHtmlForDb + * + * @param array $current + * @param boolean $is_superuser + * @param string $checkall + * @param string $url_query + * @param array $column_order + * @param array $replication_types + * @param array $replication_info + * @param $output + * + * @dataProvider providerForTestPMA_buildHtmlForDb + */ + public function testPMA_buildHtmlForDb($current, $is_superuser, $checkall, $url_query,$column_order, $replication_types, $replication_info, $output){ + + if (! function_exists('PMA_is_system_schema')) { + function PMA_is_system_schema() + { + return false; + } + } + if (! function_exists('p')) { + function p() + { + return; + } + } + if (! defined('PMA_DRIZZLE')) { + define('PMA_DRIZZLE', false); + } + + $GLOBALS['cfg']['PropertiesIconic'] = true; + $_SESSION['PMA_Theme'] = new PMA_Theme(); + $GLOBALS['pmaThemeImage'] = ''; + + $this->assertEquals( + PMA_buildHtmlForDb($current, $is_superuser, $checkall, $url_query, + $column_order, $replication_types, $replication_info), + $output + ); + } + + public function providerForTestPMA_buildHtmlForDb(){ + return array( + array( + array('SCHEMA_NAME' => 'pma'), + true, + '', + 'target=main.php', + array( + 'SCHEMA_NAME' => 'pma', + 'footer' => 1, + 'format' => 'byte', + 'description_function' => 'onClick' + ), + array( + 'SCHEMA_NAME' => 'pma', + ), + array( + 'pma' => array( + 'status' => 'true', + 'Ignore_DB' => array( + 'pma' => 'pma' + ), + ) + ), + array( + 0 => array( + 'SCHEMA_NAME' => 'pma', + 'footer' => 1, + 'format' => 'byte', + 'description_function' => 'onClick' + ), + 1 => ' pmapmaNot replicated Check Privileges' + ) + ) + ); + } +} diff --git a/test/libraries/js_escape_test.php b/test/libraries/PMA_js_escape_test.php similarity index 100% rename from test/libraries/js_escape_test.php rename to test/libraries/PMA_js_escape_test.php diff --git a/test/libraries/common/PMA_buildActionTitles_test.php b/test/libraries/common/PMA_buildActionTitles_test.php index ca8d6baa17..c6dc8f2a0c 100644 --- a/test/libraries/common/PMA_buildActionTitles_test.php +++ b/test/libraries/common/PMA_buildActionTitles_test.php @@ -12,6 +12,7 @@ */ require_once 'libraries/CommonFunctions.class.php'; require_once 'libraries/Theme.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_buildActionTitles_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_formatNumberByteDown_test.php b/test/libraries/common/PMA_formatNumberByteDown_test.php index 5d67a2940f..1873c42c4b 100644 --- a/test/libraries/common/PMA_formatNumberByteDown_test.php +++ b/test/libraries/common/PMA_formatNumberByteDown_test.php @@ -11,6 +11,7 @@ * Include to test. */ require_once 'libraries/CommonFunctions.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_getFormattedMaximumUploadSize_test.php b/test/libraries/common/PMA_getFormattedMaximumUploadSize_test.php index fba43a5ca2..7507308eb0 100644 --- a/test/libraries/common/PMA_getFormattedMaximumUploadSize_test.php +++ b/test/libraries/common/PMA_getFormattedMaximumUploadSize_test.php @@ -11,6 +11,7 @@ * Include to test. */ require_once 'libraries/CommonFunctions.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_getFormattedMaximumUploadSize_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_getTitleForTarget_test.php b/test/libraries/common/PMA_getTitleForTarget_test.php index c68210d79b..38de533791 100644 --- a/test/libraries/common/PMA_getTitleForTarget_test.php +++ b/test/libraries/common/PMA_getTitleForTarget_test.php @@ -11,6 +11,7 @@ * Include to test. */ require_once 'libraries/CommonFunctions.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_getTitleForTarget_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_localisedDateTimespan_test.php b/test/libraries/common/PMA_localisedDateTimespan_test.php index ef7ab7c96d..b7b8523cf4 100644 --- a/test/libraries/common/PMA_localisedDateTimespan_test.php +++ b/test/libraries/common/PMA_localisedDateTimespan_test.php @@ -11,6 +11,7 @@ * Include to test. */ require_once 'libraries/CommonFunctions.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_showDocu_test.php b/test/libraries/common/PMA_showDocu_test.php index 20e1a50b64..79dcc15778 100644 --- a/test/libraries/common/PMA_showDocu_test.php +++ b/test/libraries/common/PMA_showDocu_test.php @@ -12,6 +12,7 @@ */ require_once 'libraries/CommonFunctions.class.php'; require_once 'libraries/Theme.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_showDocu_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_showMessage_test_disabled.php b/test/libraries/common/PMA_showMessage_test_disabled.php index 972d79b9ef..44b37b9d66 100644 --- a/test/libraries/common/PMA_showMessage_test_disabled.php +++ b/test/libraries/common/PMA_showMessage_test_disabled.php @@ -14,7 +14,6 @@ const PMA_IS_WINDOWS = false; */ require_once 'libraries/CommonFunctions.class.php'; require_once 'libraries/Table.class.php'; -require_once 'libraries/database_interface.lib.php'; require_once 'libraries/js_escape.lib.php'; class PMA_showMessage_test extends PHPUnit_Framework_TestCase @@ -22,6 +21,10 @@ class PMA_showMessage_test extends PHPUnit_Framework_TestCase function setUp() { global $cfg; + if (! defined('VERSION_CHECK_DEFAULT')) { + define('VERSION_CHECK_DEFAULT', 1); + } + include 'libraries/config.default.php'; } diff --git a/test/libraries/common/PMA_showPHPDocu_test.php b/test/libraries/common/PMA_showPHPDocu_test.php index 9c31db2472..51ad20c07f 100644 --- a/test/libraries/common/PMA_showPHPDocu_test.php +++ b/test/libraries/common/PMA_showPHPDocu_test.php @@ -13,6 +13,7 @@ require_once 'libraries/core.lib.php'; require_once 'libraries/CommonFunctions.class.php'; require_once 'libraries/Theme.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; class PMA_showPHPDocu_test extends PHPUnit_Framework_TestCase {