object = new PMA_DbSearch('pma_test'); $GLOBALS['server'] = 0; $GLOBALS['cfg']['ServerDefault'] = 1; $GLOBALS['cfg']['ShowHint'] = true; $GLOBALS['db'] = '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 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_DbSearch'); $method = $class->getMethod($name); $method->setAccessible(true); return $method->invokeArgs($this->object, $params); } /** * Test for _getSearchSqls * * @return void */ public function testGetSearchSqls() { //mock DBI $dbi = $this->getMockBuilder('PMA_DatabaseInterface') ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->any()) ->method('getColumns') ->with('pma', 'table1') ->will($this->returnValue(array())); $GLOBALS['dbi'] = $dbi; $this->assertEquals( 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' ), $this->_callProtectedFunction( '_getSearchSqls', array('table1') ) ); } /** * Test for getSearchResults * * @return void */ public function testGetSearchResults() { $this->assertEquals( '
Search results ' . 'for "" :
', $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 string $output Expected HTML output * * @return void * * @dataProvider providerForTestGetResultsRow */ public function testGetResultsRow( $each_table, $newsearchsqls, $odd_row, $output ) { $this->assertEquals( $output, $this->_callProtectedFunction( '_getResultsRow', array($each_table, $newsearchsqls, $odd_row, 2) ) ); } /** * Data provider for testGetResultRow * * @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 * * @return void */ public function testGetSelectionForm() { $_SESSION['PMA_Theme'] = new PMA_Theme(); $GLOBALS['pmaThemeImage'] = 'themes/dot.gif'; $this->assertEquals( '
' . '' . '' . '' . '' . '
Search in database' . '' . '
Words or values to search for (wildcard: "%"):' . '
Find:' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n" . '
Inside tables:
Select ' . 'All  / Unselect' . ' All
Inside column:' . '' . '
' . '
' . '
', $this->object->getSelectionForm() ); } /** * Test for getResultDivs * * @return void */ public function testGetResultDivs() { $this->assertEquals( '
' . '
' . '

' . '
' . '', $this->_callProtectedFunction( 'getResultDivs', array() ) ); } }