"id", "col_type" => 'integer', 'col_length' => 0, 'col_isNull' => 0, 'col_extra' => 'UNSIGNED,auto_increment', 'col_default' => 1, 'col_collation' => '' ), array('col_name' => "col1", 'col_type' => 'varchar', 'col_length' => 100, 'col_isNull' => 1, 'col_extra' => 'BINARY', 'col_default' => 1, 'col_collation' => '' ), array( 'col_name' => "col2", 'col_type' => 'DATETIME', 'col_length' => 0, 'col_isNull' => 1, 'col_extra' => 'on update CURRENT_TIMESTAMP', 'col_default' => 'CURRENT_TIMESTAMP', 'col_collation' => '' ) ); private $_modifiedColumnData = array( array( 'col_name' => "id", "col_type" => 'integer', 'col_length' => 0, 'col_isNull' => 0, 'col_extra' => 'auto_increment', 'col_default' => 1, 'col_collation' => '', 'col_attribute' => 'UNSIGNED' ), array('col_name' => "col1", 'col_type' => 'varchar', 'col_length' => 100, 'col_isNull' => 1, 'col_extra' => '', 'col_default' => 1, 'col_collation' => '', 'col_attribute' => 'BINARY' ), array( 'col_name' => "col2", 'col_type' => 'DATETIME', 'col_length' => 0, 'col_isNull' => 1, 'col_extra' => '', 'col_default' => 'CURRENT_TIMESTAMP', 'col_collation' => '', 'col_attribute' => 'on update CURRENT_TIMESTAMP' ) ); /** * prepares environment for tests * * @return void */ public function setUp() { $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['cfg']['Server']['user'] = 'pma_user'; $GLOBALS['cfg']['Server']['DisableIS'] = true; $GLOBALS['cfg']['MaxRows'] = 10; $GLOBALS['cfg']['ServerDefault'] = "PMA_server"; $GLOBALS['cfg']['ActionLinksMode'] = 'icons'; $GLOBALS['cfg']['CharEditing'] = ''; $GLOBALS['cfg']['LimitChars'] = 50; $GLOBALS['db'] = 'PMA_db'; $GLOBALS['table'] = 'PMA_table'; //$_SESSION $GLOBALS['server'] = 1; $_SESSION['relation'][1] = array( 'PMA_VERSION' => PMA_VERSION, 'centralcolumnswork' => true, 'relwork' => 1, 'db' => 'phpmyadmin', 'relation' => 'relation', 'central_columns' => 'pma_central_columns' ); // mock DBI $dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface') ->disableOriginalConstructor() ->getMock(); $dbi->types = new Types($dbi); $GLOBALS['dbi'] = $dbi; // set some common expectations $dbi->expects($this->any()) ->method('selectDb') ->will($this->returnValue(true)); $dbi->expects($this->any()) ->method('getColumns') ->will( $this->returnValue( array( "id"=>array("Type"=>"integer", "Null"=>"NO"), "col1"=>array("Type"=>'varchar(100)', "Null"=>"YES"), "col2"=>array("Type"=>'DATETIME', "Null"=>"NO") ) ) ); $dbi->expects($this->any()) ->method('getColumnNames') ->will($this->returnValue(array("id", "col1", "col2"))); $dbi->expects($this->any()) ->method('tryQuery') ->will($this->returnValue(true)); $dbi->expects($this->any()) ->method('getTables') ->will( $this->returnValue(array("PMA_table", "PMA_table1", "PMA_table2")) ); $dbi->expects($this->any())->method('escapeString') ->will($this->returnArgument(0)); } /** * Test for CentralColumns::getParams * * @return void */ public function testPMACentralColumnsGetParams() { $this->assertSame( array( 'user' => 'pma_user', 'db' => 'phpmyadmin', 'table' => 'pma_central_columns' ), CentralColumns::getParams($GLOBALS['cfg']['Server']['user']) ); } /** * Test for CentralColumns::getColumnsList * * @return void */ public function testPMAGetColumnsList() { $GLOBALS['dbi']->expects($this->exactly(2)) ->method('fetchResult') ->willReturnOnConsecutiveCalls( $this->_columnData, array_slice($this->_columnData, 1, 2) ); $this->assertEquals( $this->_modifiedColumnData, CentralColumns::getColumnsList( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], 'phpmyadmin' ) ); $this->assertEquals( array_slice($this->_modifiedColumnData, 1, 2), CentralColumns::getColumnsList( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], 'phpmyadmin', 1, 2 ) ); } /** * Test for CentralColumns::getCount * * @return void */ function testPMAGetCentralColumnsCount() { $GLOBALS['dbi']->expects($this->once()) ->method('fetchResult') ->with( "SELECT count(db_name) FROM `pma_central_columns` " . "WHERE db_name = 'phpmyadmin';", null, null, DatabaseInterface::CONNECT_CONTROL ) ->will( $this->returnValue(array(3)) ); $this->assertEquals( 3, CentralColumns::getCount( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], 'phpmyadmin' ) ); } /** * Test for CentralColumns::syncUniqueColumns * * @return void */ public function testPMASyncUniqueColumns() { $_REQUEST['db'] = 'PMA_db'; $_REQUEST['table'] = 'PMA_table'; $this->assertTrue( CentralColumns::syncUniqueColumns( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], array('PMA_table') ) ); } /** * Test for CentralColumns::deleteColumnsFromList * * @return void */ public function testPMADeleteColumnsFromList() { $_REQUEST['db'] = 'PMA_db'; $_REQUEST['table'] = 'PMA_table'; // when column exists in the central column list $GLOBALS['dbi']->expects($this->at(4)) ->method('fetchResult') ->with( "SELECT col_name FROM `pma_central_columns` " . "WHERE db_name = 'PMA_db' AND col_name IN ('col1');", null, null, DatabaseInterface::CONNECT_CONTROL ) ->will( $this->returnValue(array('col1')) ); $GLOBALS['dbi']->expects($this->at(7)) ->method('tryQuery') ->with( "DELETE FROM `pma_central_columns` " . "WHERE db_name = 'PMA_db' AND col_name IN ('col1');", DatabaseInterface::CONNECT_CONTROL ) ->will( $this->returnValue(array('col1')) ); $this->assertTrue( CentralColumns::deleteColumnsFromList( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], array("col1"), false ) ); // when column does not exist in the central column list $this->assertInstanceOf( 'PhpMyAdmin\Message', CentralColumns::deleteColumnsFromList( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], array('column1'), false ) ); $this->assertInstanceOf( 'PhpMyAdmin\Message', CentralColumns::deleteColumnsFromList( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], array('PMA_table') ) ); } /** * Test for CentralColumns::makeConsistentWithList * * @return void */ public function testPMAMakeConsistentWithList() { $GLOBALS['dbi']->expects($this->any()) ->method('fetchResult') ->will( $this->returnValue($this->_columnData) ); $GLOBALS['dbi']->expects($this->any()) ->method('fetchValue') ->will( $this->returnValue('PMA_table=CREATE table `PMA_table` (id integer)') ); $this->assertTrue( CentralColumns::makeConsistentWithList( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], "phpmyadmin", array('PMA_table') ) ); } /** * Test for CentralColumns::getFromTable * * @return void */ public function testPMAGetCentralColumnsFromTable() { $db = 'PMA_db'; $table = 'PMA_table'; $GLOBALS['dbi']->expects($this->once()) ->method('fetchResult') ->with( "SELECT col_name FROM `pma_central_columns` " . "WHERE db_name = 'PMA_db' AND col_name IN ('id','col1','col2');", null, null, DatabaseInterface::CONNECT_CONTROL ) ->will( $this->returnValue(array('id','col1')) ); $this->assertEquals( array("id", "col1"), CentralColumns::getFromTable( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], $db, $table ) ); } /** * Test for CentralColumns::getFromTable with $allFields = true * * @return void */ public function testPMAGetCentralColumnsFromTableWithAllFields() { $db = 'PMA_db'; $table = 'PMA_table'; $GLOBALS['dbi']->expects($this->once()) ->method('fetchResult') ->with( "SELECT * FROM `pma_central_columns` " . "WHERE db_name = 'PMA_db' AND col_name IN ('id','col1','col2');", null, null, DatabaseInterface::CONNECT_CONTROL ) ->will( $this->returnValue(array_slice($this->_columnData, 0, 2)) ); $this->assertEquals( array_slice($this->_modifiedColumnData, 0, 2), CentralColumns::getFromTable( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], $db, $table, true ) ); } /** * Test for CentralColumns::updateOneColumn * * @return void */ public function testPMAUpdateOneColumn() { $this->assertTrue( CentralColumns::updateOneColumn( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], "phpmyadmin", "", "", "", "", "", "", "", "", "" ) ); $this->assertTrue( CentralColumns::updateOneColumn( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], "phpmyadmin", "col1", "", "", "", "", "", "", "", "" ) ); } /** * Test for CentralColumns::updateMultipleColumn * * @return void */ public function testPMAUpdateMultipleColumn() { $_POST['db'] = 'phpmyadmin'; $_POST['orig_col_name'] = array("col1","col2"); $_POST['field_name'] = array("col1","col2"); $_POST['field_default_type'] = array("",""); $_POST['col_extra'] = array("",""); $_POST['field_length'] = array("",""); $_POST['field_attribute'] = array("",""); $_POST['field_type'] = array("",""); $_POST['field_collation'] = array("",""); $this->assertTrue( CentralColumns::updateMultipleColumn( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'] ) ); } /** * Test for CentralColumns::getHtmlForEditingPage * * @return void */ public function testPMAGetHTMLforEditingPage() { $GLOBALS['dbi']->expects($this->any()) ->method('fetchResult') ->with( "SELECT * FROM `pma_central_columns` " . "WHERE db_name = 'phpmyadmin' AND col_name IN ('col1','col2');", null, null, DatabaseInterface::CONNECT_CONTROL ) ->will( $this->returnValue($this->_columnData) ); $result = CentralColumns::getHtmlForEditingPage( $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user'], $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], array("col1", "col2"), 'phpmyadmin' ); $this->assertContains( '