diff --git a/test/classes/PMA_DBQbe_test.php b/test/classes/PMA_DBQbe_test.php
new file mode 100644
index 0000000000..55ffb4a1b7
--- /dev/null
+++ b/test/classes/PMA_DBQbe_test.php
@@ -0,0 +1,400 @@
+object = $this->getMockForAbstractClass('PMA_DBQbe', array('pma'));
+ }
+
+ /**
+ * 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 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_DBQbe');
+ $method = $class->getMethod($name);
+ $method->setAccessible(true);
+ return $method->invokeArgs($this->object, $params);
+ }
+
+ /**
+ * Test for getCommonFunctions
+ */
+ public function testGetCommonFunctions(){
+ $this->assertTrue($this->object->getCommonFunctions() instanceof PMA_CommonFunctions);
+ }
+
+ /**
+ * Test for _getSortSelectCell
+ */
+ public function testGetSortSelectCell(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getSortSelectCell',
+ array(1)
+ ),
+ '
| '
+ );
+ }
+
+ /**
+ * Test for _getSortRow
+ */
+ public function testGetSortRow(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getSortRow',
+ array()
+ ),
+ '| Sort: | | | |
'
+ );
+ }
+
+ /**
+ * Test for _getShowRow
+ */
+ public function testGetShowRow(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getShowRow',
+ array()
+ ),
+ '| Show: | | | |
'
+ );
+ }
+
+ /**
+ * Test for _getCriteriaInputboxRow
+ */
+ public function testGetCriteriaInputboxRow(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getCriteriaInputboxRow',
+ array()
+ ),
+ '| Criteria: | | | |
'
+ );
+ }
+
+ /**
+ * Test for _getFootersOptions
+ */
+ public function testGetFootersOptions(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getFootersOptions',
+ array('row')
+ ),
+ 'Add/Delete criteria rows:
'
+ );
+ }
+
+ /**
+ * Test for _getTableFooters
+ */
+ public function testGetTableFooters(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getTableFooters',
+ array()
+ ),
+ ''
+ );
+ }
+
+ /**
+ * Test for _getAndOrColCell
+ */
+ public function testGetAndOrColCell(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getAndOrColCell',
+ array(1)
+ ),
+ 'Or: And: Ins Del | '
+ );
+ }
+
+ /**
+ * Test for _getModifyColumnsRow
+ */
+ public function testGetModifyColumnsRow(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getModifyColumnsRow',
+ array()
+ ),
+ '| Modify: | Or: And: Ins Del | Or: And: Ins Del | Or: And: Ins Del |
'
+ );
+ }
+
+ /**
+ * Test for _getInsDelAndOrCell
+ */
+ public function testGetInsDelAndOrCell(){
+ $GLOBALS['cell_align_right'] = 'cellAlign';
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getInsDelAndOrCell',
+ array(3, 'checked')
+ ),
+ ' | '
+ );
+ }
+
+ /**
+ * Test for _getInputboxRow
+ */
+ public function testGetInputboxRow(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getInputboxRow',
+ array(2,3)
+ ),
+ ' | | | '
+ );
+ }
+
+ /**
+ * Test for _getInsDelAndOrCriteriaRows
+ */
+ public function testGetInsDelAndOrCriteriaRows(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getInsDelAndOrCriteriaRows',
+ array(2,3)
+ ),
+ ' | | | |
'
+ );
+ }
+
+ /**
+ * Test for _getSelectClause
+ */
+ public function testGetSelectClause(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getSelectClause',
+ array()
+ ),
+ ''
+ );
+ }
+
+ /**
+ * Test for _getWhereClause
+ */
+ public function testGetWhereClause(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getWhereClause',
+ array()
+ ),
+ ''
+ );
+ }
+
+ /**
+ * Test for _getOrderByClause
+ */
+ public function testGetOrderByClause(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getOrderByClause',
+ array()
+ ),
+ ''
+ );
+ }
+
+ /**
+ * Test for _getIndexes
+ */
+ public function testGetIndexes(){
+ if (! function_exists('PMA_DBI_get_table_indexes')) {
+ function PMA_DBI_get_table_indexes()
+ {
+ return array(2,3);
+ }
+ }
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getIndexes',
+ array(
+ array('table1','table2'),
+ array('column1', 'column2', 'column3'),
+ array('column2')
+ )
+ ),
+ array(
+ 'unique' => array(),
+ 'index' => array()
+ )
+ );
+ }
+
+ /**
+ * Test for _getLeftJoinColumnCandidates
+ */
+ public function test_getLeftJoinColumnCandidates(){
+ if (! function_exists('PMA_DBI_select_db')) {
+ function PMA_DBI_select_db()
+ {
+ return 'pma';
+ }
+ }
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getLeftJoinColumnCandidates',
+ array(
+ array('table1','table2'),
+ array('column1', 'column2', 'column3'),
+ array('column2')
+ )
+ ),
+ array(
+ 0 => 'column2'
+ )
+ );
+ }
+
+ /**
+ * Test for _getMasterTable
+ */
+ public function test_getMasterTable(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getMasterTable',
+ array(
+ array('table1','table2'),
+ array('column1', 'column2', 'column3'),
+ array('column2'),
+ array('pma')
+ )
+ ),
+ 0
+ );
+ }
+
+ /**
+ * Test for _getWhereClauseTablesAndColumns
+ */
+ public function test_getWhereClauseTablesAndColumns(){
+ $_POST['criteriaColumn'] = array('table1.id', 'table1.value', 'table1.name', 'table1.deleted');
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getWhereClauseTablesAndColumns',
+ array()
+ ),
+ array(
+ 'where_clause_tables' => array(),
+ 'where_clause_columns' => array()
+ )
+ );
+ }
+
+ /**
+ * Test for _getFromClause
+ */
+ public function testGetFromClause(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getFromClause',
+ array('relation')
+ ),
+ '`table1`'
+ );
+ }
+
+ /**
+ * Test for _getSQLQuery
+ */
+ public function test_getSQLQuery(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getSQLQuery',
+ array('relation')
+ ),
+ 'FROM `table1`
+'
+ );
+ }
+}
diff --git a/test/classes/PMA_DbSearch_test.php b/test/classes/PMA_DbSearch_test.php
new file mode 100644
index 0000000000..cf88afc0fb
--- /dev/null
+++ b/test/classes/PMA_DbSearch_test.php
@@ -0,0 +1,203 @@
+object = $this->getMockForAbstractClass('PMA_DbSearch', array('pma'));
+ }
+
+ /**
+ * 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 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_DbSearch');
+ $method = $class->getMethod($name);
+ $method->setAccessible(true);
+ return $method->invokeArgs($this->object, $params);
+ }
+
+ /**
+ * Test for getCommonFunctions
+ */
+ public function testGetCommonFunctions(){
+ $this->assertTrue($this->object->getCommonFunctions() instanceof PMA_CommonFunctions);
+ }
+
+ /**
+ * Test for _getSearchSqls
+ */
+ public function testGetSearchSqls(){
+
+ $GLOBALS['db'] = 'pma';
+ if (! function_exists('PMA_DBI_get_columns')) {
+ function PMA_DBI_get_columns()
+ {
+ return array(
+ 'column1',
+ 'column2'
+ );
+ }
+ }
+
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getSearchSqls',
+ array('table1')
+ ),
+ array (
+ 'select_columns' => 'SELECT * FROM `pma`.`table1` WHERE FALSE',
+ 'select_count' => 'SELECT COUNT(*) AS `count` FROM `pma`.`table1` WHERE FALSE',
+ 'delete' => 'DELETE FROM `pma`.`table1` WHERE FALSE'
+ )
+ );
+ }
+
+ /**
+ * Test for getSearchResults
+ */
+ public function testGetSearchResults(){
+ $this->assertEquals(
+ $this->object->getSearchResults(),
+ '
'
+ );
+ }
+
+ /**
+ * Test for _getResultsRow
+ * @param string $each_table Tables on which search is to be performed
+ * @param array $newsearchsqls Contains SQL queries
+ * @param bool $odd_row For displaying contrasting table rows
+ * @param $output
+ *
+ * @dataProvider providerForTestGetResultsRow
+ */
+ public function testGetResultsRow($each_table, $newsearchsqls, $odd_row, $output){
+
+ if (! function_exists('PMA_DBI_fetch_value')) {
+ function PMA_DBI_fetch_value()
+ {
+ return 2;
+ }
+ }
+ $GLOBALS['cfg']['AjaxEnable'] = true;
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getResultsRow',
+ array($each_table, $newsearchsqls, $odd_row)
+ ),
+ $output
+ );
+ }
+
+ /**
+ * @return array provider for testGetResultsRow
+ */
+ public function providerForTestGetResultsRow(){
+ return array(
+ array(
+ 'table1',
+ array(
+ 'SELECT * FROM `pma`.`table1` WHERE FALSE',
+ 'SELECT COUNT(*) AS `count` FROM `pma`.`table1` WHERE FALSE',
+ 'select_count' => 2,
+ 'select_columns' => 'column1',
+ 'delete' => 'column2'
+ ),
+ true,
+ '| 2 matches in table1 | Browse | Delete |
'
+ )
+ );
+ }
+
+ /**
+ * Test for getSelectionForm
+ */
+ public function testGetSelectionForm(){
+ $_SESSION[' PMA_token '] = 'token';
+ $_SESSION['PMA_Theme'] = new PMA_Theme();
+ $GLOBALS['pmaThemeImage'] = 'themes/dot.gif';
+ $url_params = array('param1', 'param2');
+ $this->assertEquals(
+ $this->object->getSelectionForm($url_params),
+ '
'
+ );
+ }
+
+ /**
+ * Test for _getResultDivs
+ */
+ public function testGetResultDivs(){
+ $this->assertEquals(
+ $this->_callProtectedFunction(
+ '_getResultDivs',
+ array()
+ ),
+ '
'
+ );
+ }
+
+}