From 6f2a532bf030aacdb65f0c29a05d1bbf64ea6b38 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Wed, 17 Jul 2013 17:33:09 +0545 Subject: [PATCH 01/11] Tests for AuthenticationHttp and AuthenticationSignon --- .../plugins/auth/AuthenticationHttp.class.php | 16 +- .../auth/AuthenticationSignon.class.php | 31 +- .../auth/PMA_AuthenticationHttp_test.php | 459 ++++++++++++++++++ .../auth/PMA_AuthenticationSignon_test.php | 333 +++++++++++++ 4 files changed, 829 insertions(+), 10 deletions(-) create mode 100644 test/classes/plugin/auth/PMA_AuthenticationHttp_test.php create mode 100644 test/classes/plugin/auth/PMA_AuthenticationSignon_test.php diff --git a/libraries/plugins/auth/AuthenticationHttp.class.php b/libraries/plugins/auth/AuthenticationHttp.class.php index 5d1eb8e261..d079cc8381 100644 --- a/libraries/plugins/auth/AuthenticationHttp.class.php +++ b/libraries/plugins/auth/AuthenticationHttp.class.php @@ -37,7 +37,11 @@ class AuthenticationHttp extends AuthenticationPlugin && ! empty($GLOBALS['cfg']['Server']['LogoutURL']) ) { PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']); - exit; + if (! defined('TESTSUITE')) { + exit; + } else { + return false; + } } if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) { @@ -81,7 +85,11 @@ class AuthenticationHttp extends AuthenticationPlugin include CUSTOM_FOOTER_FILE; } - exit; + if (! defined('TESTSUITE')) { + exit; + } else { + return false; + } } /** @@ -165,7 +173,9 @@ class AuthenticationHttp extends AuthenticationPlugin ) { $PHP_AUTH_USER = ''; // -> delete user's choices that were stored in session - session_destroy(); + if (! defined('TESTSUITE')) { + session_destroy(); + } } // Returns whether we get authentication settings or not diff --git a/libraries/plugins/auth/AuthenticationSignon.class.php b/libraries/plugins/auth/AuthenticationSignon.class.php index 1fbe25fc2f..a3d6cb9d0e 100644 --- a/libraries/plugins/auth/AuthenticationSignon.class.php +++ b/libraries/plugins/auth/AuthenticationSignon.class.php @@ -42,7 +42,12 @@ class AuthenticationSignon extends AuthenticationPlugin } else { PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']); } - exit(); + + if (! defined('TESTSUITE')) { + exit(); + } else { + return false; + } } /** @@ -112,12 +117,16 @@ class AuthenticationSignon extends AuthenticationPlugin /* End current session */ $old_session = session_name(); $old_id = session_id(); - session_write_close(); + if (! defined('TESTSUITE')) { + session_write_close(); + } /* Load single signon session */ session_name($session_name); session_id($_COOKIE[$session_name]); - session_start(); + if (! defined('TESTSUITE')) { + session_start(); + } /* Clear error message */ unset($_SESSION['PMA_single_signon_error_message']); @@ -157,14 +166,18 @@ class AuthenticationSignon extends AuthenticationPlugin } /* End single signon session */ - session_write_close(); + if (! defined('TESTSUITE')) { + session_write_close(); + } /* Restart phpMyAdmin session */ session_name($old_session); if (!empty($old_id)) { session_id($old_id); } - session_start(); + if (! defined('TESTSUITE')) { + session_start(); + } /* Set the single signon host */ $GLOBALS['cfg']['Server']['host'] = $single_signon_host; @@ -234,12 +247,16 @@ class AuthenticationSignon extends AuthenticationPlugin /* Does session exist? */ if (isset($_COOKIE[$session_name])) { /* End current session */ - session_write_close(); + if (! defined('TESTSUITE')) { + session_write_close(); + } /* Load single signon session */ session_name($session_name); session_id($_COOKIE[$session_name]); - session_start(); + if (! defined('TESTSUITE')) { + session_start(); + } /* Set error message */ if (! empty($GLOBALS['login_without_password_is_forbidden'])) { diff --git a/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php b/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php new file mode 100644 index 0000000000..068f946bb1 --- /dev/null +++ b/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php @@ -0,0 +1,459 @@ +enableBc(); + $GLOBALS['server'] = 0; + $this->object = new AuthenticationHttp(null); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for AuthenticationHttp::auth + * + * @return void + */ + public function testAuth() + { + if (! defined('PMA_TEST_HEADERS')) { + $this->markTestSkipped( + 'Cannot redefine constant/function - missing runkit extension' + ); + } + + $_REQUEST['old_usr'] = '1'; + $GLOBALS['cfg']['Server']['LogoutURL'] = 'http://phpmyadmin.net/logout'; + + $this->assertFalse( + $this->object->auth() + ); + + $this->assertContains( + 'Location: http://phpmyadmin.net/logout', + $GLOBALS['header'][0] + ); + + // case 2 + + $restoreInstance = PMA_Response::getInstance(); + + // mock footer + $mockFooter = $this->getMockBuilder('PMA_Footer') + ->disableOriginalConstructor() + ->setMethods(array('setMinimal')) + ->getMock(); + + $mockFooter->expects($this->once()) + ->method('setMinimal') + ->with(); + + // mock header + + $mockHeader = $this->getMockBuilder('PMA_Header') + ->disableOriginalConstructor() + ->setMethods( + array('setBodyId', 'setTitle', 'disableMenu', 'addHTML') + ) + ->getMock(); + + $mockHeader->expects($this->once()) + ->method('setBodyId') + ->with('loginform'); + + $mockHeader->expects($this->once()) + ->method('setTitle') + ->with('Access denied'); + + $mockHeader->expects($this->once()) + ->method('disableMenu') + ->with(); + + // set mocked headers and footers + $mockResponse = $this->getMockBuilder('PMA_Response') + ->disableOriginalConstructor() + ->setMethods(array('getHeader', 'getFooter', 'addHTML')) + ->getMock(); + + $mockResponse->expects($this->once()) + ->method('getFooter') + ->with() + ->will($this->returnValue($mockFooter)); + + $mockResponse->expects($this->once()) + ->method('getHeader') + ->with() + ->will($this->returnValue($mockHeader)); + + $mockResponse->expects($this->exactly(6)) + ->method('addHTML') + ->with(); + + $attrInstance = new ReflectionProperty('PMA_Response', '_instance'); + $attrInstance->setAccessible(true); + $attrInstance->setValue(null, $mockResponse); + + $GLOBALS['header'] = array(); + $_REQUEST['old_usr'] = ''; + $GLOBALS['cfg']['Server']['verbose'] = 'verboseMessagê'; + + $this->assertFalse( + $this->object->auth() + ); + + $this->assertEquals( + array( + 'WWW-Authenticate: Basic realm="phpMyAdmin verboseMessag"', + 'HTTP/1.0 401 Unauthorized', + 'status: 401 Unauthorized' + ), + $GLOBALS['header'] + ); + + $attrInstance->setValue(null, $restoreInstance); + + // case 3 + + $GLOBALS['header'] = array(); + $GLOBALS['cfg']['Server']['verbose'] = ''; + $GLOBALS['cfg']['Server']['host'] = 'hòst'; + $this->assertFalse( + $this->object->auth() + ); + + $this->assertEquals( + array( + 'WWW-Authenticate: Basic realm="phpMyAdmin hst"', + 'HTTP/1.0 401 Unauthorized', + 'status: 401 Unauthorized' + ), + $GLOBALS['header'] + ); + + // case 4 + + $GLOBALS['header'] = array(); + $GLOBALS['cfg']['Server']['host'] = ''; + $GLOBALS['cfg']['Server']['auth_http_realm'] = 'rêäealmmessage'; + $this->assertFalse( + $this->object->auth() + ); + + $this->assertEquals( + array( + 'WWW-Authenticate: Basic realm="realmmessage"', + 'HTTP/1.0 401 Unauthorized', + 'status: 401 Unauthorized' + ), + $GLOBALS['header'] + ); + } + + /** + * Test for AuthenticationHttp::authCheck + * + * @param string $user test username + * @param string $pass test password + * @param string $userIndex index to test username against + * @param string $passIndex index to test username against + * @param string $expectedReturn expected return value from test + * @param string $expectedUser expected username to be set + * @param string $expectedPass expected password to be set + * @param string $old_usr value for $_REQUEST['old_usr'] + * + * @return void + * @dataProvider authCheckProvider + */ + public function testAuthCheck($user, $pass, $userIndex, $passIndex, + $expectedReturn, $expectedUser, $expectedPass, $old_usr = '' + ) { + $GLOBALS['PHP_AUTH_USER'] = ''; + $GLOBALS['PHP_AUTH_PW'] = ''; + + $_SERVER[$userIndex] = $user; + $_SERVER[$passIndex] = $pass; + + $_REQUEST['old_usr'] = $old_usr; + + $this->assertEquals( + $expectedReturn, + $this->object->authCheck() + ); + + $this->assertEquals( + $expectedUser, + $GLOBALS['PHP_AUTH_USER'] + ); + + $this->assertEquals( + $expectedPass, + $GLOBALS['PHP_AUTH_PW'] + ); + + $_SERVER[$userIndex] = null; + $_SERVER[$passIndex] = null; + } + + /** + * Data provider for testAuthCheck + * + * @return array Test data + */ + public function authCheckProvider() + { + return array( + array( + 'Basic ' . base64_encode('foo:bar'), + 'pswd', + 'PHP_AUTH_USER', + 'PHP_AUTH_PW', + false, + '', + 'bar', + 'foo' + ), + array( + 'Basic ' . base64_encode('foobar'), + 'pswd', + 'REMOTE_USER', + 'REMOTE_PASSWORD', + true, + 'Basic Zm9vYmFy', + 'pswd' + ), + array( + 'Basic ' . base64_encode('foobar:'), + 'pswd', + 'AUTH_USER', + 'AUTH_PASSWORD', + true, + 'foobar', + false + ), + array( + 'Basic ' . base64_encode(':foobar'), + 'pswd', + 'HTTP_AUTHORIZATION', + 'AUTH_PASSWORD', + true, + 'Basic OmZvb2Jhcg==', + 'pswd' + ), + array( + 'BasicTest', + 'pswd', + 'Authorization', + 'AUTH_PASSWORD', + true, + 'BasicTest', + 'pswd' + ), + ); + } + + /** + * Test for AuthenticationHttp::authSetUser + * + * @return void + */ + public function testAuthSetUser() + { + // case 1 + + $GLOBALS['PHP_AUTH_USER'] = 'testUser'; + $GLOBALS['PHP_AUTH_PW'] = 'testPass'; + $GLOBALS['server'] = 2; + $GLOBALS['cfg']['Server']['user'] = 'testUser'; + + $this->assertTrue( + $this->object->authSetUser() + ); + + $this->assertEquals( + 'testUser', + $GLOBALS['cfg']['Server']['user'] + ); + + $this->assertEquals( + 'testPass', + $GLOBALS['cfg']['Server']['password'] + ); + + $this->assertFalse( + isset($GLOBALS['PHP_AUTH_PW']) + ); + + $this->assertFalse( + isset($_SERVER['PHP_AUTH_PW']) + ); + + $this->assertEquals( + 2, + $GLOBALS['server'] + ); + + // case 2 + $GLOBALS['PHP_AUTH_USER'] = 'testUser'; + $GLOBALS['PHP_AUTH_PW'] = 'testPass'; + $GLOBALS['cfg']['Servers'][1] = array( + 'host' => 'a', + 'user' => 'testUser', + 'foo' => 'bar' + ); + + $GLOBALS['cfg']['Server']= array( + 'host' => 'a', + 'user' => 'user2' + ); + + $this->assertTrue( + $this->object->authSetUser() + ); + + $this->assertEquals( + array( + 'user' => 'testUser', + 'password' => 'testPass', + 'host' => 'a', + 'foo' => 'bar' + ), + $GLOBALS['cfg']['Server'] + ); + + $this->assertEquals( + 1, + $GLOBALS['server'] + ); + + // case 3 + $GLOBALS['server'] = 3; + $GLOBALS['PHP_AUTH_USER'] = 'testUser'; + $GLOBALS['PHP_AUTH_PW'] = 'testPass'; + $GLOBALS['cfg']['Servers'][1] = array( + 'host' => 'a', + 'user' => 'testUsers', + 'foo' => 'bar' + ); + + $GLOBALS['cfg']['Server']= array( + 'host' => 'a', + 'user' => 'user2' + ); + + $this->assertTrue( + $this->object->authSetUser() + ); + + $this->assertEquals( + array( + 'user' => 'testUser', + 'password' => 'testPass', + 'host' => 'a' + ), + $GLOBALS['cfg']['Server'] + ); + + $this->assertEquals( + 3, + $GLOBALS['server'] + ); + } + + /** + * Test for AuthenticationHttp::authSetFails + * + * @return void + */ + public function testAuthFails() + { + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('getError') + ->will($this->returnValue('error 123')); + + $dbi->expects($this->at(1)) + ->method('getError') + ->will($this->returnValue('error 321')); + + $dbi->expects($this->at(2)) + ->method('getError') + ->will($this->returnValue(null)); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['errno'] = 31; + + ob_start(); + $this->object->authFails(); + $result = ob_get_clean(); + + $this->assertTag( + PMA_getTagArray( + '

error 123

' + ), + $result + ); + + $this->object = $this->getMockBuilder('AuthenticationHttp') + ->disableOriginalConstructor() + ->setMethods(array('auth')) + ->getMock(); + + $this->object->expects($this->exactly(2)) + ->method('auth'); + // case 2 + $GLOBALS['errno'] = 1045; + + $this->assertTrue( + $this->object->authFails() + ); + + // case 3 + $GLOBALS['errno'] = 1043; + $this->assertTrue( + $this->object->authFails() + ); + } +} +?> diff --git a/test/classes/plugin/auth/PMA_AuthenticationSignon_test.php b/test/classes/plugin/auth/PMA_AuthenticationSignon_test.php new file mode 100644 index 0000000000..78e28f4acb --- /dev/null +++ b/test/classes/plugin/auth/PMA_AuthenticationSignon_test.php @@ -0,0 +1,333 @@ +enableBc(); + $GLOBALS['server'] = 0; + $this->object = new AuthenticationSignon(null); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for AuthenticationSignon::auth + * + * @return void + */ + public function testAuth() + { + if (! defined('PMA_TEST_HEADERS')) { + $this->markTestSkipped( + 'Cannot redefine constant/function - missing runkit extension' + ); + } + + // case 1 + + $GLOBALS['cfg']['Server']['SignonURL'] = ''; + + ob_start(); + $this->object->auth(); + $result = ob_get_clean(); + + $this->assertContains( + 'You must set SignonURL!', + $result + ); + + // case 2 + + $GLOBALS['cfg']['Server']['SignonURL'] = 'http://phpmyadmin.net/SignonURL'; + $_REQUEST['old_usr'] = 'oldUser'; + $GLOBALS['cfg']['Server']['LogoutURL'] = 'http://phpmyadmin.net/logoutURL'; + + $this->object->auth(); + + $this->assertContains( + 'Location: http://phpmyadmin.net/logoutURL?PHPSESSID=', + $GLOBALS['header'][0] + ); + + // case 3 + + $GLOBALS['header'] = array(); + $GLOBALS['cfg']['Server']['SignonURL'] = 'http://phpmyadmin.net/SignonURL'; + $_REQUEST['old_usr'] = ''; + $GLOBALS['cfg']['Server']['LogoutURL'] = ''; + + $this->object->auth(); + + $this->assertContains( + 'Location: http://phpmyadmin.net/SignonURL?PHPSESSID=', + $GLOBALS['header'][0] + ); + } + + /** + * Test for AuthenticationSignon::authCheck + * + * @return void + */ + public function testAuthCheck() + { + // case 1 + + $GLOBALS['cfg']['Server']['SignonURL'] = 'http://phpmyadmin.net/SignonURL'; + $_SESSION['LAST_SIGNON_URL'] = 'http://phpmyadmin.net/SignonDiffURL'; + + $this->assertFalse( + $this->object->authCheck() + ); + + // case 2 + + $_SESSION['LAST_SIGNON_URL'] = 'http://phpmyadmin.net/SignonURL'; + $GLOBALS['cfg']['Server']['SignonScript'] = './examples/signon-script.php'; + $GLOBALS['cfg']['Server']['SignonSession'] = 'session123'; + $GLOBALS['cfg']['Server']['host'] = 'localhost'; + $GLOBALS['cfg']['Server']['port'] = '80'; + $GLOBALS['cfg']['Server']['user'] = 'user'; + + $this->assertTrue( + $this->object->authCheck() + ); + + $this->assertEquals( + 'root', + $GLOBALS['PHP_AUTH_USER'] + ); + + $this->assertEquals( + '', + $GLOBALS['PHP_AUTH_PW'] + ); + + $this->assertEquals( + 'http://phpmyadmin.net/SignonURL', + $_SESSION['LAST_SIGNON_URL'] + ); + + // case 3 + + $GLOBALS['cfg']['Server']['SignonScript'] = ''; + $_COOKIE['session123'] = true; + $_REQUEST['old_usr'] = 'oldUser'; + $_SESSION['PMA_single_signon_user'] = 'user123'; + $_SESSION['PMA_single_signon_password'] = 'pass123'; + $_SESSION['PMA_single_signon_host'] = 'local'; + $_SESSION['PMA_single_signon_port'] = '12'; + $_SESSION['PMA_single_signon_cfgupdate'] = array('foo' => 'bar'); + $_SESSION['PMA_single_signon_token'] = 'pmaToken'; + $sessionName = session_name(); + $sessionID = session_id(); + + $this->assertFalse( + $this->object->authCheck() + ); + + $this->assertEquals( + array( + 'SignonURL' => 'http://phpmyadmin.net/SignonURL', + 'SignonScript' => '', + 'SignonSession' => 'session123', + 'host' => 'local', + 'port' => '12', + 'user' => 'user', + 'foo' => 'bar' + ), + $GLOBALS['cfg']['Server'] + ); + + $this->assertEquals( + 'pmaToken', + $_SESSION[' PMA_token '] + ); + + $this->assertEquals( + $sessionName, + session_name() + ); + + $this->assertEquals( + $sessionID, + session_id() + ); + + $this->assertFalse( + isset($_SESSION['LAST_SIGNON_URL']) + ); + + // case 4 + $_REQUEST['old_usr'] = ''; + + $this->assertTrue( + $this->object->authCheck() + ); + + $this->assertEquals( + 'user123', + $GLOBALS['PHP_AUTH_USER'] + ); + + $this->assertEquals( + 'pass123', + $GLOBALS['PHP_AUTH_PW'] + ); + } + + /** + * Test for AuthenticationSignon::authSetUser + * + * @return void + */ + public function testAuthSetUser() + { + $GLOBALS['PHP_AUTH_USER'] = 'testUser123'; + $GLOBALS['PHP_AUTH_PW'] = 'testPass123'; + + $this->assertTrue( + $this->object->authSetUser() + ); + + $this->assertEquals( + 'testUser123', + $GLOBALS['cfg']['Server']['user'] + ); + + $this->assertEquals( + 'testPass123', + $GLOBALS['cfg']['Server']['password'] + ); + } + + /** + * Test for AuthenticationSignon::authFails + * + * @return void + */ + public function testAuthFails() + { + $GLOBALS['cfg']['Server']['SignonSession'] = 'newSession'; + $_COOKIE['newSession'] = '42'; + + $this->object = $this->getMockBuilder('AuthenticationSignon') + ->disableOriginalConstructor() + ->setMethods(array('auth')) + ->getMock(); + + $this->object->expects($this->exactly(5)) + ->method('auth'); + + // case 1 + + $GLOBALS['login_without_password_is_forbidden'] = true; + + $this->object->authFails(); + + $this->assertEquals( + 'Login without a password is forbidden by configuration ' + . '(see AllowNoPassword)', + $_SESSION['PMA_single_signon_error_message'] + ); + + // case 2 + + $GLOBALS['login_without_password_is_forbidden'] = null; + $GLOBALS['allowDeny_forbidden'] = true; + + $this->object->authFails(); + + $this->assertEquals( + 'Access denied', + $_SESSION['PMA_single_signon_error_message'] + ); + + // case 3 + + $GLOBALS['allowDeny_forbidden'] = null; + $GLOBALS['no_activity'] = true; + $GLOBALS['cfg']['LoginCookieValidity'] = '1440'; + + $this->object->authFails(); + + $this->assertEquals( + 'No activity within 1440 seconds; please log in again.', + $_SESSION['PMA_single_signon_error_message'] + ); + + // case 4 + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('getError') + ->will($this->returnValue('error<123>')); + + $dbi->expects($this->at(1)) + ->method('getError') + ->will($this->returnValue('error<123>')); + + $dbi->expects($this->at(2)) + ->method('getError') + ->will($this->returnValue(null)); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['no_activity'] = null; + + $this->object->authFails(); + + $this->assertEquals( + 'error<123>', + $_SESSION['PMA_single_signon_error_message'] + ); + + // case 5 + $this->object->authFails(); + + $this->assertEquals( + 'Cannot log in to the MySQL server', + $_SESSION['PMA_single_signon_error_message'] + ); + } +} +?> From b86f703a6ab09c0ccabb8a017a62082ce1a53324 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Thu, 18 Jul 2013 15:31:43 +0545 Subject: [PATCH 02/11] UTs for libraries/plugins/Plugin* --- .../classes/plugin/PMA_PluginManager_test.php | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 test/classes/plugin/PMA_PluginManager_test.php diff --git a/test/classes/plugin/PMA_PluginManager_test.php b/test/classes/plugin/PMA_PluginManager_test.php new file mode 100644 index 0000000000..e39c7f1789 --- /dev/null +++ b/test/classes/plugin/PMA_PluginManager_test.php @@ -0,0 +1,169 @@ +enableBc(); + $GLOBALS['server'] = 0; + + $this->object = new PluginManager(null); + + $this->attrStorage = new \ReflectionProperty('PluginManager', '_storage'); + $this->attrStorage->setAccessible(true); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for PluginManager::__construct + * + * @return void + */ + public function testConstructor() + { + $this->assertInstanceOf( + 'SplObjectStorage', + $this->attrStorage->getValue($this->object) + ); + } + + /** + * Test for PluginManager::attach + * + * @return void + */ + public function testAttach() + { + $observer = new PMA_TestObserver(); + + $mock = $this->getMockBuilder('SplObjectStorage') + ->disableOriginalConstructor() + ->setMethods(array('attach')) + ->getMock(); + + $mock->expects($this->once()) + ->method('attach') + ->with($observer); + + $this->attrStorage->setValue($this->object, $mock); + + $this->object->attach($observer); + + } + + /** + * Test for PluginManager::detach + * + * @return void + */ + public function testDetach() + { + $observer = new PMA_TestObserver(); + + $mock = $this->getMockBuilder('SplObjectStorage') + ->disableOriginalConstructor() + ->setMethods(array('detach')) + ->getMock(); + + $mock->expects($this->once()) + ->method('detach') + ->with($observer); + + $this->attrStorage->setValue($this->object, $mock); + + $this->object->detach($observer); + } + + /** + * Test for + * - PluginManager::getStorage + * - PluginManager::setStorage + * + * @return void + */ + public function testSetGetStorage() + { + $s = new SplObjectStorage(); + $o1 = new StdClass; + $s[$o1] = 'testData'; + + $this->object->setStorage($s); + + $this->assertEquals( + $s, + $this->object->getStorage() + ); + } + + /** + * Test for + * - PluginManager::getStatus + * - PluginManager::setStatus + * + * @return void + */ + public function testSetGetStatus() + { + $this->object->setStatus('active'); + + $this->assertEquals( + 'active', + $this->object->getStatus() + ); + } +} +?> From df114e88dcd385bd72dd6187923c7f9632cd8eed Mon Sep 17 00:00:00 2001 From: ayushchd Date: Thu, 18 Jul 2013 15:33:44 +0545 Subject: [PATCH 03/11] UTs for libraries/properties/* --- .../PMA_OptionsPropertyMainGroup_test.php | 53 +++++++ .../PMA_OptionsPropertyRootGroup_test.php | 53 +++++++ .../PMA_OptionsPropertySubgroup_test.php | 69 ++++++++++ .../options/items/PMA_PropertyItems_test.php | 130 ++++++++++++++++++ .../PMA_ExportPluginProperties_test.php | 73 ++++++++++ .../PMA_ImportPluginProperties_test.php | 88 ++++++++++++ 6 files changed, 466 insertions(+) create mode 100644 test/classes/properties/options/groups/PMA_OptionsPropertyMainGroup_test.php create mode 100644 test/classes/properties/options/groups/PMA_OptionsPropertyRootGroup_test.php create mode 100644 test/classes/properties/options/groups/PMA_OptionsPropertySubgroup_test.php create mode 100644 test/classes/properties/options/items/PMA_PropertyItems_test.php create mode 100644 test/classes/properties/plugins/PMA_ExportPluginProperties_test.php create mode 100644 test/classes/properties/plugins/PMA_ImportPluginProperties_test.php diff --git a/test/classes/properties/options/groups/PMA_OptionsPropertyMainGroup_test.php b/test/classes/properties/options/groups/PMA_OptionsPropertyMainGroup_test.php new file mode 100644 index 0000000000..66569114fc --- /dev/null +++ b/test/classes/properties/options/groups/PMA_OptionsPropertyMainGroup_test.php @@ -0,0 +1,53 @@ +object = new OptionsPropertyMainGroup(); + } + + /** + * tearDown for test cases + * + * @return void + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * Test for OptionsPropertyMainGroup::getItemType + * + * @return void + */ + public function testGetItemType() + { + $this->assertEquals( + 'main', + $this->object->getItemType() + ); + } + +} +?> diff --git a/test/classes/properties/options/groups/PMA_OptionsPropertyRootGroup_test.php b/test/classes/properties/options/groups/PMA_OptionsPropertyRootGroup_test.php new file mode 100644 index 0000000000..fa76c6f3d5 --- /dev/null +++ b/test/classes/properties/options/groups/PMA_OptionsPropertyRootGroup_test.php @@ -0,0 +1,53 @@ +object = new OptionsPropertyRootGroup(); + } + + /** + * tearDown for test cases + * + * @return void + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * Test for OptionsPropertyRootGroup::getItemType + * + * @return void + */ + public function testGetItemType() + { + $this->assertEquals( + 'root', + $this->object->getItemType() + ); + } + +} +?> diff --git a/test/classes/properties/options/groups/PMA_OptionsPropertySubgroup_test.php b/test/classes/properties/options/groups/PMA_OptionsPropertySubgroup_test.php new file mode 100644 index 0000000000..7c0b74677b --- /dev/null +++ b/test/classes/properties/options/groups/PMA_OptionsPropertySubgroup_test.php @@ -0,0 +1,69 @@ +object = new OptionsPropertySubgroup(); + } + + /** + * tearDown for test cases + * + * @return void + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * Test for OptionsPropertySubgroup::getItemType + * + * @return void + */ + public function testGetItemType() + { + $this->assertEquals( + 'subgroup', + $this->object->getItemType() + ); + } + + /** + * Test for + * - OptionsPropertySubgroup::getSubgroupHeader + * - OptionsPropertySubgroup::setSubgroupHeader + * + * @return void + */ + public function testGetSetSubgroupHeader() + { + $this->object->setSubgroupHeader('subGroupHeader123'); + + $this->assertEquals( + 'subGroupHeader123', + $this->object->getSubgroupHeader() + ); + } +} +?> diff --git a/test/classes/properties/options/items/PMA_PropertyItems_test.php b/test/classes/properties/options/items/PMA_PropertyItems_test.php new file mode 100644 index 0000000000..bf47bf62a3 --- /dev/null +++ b/test/classes/properties/options/items/PMA_PropertyItems_test.php @@ -0,0 +1,130 @@ +assertEquals( + "bool", + $object->getItemType() + ); + } + + /** + * Test for DocPropertyItem::getItemType + * + * @return void + */ + public function testGetItemTypeDoc() + { + $object = new DocPropertyItem(); + + $this->assertEquals( + "doc", + $object->getItemType() + ); + } + + /** + * Test for HiddenPropertyItem::getItemType + * + * @return void + */ + public function testGetItemTypeHidden() + { + $object = new HiddenPropertyItem(); + + $this->assertEquals( + "hidden", + $object->getItemType() + ); + } + + /** + * Test for MessageOnlyPropertyItem::getItemType + * + * @return void + */ + public function testGetItemTypeMessageOnly() + { + $object = new MessageOnlyPropertyItem(); + + $this->assertEquals( + "messageOnly", + $object->getItemType() + ); + } + + /** + * Test for RadioPropertyItem::getItemType + * + * @return void + */ + public function testGetItemTypeRadio() + { + $object = new RadioPropertyItem(); + + $this->assertEquals( + "radio", + $object->getItemType() + ); + } + + /** + * Test for SelectPropertyItem::getItemType + * + * @return void + */ + public function testGetItemTypeSelect() + { + $object = new SelectPropertyItem(); + + $this->assertEquals( + "select", + $object->getItemType() + ); + } + + /** + * Test for TextPropertyItem::getItemType + * + * @return void + */ + public function testGetItemTypeText() + { + $object = new TextPropertyItem(); + + $this->assertEquals( + "text", + $object->getItemType() + ); + } + + +} +?> diff --git a/test/classes/properties/plugins/PMA_ExportPluginProperties_test.php b/test/classes/properties/plugins/PMA_ExportPluginProperties_test.php new file mode 100644 index 0000000000..892f9ccd31 --- /dev/null +++ b/test/classes/properties/plugins/PMA_ExportPluginProperties_test.php @@ -0,0 +1,73 @@ +object = new ExportPluginProperties(); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for ExportPluginProperties::getItemType + * + * @return void + */ + public function testGetItemType() + { + $this->assertEquals( + 'export', + $this->object->getItemType() + ); + } + + /** + * Test for + * - ExportPluginProperties::getForceFile + * - ExportPluginProperties::setForceFile + * + * @return void + */ + public function testSetGetForceFile() + { + $this->object->setForceFile(true); + + $this->assertTrue( + $this->object->getForceFile() + ); + } + +} +?> diff --git a/test/classes/properties/plugins/PMA_ImportPluginProperties_test.php b/test/classes/properties/plugins/PMA_ImportPluginProperties_test.php new file mode 100644 index 0000000000..2f957c85aa --- /dev/null +++ b/test/classes/properties/plugins/PMA_ImportPluginProperties_test.php @@ -0,0 +1,88 @@ +object = new ImportPluginProperties(); + } + + /** + * tearDown for test cases + * + * @return void + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * Test for ImportPluginProperties::getItemType + * + * @return void + */ + public function testGetItemType() + { + $this->assertEquals( + 'import', + $this->object->getItemType() + ); + } + + /** + * Test for + * - ImportPluginProperties::getOptionsText + * - ImportPluginProperties::setOptionsText + * + * @return void + */ + public function testSetGetOptionsText() + { + $this->object->setOptionsText('options123'); + + $this->assertEquals( + 'options123', + $this->object->getOptionsText() + ); + } + + /** + * Test for + * - ImportPluginProperties::setMimeType + * - ImportPluginProperties::getMimeType + * + * @return void + */ + public function testSetGetMimeType() + { + $this->object->setMimeType('mime123'); + + $this->assertEquals( + 'mime123', + $this->object->getMimeType() + ); + } + +} +?> From e8994364a8061d4311306fde8a30fa35199a6f48 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 19:35:06 +0530 Subject: [PATCH 04/11] added methods PMA_executeQueryAndSendResponse, PMA_sendResponse --- libraries/sql.lib.php | 146 ++++++++++++++++++++++++++++++++++++++++-- sql.php | 53 ++++----------- 2 files changed, 151 insertions(+), 48 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 6ec9efa841..943eb4fc8d 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1815,14 +1815,13 @@ function PMA_getBookmarkCreatedMessage() * @param int $num_rows number of rows * @param bool $showtable whether to show table or not * @param object $result result of the executed query - * @param int $querytime query execution time * @param array $analyzed_sql_results analyzed sql results * * @return type */ function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $db, $goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append, - $editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, + $editable, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results ) { $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; @@ -1845,7 +1844,7 @@ function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $d $unlim_num_rows, $fields_meta, $analyzed_sql_results['is_count'], $analyzed_sql_results['is_export'], $analyzed_sql_results['is_func'], $analyzed_sql_results['is_analyse'], $num_rows, - $fields_cnt, $querytime, $pmaThemeImage, $GLOBALS['text_dir'], + $fields_cnt, $GLOBALS['querytime'], $pmaThemeImage, $GLOBALS['text_dir'], $analyzed_sql_results['is_maint'], $analyzed_sql_results['is_explain'], $analyzed_sql_results['is_show'], $showtable, $printview, $url_query, $editable @@ -1981,7 +1980,6 @@ function PMA_getHtmlForPrintButton() * @param string $sql_limit_to_append sql limit to append * @param int $unlim_num_rows unlimited number of rows * @param int $num_rows number of rows - * @param int $querytime query time * @param string $full_sql_query full sql query * @param string $disp_query display query * @param string $disp_message display message @@ -1997,7 +1995,7 @@ function PMA_getHtmlForPrintButton() function PMA_sendResponseForResultsReturned($result, $justBrowsing, $analyzed_sql_results, $db, $table, $disp_mode, $message, $sql_data, $displayResultsObject, $goto, $pmaThemeImage, $sql_limit_to_append, - $unlim_num_rows, $num_rows, $querytime, $full_sql_query, $disp_query, + $unlim_num_rows, $num_rows, $full_sql_query, $disp_query, $disp_message, $profiling_results, $query_type, $selected, $sql_query, $complete_query, $cfg ) { @@ -2101,7 +2099,7 @@ function PMA_sendResponseForResultsReturned($result, $justBrowsing, $table_html = PMA_getHtmlForSqlQueryResultsTable( isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append, - $editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, + $editable, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results ); @@ -2133,4 +2131,140 @@ function PMA_sendResponseForResultsReturned($result, $justBrowsing, exit(); } + +/** + * Function to send response for both empty results and non empty results + * + * @param int $num_rows number of rows returned by the executed query + * @param int $unlim_num_rows unlimited number of rows + * @param bool $is_affected is affected + * @param string $db current database + * @param string $table current table + * @param string $message_to_show message to show + * @param array $analyzed_sql_results analyzed Sql Results + * @param object $displayResultsObject Instance of DisplayResult class + * @param array $extra_data extra data + * @param array $cfg configuration + * @param array $result executed query results + * @param bool $justBrowsing whether just browsing or not + * @param string $disp_mode disply mode + * @param object $message message + * @param array $sql_data sql data + * @param string $goto goto page url + * @param string $pmaThemeImage uri of the PMA theme image + * @param string $sql_limit_to_append sql limit to append + * @param string $full_sql_query full sql query + * @param string $disp_query display query + * @param string $disp_message display message + * @param array $profiling_results profiling results + * @param string $query_type query type + * @param bool $selected selected + * @param string $sql_query sql query + * @param string $complete_query complete query + * + * @return void + */ +function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, + $db, $table, $message_to_show, $analyzed_sql_results, $displayResultsObject, + $extra_data, $cfg, $result, $justBrowsing, $disp_mode,$message, $sql_data, + $goto, $pmaThemeImage, $sql_limit_to_append, $full_sql_query, + $disp_query, $disp_message, $profiling_results, $query_type, $selected, + $sql_query, $complete_query +) { + // No rows returned -> move back to the calling page + if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { + PMA_sendResponseForNoResultsReturned( + $analyzed_sql_results, $db, $table, + isset($message_to_show) ? $message_to_show : null, + $num_rows, $displayResultsObject, $extra_data, $cfg + ); + + } else { + // At least one row is returned -> displays a table with results + PMA_sendResponseForResultsReturned( + isset($result) ? $result : null, $justBrowsing, $analyzed_sql_results, + $db, $table, isset($disp_mode) ? $disp_mode : null, + isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, + $displayResultsObject, $goto, $pmaThemeImage, + $sql_limit_to_append, $unlim_num_rows, + $num_rows, $full_sql_query, + isset($disp_query) ? $disp_query : null, + isset($disp_message) ? $disp_message : null, $profiling_results, + isset($query_type) ? $query_type : null, + isset($selected) ? $selected : null, $sql_query, + isset($complete_query) ? $complete_query : null, $cfg + ); + } // end rows returned +} + +/** + * Function to execute the query and send the response + * + * @param array $analyzed_sql_results analysed sql results + * @param string $full_sql_query full sql query + * @param bool $is_gotofile whether goto file or not + * @param string $db current database + * @param string $table current table + * @param bool $find_real_end whether to find real end or not + * @param string $import_text import text + * @param array $cfg configuration + * @param bool $is_affected whether affected or not + * @param string $message_to_show message to show + * @param string $disp_modem display mode + * @param string $message message + * @param array $sql_data sql data + * @param string $goto goto page url + * @param string $pmaThemeImage uri of the PMA theme image + * @param string $sql_limit_to_append sql limit to append + * @param string $disp_query display query + * @param string $disp_message display message + * @param string $query_type query type + * @param string $sql_query sql query + * @param bool $selected whether selected or not + * @param string $complete_query complete query + * + * @return void + */ +function PMA_executeQueryAndSendResponse($analyzed_sql_results, $full_sql_query, + $is_gotofile, $db, $table, $find_real_end, $import_text, $extra_data, $cfg, + $is_affected, $message_to_show, $disp_mode, $message, $sql_data, $goto, + $pmaThemeImage, $sql_limit_to_append, $disp_query, $disp_message, + $query_type, $sql_query, $selected, $complete_query +){ + // Include PMA_Index class for use in PMA_DisplayResults class + include './libraries/Index.class.php'; + + include 'libraries/DisplayResults.class.php'; + + $displayResultsObject = new PMA_DisplayResults( + $GLOBALS['db'], $GLOBALS['table'], $GLOBALS['goto'], $GLOBALS['sql_query'] + ); + + $displayResultsObject->setConfigParamsForDisplayTable(); + + + // Execute the query + list($result, $num_rows, $unlim_num_rows, $profiling_results, + $justBrowsing, $extra_data + ) = PMA_executeTheQuery( + $analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, + isset($find_real_end) ? $find_real_end : null, + isset($import_text) ? $import_text : null, $cfg['Bookmark']['user'], + isset($extra_data) ? $extra_data : null + ); + + PMA_sendResponse( + $num_rows, $unlim_num_rows, $is_affected, $db, $table, + isset($message_to_show) ? $message_to_show : null, + $analyzed_sql_results, $displayResultsObject, $extra_data, $cfg, + isset($result) ? $result : null, $justBrowsing, + isset($disp_mode) ? $disp_mode : null, isset($message) ? $message : null, + isset($sql_data) ? $sql_data : null, + $goto, $pmaThemeImage, $sql_limit_to_append, $full_sql_query, + isset($disp_query) ? $disp_query : null, + isset($disp_message) ? $disp_message : null, $profiling_results, + isset($query_type) ? $query_type : null, isset($selected) ? $selected : null, + $sql_query, isset($complete_query) ? $complete_query : null + ); +} ?> diff --git a/sql.php b/sql.php index 19053ad1b5..5c2fbc0e66 100644 --- a/sql.php +++ b/sql.php @@ -140,17 +140,6 @@ if (PMA_hasNoRightsToDropDatabase( ); } // end if -// Include PMA_Index class for use in PMA_DisplayResults class -require_once './libraries/Index.class.php'; - -require_once 'libraries/DisplayResults.class.php'; - -$displayResultsObject = new PMA_DisplayResults( - $GLOBALS['db'], $GLOBALS['table'], $GLOBALS['goto'], $GLOBALS['sql_query'] -); - -$displayResultsObject->setConfigParamsForDisplayTable(); - /** * Need to find the real end of rows? */ @@ -199,39 +188,19 @@ if (PMA_isAppendLimitClause($analyzed_sql_results)) { $reload = PMA_hasCurrentDbChanged($db); -// Execute the query -list($result, $num_rows, $unlim_num_rows, $profiling_results, - $justBrowsing, $extra_data -) = PMA_executeTheQuery( +PMA_executeQueryAndSendResponse( $analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, isset($find_real_end) ? $find_real_end : null, - isset($import_text) ? $import_text : null, $cfg['Bookmark']['user'], - isset($extra_data) ? $extra_data : null + isset($import_text) ? $import_text : null, + isset($extra_data) ? $extra_data : null, $cfg, $is_affected, + isset($message_to_show) ? $message_to_show : null, + isset($disp_mode) ? $disp_mode : null, isset($message) ? $message : null, + isset($sql_data) ? $sql_data : null, $goto, $pmaThemeImage, + $sql_limit_to_append, isset($disp_query) ? $display_query : null, + isset($disp_message) ? $disp_message : null, + isset($query_type) ? $query_type : null, + $sql_query, isset($selected) ? $selected : null, + isset($complete_query) ? $complete_query : null ); - -// No rows returned -> move back to the calling page -if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { - PMA_sendResponseForNoResultsReturned( - $analyzed_sql_results, $db, $table, - isset($message_to_show) ? $message_to_show : null, - $num_rows, $displayResultsObject, $extra_data, $cfg - ); - -} else { - // At least one row is returned -> displays a table with results - PMA_sendResponseForResultsReturned( - isset($result) ? $result : null, $justBrowsing, $analyzed_sql_results, - $db, $table, isset($disp_mode) ? $disp_mode : null, - isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, - $displayResultsObject, $goto, $pmaThemeImage, - $sql_limit_to_append, $unlim_num_rows, - $num_rows, $querytime, $full_sql_query, - isset($disp_query) ? $disp_query : null, - isset($disp_message) ? $disp_message : null, $profiling_results, - isset($query_type) ? $query_type : null, - isset($selected) ? $selected : null, $sql_query, - isset($complete_query) ? $complete_query : null, $cfg - ); -} // end rows returned ?> From f043cf18e01f542d54d475e48336f115adef7b31 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 19:39:43 +0530 Subject: [PATCH 05/11] phpcs errors and warnings corrected --- libraries/sql.lib.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 943eb4fc8d..7619b4d666 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -527,6 +527,7 @@ EOT; * $chart_json for displaying the chart. * * @param array $profiling_results profiling results + * * @return mixed */ function PMA_analyzeAndGetTableHtmlForProfilingResults( @@ -2022,9 +2023,11 @@ function PMA_sendResponseForResultsReturned($result, $justBrowsing, // - for information_schema // - if the result set does not contain all the columns of a unique key // and we are not just browing all the columns of an updatable view + + $sele_exp_cls = $analyzed_sql_results['analyzed_sql'][0]['select_expr_clause']; $updatableView = $justBrowsing - && trim($analyzed_sql_results['analyzed_sql'][0]['select_expr_clause']) == '*' + && trim($sele_exp_cls) == '*' && PMA_Table::isUpdatableView($db, $table); $has_unique = PMA_resultSetContainsUniqueKey( @@ -2207,10 +2210,11 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, * @param string $table current table * @param bool $find_real_end whether to find real end or not * @param string $import_text import text + * @param array $extra_data extra data * @param array $cfg configuration * @param bool $is_affected whether affected or not * @param string $message_to_show message to show - * @param string $disp_modem display mode + * @param string $disp_mode display mode * @param string $message message * @param array $sql_data sql data * @param string $goto goto page url @@ -2230,7 +2234,7 @@ function PMA_executeQueryAndSendResponse($analyzed_sql_results, $full_sql_query, $is_affected, $message_to_show, $disp_mode, $message, $sql_data, $goto, $pmaThemeImage, $sql_limit_to_append, $disp_query, $disp_message, $query_type, $sql_query, $selected, $complete_query -){ +) { // Include PMA_Index class for use in PMA_DisplayResults class include './libraries/Index.class.php'; From b2a63c9654001f0c43aa7ddc417c798d3dd69b36 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 20:35:07 +0530 Subject: [PATCH 06/11] use $GLOBALS['cfg'] instead of parsing $cfg variable among methods --- libraries/sql.lib.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 7619b4d666..eec2992b3c 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1470,14 +1470,13 @@ function PMA_countQueryResults( * @param String $db current database * @param String $table current table * @param boolean $find_real_end whether to find the real end - * @param String $import_text sql command - * @param String $bkm_user bookmarking user + * @param String $import_text sql command * @param array $extra_data extra data * * @return mixed */ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofile, - $db, $table, $find_real_end, $import_text, $bkm_user, $extra_data + $db, $table, $find_real_end, $import_text, $extra_data ) { // Only if we ask to see the php code if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { @@ -1501,7 +1500,7 @@ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofil // store the query as a bookmark if (! empty($_POST['bkm_label']) && ! empty($import_text)) { PMA_storeTheQueryAsBookmark( - $db, $bkm_user, $import_text, $_POST['bkm_label'], + $db, $GLOBALS['cfg']['Bookmark']['user'], $import_text, $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null ); } // end store bookmarks @@ -1643,13 +1642,12 @@ function PMA_getMessageForNoRowsReturned($message_to_show, $analyzed_sql_results * @param string $message message to be send * @param array $analyzed_sql analyzed sql * @param object $displayResultsObject DisplayResult instance - * @param bool $showSql whether to show sql or not * @param array $extra_data extra data * * @return void */ function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql, - $displayResultsObject, $showSql, $extra_data + $displayResultsObject, $extra_data ) { /** * @todo find a better way to make getMessage() in Header.class.php @@ -1657,7 +1655,7 @@ function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql, */ $GLOBALS['message'] = $message; - if ($showSql) { + if ($GLOBALS['cfg']['ShowSQL']) { $extra_data['sql_query'] = PMA_Util::getMessage( $message, $GLOBALS['sql_query'], 'success' ); @@ -1703,12 +1701,11 @@ function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql, * @param int $num_rows number of rows * @param object $displayResultsObject DisplayResult instance * @param array $extra_data extra data - * @param array $cfg configuration * * @return void */ function PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table, - $message_to_show, $num_rows, $displayResultsObject, $extra_data, $cfg + $message_to_show, $num_rows, $displayResultsObject, $extra_data ) { if (PMA_isDeleteTransformationInfo($analyzed_sql_results)) { PMA_deleteTransformationInfo( @@ -1723,7 +1720,7 @@ function PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table if ($GLOBALS['is_ajax_request'] == true) { PMA_sendAjaxResponseForNoResultsReturned( $message, $analyzed_sql_results['analyzed_sql'], - $displayResultsObject, $cfg['ShowSQL'], + $displayResultsObject, isset($extra_data) ? $extra_data : null ); } @@ -2147,7 +2144,6 @@ function PMA_sendResponseForResultsReturned($result, $justBrowsing, * @param array $analyzed_sql_results analyzed Sql Results * @param object $displayResultsObject Instance of DisplayResult class * @param array $extra_data extra data - * @param array $cfg configuration * @param array $result executed query results * @param bool $justBrowsing whether just browsing or not * @param string $disp_mode disply mode @@ -2169,7 +2165,7 @@ function PMA_sendResponseForResultsReturned($result, $justBrowsing, */ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, $db, $table, $message_to_show, $analyzed_sql_results, $displayResultsObject, - $extra_data, $cfg, $result, $justBrowsing, $disp_mode,$message, $sql_data, + $extra_data, $result, $justBrowsing, $disp_mode,$message, $sql_data, $goto, $pmaThemeImage, $sql_limit_to_append, $full_sql_query, $disp_query, $disp_message, $profiling_results, $query_type, $selected, $sql_query, $complete_query @@ -2179,7 +2175,7 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, PMA_sendResponseForNoResultsReturned( $analyzed_sql_results, $db, $table, isset($message_to_show) ? $message_to_show : null, - $num_rows, $displayResultsObject, $extra_data, $cfg + $num_rows, $displayResultsObject, $extra_data ); } else { @@ -2211,7 +2207,6 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, * @param bool $find_real_end whether to find real end or not * @param string $import_text import text * @param array $extra_data extra data - * @param array $cfg configuration * @param bool $is_affected whether affected or not * @param string $message_to_show message to show * @param string $disp_mode display mode @@ -2230,7 +2225,7 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, * @return void */ function PMA_executeQueryAndSendResponse($analyzed_sql_results, $full_sql_query, - $is_gotofile, $db, $table, $find_real_end, $import_text, $extra_data, $cfg, + $is_gotofile, $db, $table, $find_real_end, $import_text, $extra_data, $is_affected, $message_to_show, $disp_mode, $message, $sql_data, $goto, $pmaThemeImage, $sql_limit_to_append, $disp_query, $disp_message, $query_type, $sql_query, $selected, $complete_query @@ -2253,14 +2248,14 @@ function PMA_executeQueryAndSendResponse($analyzed_sql_results, $full_sql_query, ) = PMA_executeTheQuery( $analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, isset($find_real_end) ? $find_real_end : null, - isset($import_text) ? $import_text : null, $cfg['Bookmark']['user'], + isset($import_text) ? $import_text : null, isset($extra_data) ? $extra_data : null ); PMA_sendResponse( $num_rows, $unlim_num_rows, $is_affected, $db, $table, isset($message_to_show) ? $message_to_show : null, - $analyzed_sql_results, $displayResultsObject, $extra_data, $cfg, + $analyzed_sql_results, $displayResultsObject, $extra_data, isset($result) ? $result : null, $justBrowsing, isset($disp_mode) ? $disp_mode : null, isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, From f31bb7a1965426255353295724f5190002785c95 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 20:39:43 +0530 Subject: [PATCH 07/11] renamed methods to better reflect their usage. --- libraries/sql.lib.php | 14 +++++++------- sql.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index eec2992b3c..118caccf56 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1704,7 +1704,7 @@ function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql, * * @return void */ -function PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table, +function PMA_sendQueryResponseForNoResultsReturned($analyzed_sql_results, $db, $table, $message_to_show, $num_rows, $displayResultsObject, $extra_data ) { if (PMA_isDeleteTransformationInfo($analyzed_sql_results)) { @@ -1990,7 +1990,7 @@ function PMA_getHtmlForPrintButton() * * @return void */ -function PMA_sendResponseForResultsReturned($result, $justBrowsing, +function PMA_sendQueryResponseForResultsReturned($result, $justBrowsing, $analyzed_sql_results, $db, $table, $disp_mode, $message, $sql_data, $displayResultsObject, $goto, $pmaThemeImage, $sql_limit_to_append, $unlim_num_rows, $num_rows, $full_sql_query, $disp_query, @@ -2163,7 +2163,7 @@ function PMA_sendResponseForResultsReturned($result, $justBrowsing, * * @return void */ -function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, +function PMA_sendQueryResponse($num_rows, $unlim_num_rows, $is_affected, $db, $table, $message_to_show, $analyzed_sql_results, $displayResultsObject, $extra_data, $result, $justBrowsing, $disp_mode,$message, $sql_data, $goto, $pmaThemeImage, $sql_limit_to_append, $full_sql_query, @@ -2172,7 +2172,7 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, ) { // No rows returned -> move back to the calling page if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { - PMA_sendResponseForNoResultsReturned( + PMA_sendQueryResponseForNoResultsReturned( $analyzed_sql_results, $db, $table, isset($message_to_show) ? $message_to_show : null, $num_rows, $displayResultsObject, $extra_data @@ -2180,7 +2180,7 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, } else { // At least one row is returned -> displays a table with results - PMA_sendResponseForResultsReturned( + PMA_sendQueryResponseForResultsReturned( isset($result) ? $result : null, $justBrowsing, $analyzed_sql_results, $db, $table, isset($disp_mode) ? $disp_mode : null, isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, @@ -2224,7 +2224,7 @@ function PMA_sendResponse($num_rows, $unlim_num_rows, $is_affected, * * @return void */ -function PMA_executeQueryAndSendResponse($analyzed_sql_results, $full_sql_query, +function PMA_executeQueryAndSendQueryResponse($analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, $find_real_end, $import_text, $extra_data, $is_affected, $message_to_show, $disp_mode, $message, $sql_data, $goto, $pmaThemeImage, $sql_limit_to_append, $disp_query, $disp_message, @@ -2252,7 +2252,7 @@ function PMA_executeQueryAndSendResponse($analyzed_sql_results, $full_sql_query, isset($extra_data) ? $extra_data : null ); - PMA_sendResponse( + PMA_sendQueryResponse( $num_rows, $unlim_num_rows, $is_affected, $db, $table, isset($message_to_show) ? $message_to_show : null, $analyzed_sql_results, $displayResultsObject, $extra_data, diff --git a/sql.php b/sql.php index 5c2fbc0e66..b631098976 100644 --- a/sql.php +++ b/sql.php @@ -188,11 +188,11 @@ if (PMA_isAppendLimitClause($analyzed_sql_results)) { $reload = PMA_hasCurrentDbChanged($db); -PMA_executeQueryAndSendResponse( +PMA_executeQueryAndSendQueryResponse( $analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, isset($find_real_end) ? $find_real_end : null, isset($import_text) ? $import_text : null, - isset($extra_data) ? $extra_data : null, $cfg, $is_affected, + isset($extra_data) ? $extra_data : null, $is_affected, isset($message_to_show) ? $message_to_show : null, isset($disp_mode) ? $disp_mode : null, isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, $goto, $pmaThemeImage, From 2b39b25f30acc51271a3398aa85e0e8bee7af063 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 20:44:46 +0530 Subject: [PATCH 08/11] changed comments to better reflect the origin of the parameter $selected --- libraries/sql.lib.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 118caccf56..bc0f819b50 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1915,7 +1915,10 @@ function PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode) * Function to get html to display problems in indexes * * @param string $query_type query type - * @param boolean $selected selected + * @param bool $selected whether check table, optimize table, analyze + * table or repair table has been selected with + * respect to the selected tables from the + * databse structure page. * * @return void */ @@ -1983,7 +1986,10 @@ function PMA_getHtmlForPrintButton() * @param string $disp_message display message * @param array $profiling_results profiling results * @param string $query_type query type - * @param bool $selected selected + * @param bool $selected whether check table, optimize table, analyze + * table or repair table has been selected with + * respect to the selected tables from the + * databse structure page. * @param string $sql_query sql query * @param string $complete_query complete sql query * @param array $cfg configuration @@ -2157,7 +2163,10 @@ function PMA_sendQueryResponseForResultsReturned($result, $justBrowsing, * @param string $disp_message display message * @param array $profiling_results profiling results * @param string $query_type query type - * @param bool $selected selected + * @param bool $selected whether check table, optimize table, analyze + * table or repair table has been selected with + * respect to the selected tables from the + * databse structure page. * @param string $sql_query sql query * @param string $complete_query complete query * @@ -2219,7 +2228,10 @@ function PMA_sendQueryResponse($num_rows, $unlim_num_rows, $is_affected, * @param string $disp_message display message * @param string $query_type query type * @param string $sql_query sql query - * @param bool $selected whether selected or not + * @param bool $selected whether check table, optimize table, analyze + * table or repair table has been selected with + * respect to the selected tables from the + * databse structure page. * @param string $complete_query complete query * * @return void From edc8042fec3784b10b54cbf8e27f17ad61be1db7 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 21:28:42 +0530 Subject: [PATCH 09/11] error corrected --- libraries/sql.lib.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index bc0f819b50..c07af58aea 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1992,7 +1992,6 @@ function PMA_getHtmlForPrintButton() * databse structure page. * @param string $sql_query sql query * @param string $complete_query complete sql query - * @param array $cfg configuration * * @return void */ @@ -2001,7 +2000,7 @@ function PMA_sendQueryResponseForResultsReturned($result, $justBrowsing, $displayResultsObject, $goto, $pmaThemeImage, $sql_limit_to_append, $unlim_num_rows, $num_rows, $full_sql_query, $disp_query, $disp_message, $profiling_results, $query_type, $selected, $sql_query, - $complete_query, $cfg + $complete_query ) { // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here @@ -2088,7 +2087,7 @@ function PMA_sendQueryResponseForResultsReturned($result, $justBrowsing, $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( isset($disp_query) ? $disp_query : null, - $cfg['ShowSQL'], isset($sql_data) ? $sql_data : null, + $GLOBALS['cfg']['ShowSQL'], isset($sql_data) ? $sql_data : null, isset($disp_message) ? $disp_message : null ); @@ -2115,9 +2114,11 @@ function PMA_sendQueryResponseForResultsReturned($result, $justBrowsing, ); $bookmark_support_html = PMA_getHtmlForBookmark( - $disp_mode, isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $sql_query, - $db, $table, isset($complete_query) ? $complete_query : $sql_query, - $cfg['Bookmark']['user'] + $disp_mode, + isset($GLOBALS['cfg']['Bookmark']) ? $GLOBALS['cfg']['Bookmark'] : '', + $sql_query, $db, $table, + isset($complete_query) ? $complete_query : $sql_query, + $GLOBALS['cfg']['Bookmark']['user'] ); $print_button_html = PMA_getHtmlForPrintButton(); @@ -2200,7 +2201,7 @@ function PMA_sendQueryResponse($num_rows, $unlim_num_rows, $is_affected, isset($disp_message) ? $disp_message : null, $profiling_results, isset($query_type) ? $query_type : null, isset($selected) ? $selected : null, $sql_query, - isset($complete_query) ? $complete_query : null, $cfg + isset($complete_query) ? $complete_query : null ); } // end rows returned } From be6864a5a721613e208cf8990bd69edc2a6a47b4 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 18 Jul 2013 22:29:52 +0530 Subject: [PATCH 10/11] phpcs errors and warnings corrected --- libraries/sql.lib.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index c07af58aea..6d16fb793a 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1500,7 +1500,8 @@ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofil // store the query as a bookmark if (! empty($_POST['bkm_label']) && ! empty($import_text)) { PMA_storeTheQueryAsBookmark( - $db, $GLOBALS['cfg']['Bookmark']['user'], $import_text, $_POST['bkm_label'], + $db, $GLOBALS['cfg']['Bookmark']['user'], + $import_text, $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null ); } // end store bookmarks @@ -1704,8 +1705,8 @@ function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql, * * @return void */ -function PMA_sendQueryResponseForNoResultsReturned($analyzed_sql_results, $db, $table, - $message_to_show, $num_rows, $displayResultsObject, $extra_data +function PMA_sendQueryResponseForNoResultsReturned($analyzed_sql_results, $db, + $table, $message_to_show, $num_rows, $displayResultsObject, $extra_data ) { if (PMA_isDeleteTransformationInfo($analyzed_sql_results)) { PMA_deleteTransformationInfo( @@ -1914,8 +1915,8 @@ function PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode) /** * Function to get html to display problems in indexes * - * @param string $query_type query type - * @param bool $selected whether check table, optimize table, analyze + * @param string $query_type query type + * @param bool $selected whether check table, optimize table, analyze * table or repair table has been selected with * respect to the selected tables from the * databse structure page. From b1b39e8b0f61ff7c109ff0731de93f5bb1f9a52e Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 18 Jul 2013 13:19:55 -0400 Subject: [PATCH 11/11] Fix typos --- libraries/operations.lib.php | 6 +++--- libraries/relation.lib.php | 2 +- libraries/sql.lib.php | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index 126c835306..9e25525437 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -395,7 +395,7 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy() * * @param array $tables_full array of all tables in given db or dbs * @param object $export_sql_plugin export plugin instance - * @param boolean $move whether databse name is empty or not + * @param boolean $move whether database name is empty or not * @param string $db database name * * @return string sql constraints query for full databases @@ -459,7 +459,7 @@ function PMA_getViewsAndCreateSqlViewStandIn( * * @param array $tables_full array of all tables in given db or dbs * @param string $sql_query sql query for all operations - * @param boolean $move whether databse name is empty or not + * @param boolean $move whether database name is empty or not * @param string $db database name * * @return array ($sql_query, $error) @@ -562,7 +562,7 @@ function PMA_runEventDefinitionsForDb($db) * Handle the views, return the boolean value whether table rename/copy or not * * @param array $views views as an array - * @param boolean $move whether databse name is empty or not + * @param boolean $move whether database name is empty or not * @param string $db database name * * @return boolean $_error whether table rename/copy or not diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index c3b83c3d40..c2ffdff99d 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -1282,7 +1282,7 @@ function PMA_getRelatives($all_tables, $master) * * usually called after a column in a table was renamed * - * @param string $db databse name + * @param string $db database name * @param string $table table name * @param string $field old field name * @param string $new_name new field name diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 11d94787d5..b4c96284d5 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -711,7 +711,7 @@ function PMA_getHtmlForOptionsList($values, $selected_values) * return null * * @param string $disp_mode display mode - * @param bool $cfgBookmark confguration setting for bookmarking + * @param bool $cfgBookmark configuration setting for bookmarking * @param string $sql_query sql query * @param string $db current database * @param string $table current table @@ -1919,7 +1919,7 @@ function PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode) * @param bool $selected whether check table, optimize table, analyze * table or repair table has been selected with * respect to the selected tables from the - * databse structure page. + * database structure page. * @param string $db current database * * @return void @@ -1991,7 +1991,7 @@ function PMA_getHtmlForPrintButton() * @param bool $selected whether check table, optimize table, analyze * table or repair table has been selected with * respect to the selected tables from the - * databse structure page. + * database structure page. * @param string $sql_query sql query * @param string $complete_query complete sql query * @@ -2169,7 +2169,7 @@ function PMA_sendQueryResponseForResultsReturned($result, $justBrowsing, * @param bool $selected whether check table, optimize table, analyze * table or repair table has been selected with * respect to the selected tables from the - * databse structure page. + * database structure page. * @param string $sql_query sql query * @param string $complete_query complete query * @@ -2234,7 +2234,7 @@ function PMA_sendQueryResponse($num_rows, $unlim_num_rows, $is_affected, * @param bool $selected whether check table, optimize table, analyze * table or repair table has been selected with * respect to the selected tables from the - * databse structure page. + * database structure page. * @param string $complete_query complete query * * @return void