diff --git a/libraries/DBQbe.class.php b/libraries/DBQbe.class.php index 6407b63f98..dd14979ec5 100644 --- a/libraries/DBQbe.class.php +++ b/libraries/DBQbe.class.php @@ -1366,7 +1366,7 @@ class PMA_DbQbe } // end while // Create LEFT JOINS out of Relations - if ($cfgRelation['relwork'] && count($all_tables) > 0) { + if (count($all_tables) > 0) { // Get tables and columns with valid where clauses $valid_where_clauses = $this->_getWhereClauseTablesAndColumns(); $where_clause_tables = $valid_where_clauses['where_clause_tables']; diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 190243b397..27a7f3c93b 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -1334,7 +1334,7 @@ function PMA_getRelatives($all_tables, $master) $known_tables = array(); $known_tables[$master] = $master; $run = 0; - while (count($remaining_tables) > 0) { + while ($GLOBALS['cfgRelation']['relwork'] && count($remaining_tables) > 0) { // Whether to go from master to foreign or vice versa if ($run % 2 == 0) { $from = 'master'; diff --git a/tbl_relation.php b/tbl_relation.php index 58214837df..ebb9b4fef8 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -152,7 +152,8 @@ $columns = $GLOBALS['dbi']->getColumns($db, $table); // common form $html_output .= PMA_getHtmlForCommonForm( - $db, $table, $columns, $cfgRelation, $tbl_storage_engine, $existrel, + $db, $table, $columns, $cfgRelation, $tbl_storage_engine, + isset($existrel) ? $existrel : null, isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : null, $options_array ); diff --git a/test/classes/PMA_DBQbe_test.php b/test/classes/PMA_DBQbe_test.php index d166f91837..a22025370a 100644 --- a/test/classes/PMA_DBQbe_test.php +++ b/test/classes/PMA_DBQbe_test.php @@ -16,6 +16,7 @@ require_once 'libraries/core.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/relation.lib.php'; +require_once 'libraries/sqlparser.lib.php'; /** * Tests for PMA_DBQbe class @@ -39,6 +40,30 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase protected function setUp() { $this->object = new PMA_DBQbe('pma_test'); + $GLOBALS['server'] = 0; + $GLOBALS['db'] = 'pma_test'; + //mock DBI + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $create_table = 'CREATE TABLE `table1` (' + . '`id` int(11) NOT NULL,' + . '`value` int(11) NOT NULL,' + . 'PRIMARY KEY (`id`,`value`),' + . 'KEY `value` (`value`)' + . ') ENGINE=InnoDB DEFAULT CHARSET=latin1'; + + $dbi->expects($this->any()) + ->method('fetchValue') + ->with('SHOW CREATE TABLE `pma_test`.`table1`', 0, 1) + ->will($this->returnValue($create_table)); + + $dbi->expects($this->any()) + ->method('getTableIndexes') + ->will($this->returnValue(array())); + + $GLOBALS['dbi'] = $dbi; } /** @@ -400,7 +425,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase $this->_callProtectedFunction( '_getIndexes', array( - array('table1','table2'), + array('`table1`','table2'), array('column1', 'column2', 'column3'), array('column2') ) @@ -422,7 +447,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase $this->_callProtectedFunction( '_getLeftJoinColumnCandidates', array( - array('table1','table2'), + array('`table1`','table2'), array('column1', 'column2', 'column3'), array('column2') ) @@ -490,7 +515,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase 'table1.deleted' ); $this->assertEquals( - 'table1', + '`table1`', $this->_callProtectedFunction( '_getFromClause', array(array('relwork' => false)) @@ -512,7 +537,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase 'table1.deleted' ); $this->assertEquals( - 'FROM table1 + 'FROM `table1` ', $this->_callProtectedFunction( '_getSQLQuery',