object = new DbQbe('pma_test'); $GLOBALS['server'] = 0; $GLOBALS['db'] = 'pma_test'; //mock DBI $dbi = $this->getMockBuilder('PMA\libraries\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; } /** * 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 setting visibility 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\libraries\DbQbe'); $method = $class->getMethod($name); $method->setAccessible(true); return $method->invokeArgs($this->object, $params); } /** * Test for _getSortSelectCell * * @return void */ public function testGetSortSelectCell() { $this->assertEquals( '', $this->_callProtectedFunction( '_getSortSelectCell', array(1) ) ); } /** * Test for _getSortRow * * @return void */ public function testGetSortRow() { $this->assertEquals( 'Sort:' . '' . '' . '', $this->_callProtectedFunction( '_getSortRow', array() ) ); } /** * Test for _getShowRow * * @return void */ public function testGetShowRow() { $this->assertEquals( 'Show:' . '' . '', $this->_callProtectedFunction( '_getShowRow', array() ) ); } /** * Test for _getCriteriaInputboxRow * * @return void */ public function testGetCriteriaInputboxRow() { $this->assertEquals( 'Criteria:' . '' . '' . '' . '' . '' . '', $this->_callProtectedFunction( '_getCriteriaInputboxRow', array() ) ); } /** * Test for _getFootersOptions * * @return void */ public function testGetFootersOptions() { $this->assertEquals( '
Add/Delete criteria rows:
', $this->_callProtectedFunction( '_getFootersOptions', array('row') ) ); } /** * Test for _getTableFooters * * @return void */ public function testGetTableFooters() { $this->assertEquals( '
Add/Delete criteria' . ' rows:
Add/Delete columns:
', $this->_callProtectedFunction( '_getTableFooters', array() ) ); } /** * Test for _getAndOrColCell * * @return void */ public function testGetAndOrColCell() { $this->assertEquals( 'Or:  And:' . '
Ins  Del', $this->_callProtectedFunction( '_getAndOrColCell', array(1) ) ); } /** * Test for _getModifyColumnsRow * * @return void */ public function testGetModifyColumnsRow() { $this->assertEquals( 'Modify:' . 'Or:  And:
Ins' . '  ' . 'DelOr:  And:' . '
Ins  Del
Ins' . '  ' . 'Del' . '', $this->_callProtectedFunction( '_getModifyColumnsRow', array() ) ); } /** * Test for _getInsDelAndOrCell * * @return void */ public function testGetInsDelAndOrCell() { $GLOBALS['cell_align_right'] = 'cellAlign'; $this->assertEquals( '
Ins:' . 'And:
Del:' . 'Or:
', $this->_callProtectedFunction( '_getInsDelAndOrCell', array(3, array('and' => '', 'or' => ' checked="checked"')) ) ); } /** * Test for _getInputboxRow * * @return void */ public function testGetInputboxRow() { $this->assertEquals( '' . '', $this->_callProtectedFunction( '_getInputboxRow', array(2) ) ); } /** * Test for _getInsDelAndOrCriteriaRows * * @return void */ public function testGetInsDelAndOrCriteriaRows() { $GLOBALS['cell_align_right'] = 'cellAlign'; $this->assertEquals( '' . '
Ins:And:' . '
Del:' . 'Or:' . '
', $this->_callProtectedFunction( '_getInsDelAndOrCriteriaRows', array(2,3) ) ); } /** * Test for _getSelectClause * * @return void */ public function testGetSelectClause() { $this->assertEquals( '', $this->_callProtectedFunction( '_getSelectClause', array() ) ); } /** * Test for _getWhereClause * * @return void */ public function testGetWhereClause() { $this->assertEquals( '', $this->_callProtectedFunction( '_getWhereClause', array() ) ); } /** * Test for _getOrderByClause * * @return void */ public function testGetOrderByClause() { $this->assertEquals( '', $this->_callProtectedFunction( '_getOrderByClause', array() ) ); } /** * Test for _getIndexes * * @return void */ public function testGetIndexes() { $this->assertEquals( array( 'unique' => array(), 'index' => array() ), $this->_callProtectedFunction( '_getIndexes', array( array('`table1`','table2'), array('column1', 'column2', 'column3'), array('column2') ) ) ); } /** * Test for _getLeftJoinColumnCandidates * * @return void */ public function testGetLeftJoinColumnCandidates() { $this->assertEquals( array( 0 => 'column2' ), $this->_callProtectedFunction( '_getLeftJoinColumnCandidates', array( array('`table1`','table2'), array('column1', 'column2', 'column3'), array('column2') ) ) ); } /** * Test for _getMasterTable * * @return void */ public function testGetMasterTable() { $this->assertEquals( 0, $this->_callProtectedFunction( '_getMasterTable', array( array('table1','table2'), array('column1', 'column2', 'column3'), array('column2'), array('qbe_test') ) ) ); } /** * Test for _getWhereClauseTablesAndColumns * * @return void */ public function testGetWhereClauseTablesAndColumns() { $_POST['criteriaColumn'] = array( 'table1.id', 'table1.value', 'table1.name', 'table1.deleted' ); $this->assertEquals( array( 'where_clause_tables' => array(), 'where_clause_columns' => array() ), $this->_callProtectedFunction( '_getWhereClauseTablesAndColumns', array() ) ); } /** * Test for _getFromClause * * @return void */ public function testGetFromClause() { $_POST['criteriaColumn'] = array( 'table1.id', 'table1.value', 'table1.name', 'table1.deleted' ); $this->assertEquals( '`table1`', $this->_callProtectedFunction( '_getFromClause', array(array('`table1`.`id`')) ) ); } /** * Test for _getSQLQuery * * @return void */ public function testGetSQLQuery() { $_POST['criteriaColumn'] = array( 'table1.id', 'table1.value', 'table1.name', 'table1.deleted' ); $this->assertEquals( 'FROM `table1` ', $this->_callProtectedFunction( '_getSQLQuery', array(array('`table1`.`id`')) ) ); } }