diff --git a/test/libraries/PMA_tbl_columns_definition_form_test.php b/test/libraries/PMA_tbl_columns_definition_form_test.php new file mode 100644 index 0000000000..ee4c948cea --- /dev/null +++ b/test/libraries/PMA_tbl_columns_definition_form_test.php @@ -0,0 +1,1116 @@ +assertEquals( + array( + 'db' => 'dbname', + 'reload' => 1, + 'orig_num_fields' => 22, + 'orig_field_where' => 'fwhere', + 'orig_after_field' => 'affield', + 'selected[0]' => 12, + 'selected[1]' => 13 + ), + $result + ); + + // case 2 + $result = PMA_getFormsParameters( + "dbname", "tablename", "tbl_addfield.php", null, 1 + ); + + $this->assertEquals( + array( + 'db' => 'dbname', + 'table' => 'tablename', + 'orig_field_where' => 'fwhere', + 'orig_after_field' => 'affield', + 'field_where' => 'fwhere', + 'after_field' => 'affield' + ), + $result + ); + + // case 3 + $_REQUEST['after_field'] = null; + $_REQUEST['field_where'] = null; + + $result = PMA_getFormsParameters( + "dbname", "tablename", null, 0, null + ); + + $this->assertEquals( + array( + 'db' => 'dbname', + 'table' => 'tablename', + 'orig_num_fields' => 0 + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForTableConfigurations + * + * @return void + */ + public function testGetHtmlForTableConfigurations() + { + $_REQUEST['comment'] = 'c&d'; + $_REQUEST['tbl_storage_engine'] = 'engine'; + $_REQUEST['tbl_collation'] = 'latin1_swedish_ci'; + $_REQUEST['partition_definition'] = "partition>"; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->any()) + ->method('fetchResult') + ->will( + $this->returnValue( + array( + array( + 'Name' => 'partition', + 'Support' => 'NO' + ) + ) + ) + ); + + $GLOBALS['dbi'] = $dbi; + + $result = PMA_getHtmlForTableConfigurations(); + + $this->assertTag( + PMA_getTagArray( + 'assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + . 'utf8_bin' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + 'partition>' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForFooter + * + * @return void + */ + public function testGetHtmlForFooter() + { + $result = PMA_getHtmlForFooter(); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForTableNameAndNoOfColumns + * + * @return void + */ + public function testGetHtmlForTableNameAndNoOfColumns() + { + $_REQUEST['table'] = "tablename"; + + $result = PMA_getHtmlForTableNameAndNoOfColumns(); + + $this->assertTag( + PMA_getTagArray( + 'assertTag( + PMA_getTagArray( + 'assertTag( + PMA_getTagArray( + 'assertTag( + array('tag' => 'th', 'content' => 'h1'), + $result + ); + + $this->assertTag( + array('tag' => 'th', 'content' => 'h2'), + $result + ); + + $this->assertTag( + array('tag' => 'td', 'content' => 'a'), + $result + ); + + $this->assertTag( + array('tag' => 'td', 'content' => 'b'), + $result + ); + + $this->assertTag( + array('tag' => 'td', 'content' => 'c'), + $result + ); + } + + /** + * Test for PMA_getHtmlForTableCreateOrAddField + * + * @return void + */ + public function testGetHtmlForTableCreateOrAddField() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->any()) + ->method('fetchResult') + ->will( + $this->returnValue( + array() + ) + ); + + $GLOBALS['dbi'] = $dbi; + $result = PMA_getHtmlForTableCreateOrAddField( + "tbl_create.php", + array('a' => 'b'), + array(array('c1')), + array('h1') + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + 'assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + 'assertTag( + PMA_getTagArray( + 'assertContains( + 'Index', + $result + ); + + $this->assertContains( + 'Move column', + $result + ); + + $this->assertContains( + 'MIME type', + $result + ); + + $this->assertContains( + 'transformation_overview.php?db=db&table=table', + $result[count($result)-1] + ); + } + + /** + * Test for PMA_getMoveColumns + * + * @return void + */ + public function testGetMoveColumns() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->with("SELECT * FROM `db`.`table` LIMIT 1") + ->will($this->returnValue('v1')); + + $dbi->expects($this->once()) + ->method('getFieldsMeta') + ->with("v1") + ->will($this->returnValue('movecols')); + + $GLOBALS['dbi'] = $dbi; + + $this->assertEquals( + PMA_getMoveColumns('db', 'table'), + 'movecols' + ); + } + + /** + * Test for PMA_getRowDataForRegeneration + * + * @return void + */ + public function testGetRowDataForRegeneration() + { + $_REQUEST = array( + 'field_name' => array(1 => 'name'), + 'field_type' => array(0 => 'type'), + 'field_collation' => array(1 => 'colltn'), + 'field_null' => array(1 => true), + 'field_key' => array(1 => "fulltext_1"), + 'field_default_type' => array(1 => 'USER_DEFINED'), + 'field_default_value' => array(1 => 'DEF'), + 'field_extra' => array(1 => 'extra') + ); + + $submit_fulltext = array(1 => 1); + + $result = PMA_getRowDataForRegeneration(1, $submit_fulltext); + + $this->assertEquals( + array( + 'Field' => 'name', + 'Type' => '', + 'Collation' => 'colltn', + 'Null' => '1', + 'Key' => '', + 'DefaultType' => 'USER_DEFINED', + 'DefaultValue' => 'DEF', + 'Default' => 'DEF', + 'Extra' => 'extra', + 'Comment' => 'FULLTEXT' + ), + $result + ); + } + + /** + * Test for PMA_getSubmitPropertiesForRegeneration + * + * @return void + */ + public function testGetSubmitPropertiesForRegeneration() + { + $_REQUEST = array( + 'field_length' => array(1 => 22), + 'field_attribute' => array(1 => 'attr'), + 'field_default_current_timestamp' => array() + ); + + $result = PMA_getSubmitPropertiesForRegeneration(1); + + $this->assertEquals( + array(22, 'attr', false), + $result + ); + + } + + /** + * Test for PMA_getColumnMetaForDefault + * + * @return void + */ + public function testHandleRegeneration() + { + $_REQUEST = array( + 'field_comments' => array(1 => 'comm'), + 'field_mimetype' => array(1 => 'mime'), + 'field_transformation' => array(1 => 'trans'), + 'field_transformation_options' => array(1 => 'transops') + ); + + $result = PMA_handleRegeneration(1, 'FULLTEXT', array(), array()); + + $this->assertEquals( + array('comm'), + $result[4] + ); + + $this->assertEquals( + array( + array( + 'mimetype' => 'mime', + 'transformation' => 'trans', + 'transformation_options' => 'transops' + ) + ), + $result[5] + ); + } + + /** + * Test for PMA_getColumnMetaForDefault + * + * @return void + */ + public function testGetColumnMetaForDefault() + { + $cmeta = array( + 'Default' => null, + 'Null' => 'YES', + 'DefaultType' => 'a', + 'DefaultValue' => 'b', + ); + + $result = PMA_getColumnMetaForDefault($cmeta, null); + + $this->assertEquals( + 'NULL', + $result['DefaultType'] + ); + + $this->assertEquals( + '', + $result['DefaultValue'] + ); + + // case 2 + $cmeta = array( + 'Default' => null, + 'Null' => 'NO', + 'DefaultType' => 'a', + 'DefaultValue' => 'b', + ); + + $result = PMA_getColumnMetaForDefault($cmeta, true); + + $this->assertEquals( + 'USER_DEFINED', + $result['DefaultType'] + ); + + $this->assertEquals( + null, + $result['DefaultValue'] + ); + + // case 3 + $cmeta = array( + 'Default' => null, + 'Null' => 'NO', + 'DefaultType' => 'a', + 'DefaultValue' => 'b', + ); + + $result = PMA_getColumnMetaForDefault($cmeta, false); + + $this->assertEquals( + 'NONE', + $result['DefaultType'] + ); + + $this->assertEquals( + null, + $result['DefaultValue'] + ); + + // case 4 + $cmeta = array( + 'Default' => 'CURRENT_TIMESTAMP', + 'Null' => 'NO', + 'DefaultType' => 'a', + 'DefaultValue' => 'b', + ); + + $result = PMA_getColumnMetaForDefault($cmeta, false); + + $this->assertEquals( + 'CURRENT_TIMESTAMP', + $result['DefaultType'] + ); + + $this->assertEquals( + null, + $result['DefaultValue'] + ); + + // case 5 + $cmeta = array( + 'Default' => 'SOMETHING_ELSE', + 'Null' => 'NO', + 'DefaultType' => 'a', + 'DefaultValue' => 'b', + ); + + $result = PMA_getColumnMetaForDefault($cmeta, false); + + $this->assertEquals( + 'USER_DEFINED', + $result['DefaultType'] + ); + + $this->assertEquals( + 'SOMETHING_ELSE', + $result['DefaultValue'] + ); + } + + /** + * Test for PMA_getHtmlForColumnName + * + * @return void + */ + public function testGetHtmlForColumnName() + { + $result = PMA_getHtmlForColumnName( + 2, 4, 4, array('Field' => "fieldname") + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnType + * + * @return void + */ + public function testGetHtmlForColumnType() + { + $GLOBALS['PMA_Types'] = new PMA_Types; + $result = PMA_getHtmlForColumnType( + 1, 4, 3, false + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + 'INT' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForTransformationOption + * + * @return void + */ + public function testGetHtmlForTransformationOption() + { + $cmeta = array( + 'Field' => 'fieldname' + ); + + $mime = array( + 'fieldname' => array( + 'transformation_options' => 'transops' + ) + ); + + $result = PMA_getHtmlForTransformationOption( + 2, 4, 4, $cmeta, $mime + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForBrowserTransformation + * + * @return void + */ + public function testGetHtmlForBrowserTransformation() + { + $cmeta = array( + 'Field' => 'fieldname' + ); + + $mime = array( + 'fieldname' => array( + 'transformation' => 'Text_Plain_Append.class.php', + 'transformation_options' => 'transops' + ) + ); + + $avail_mime = array( + 'transformation' => array( + 'foo' => 'bar' + ), + 'transformation_file' => array( + 'foo' => 'Text_Plain_Append.class.php' + ) + ); + $result = PMA_getHtmlForBrowserTransformation( + 2, 0, 0, $avail_mime, $cmeta, $mime + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'bar') + ), + $result + ); + + $this->assertContains( + 'selected ', + $result + ); + } + + /** + * Test for PMA_getHtmlForMoveColumn + * + * @return void + */ + public function testGetHtmlForMoveColumn() + { + $cmeta = array( + 'Field' => 'fieldname' + ); + + $moveColumns = array(); + + $temp = new stdClass; + $temp->name = 'a'; + $moveColumns[] = $temp; + + $temp = new stdClass; + $temp->name = 'fieldname'; + $moveColumns[] = $temp; + + $result = PMA_getHtmlForMoveColumn( + 2, 0, 0, $moveColumns, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => ' ') + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'after `a`') + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'after `fieldname`') + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnComment + * + * @return void + */ + public function testGetHtmlForColumnComment() + { + $cmeta = array( + 'Field' => 'fieldname' + ); + + $commentMeta = array( + 'fieldname' => 'fieldnamecomment<' + ); + + $result = PMA_getHtmlForColumnComment( + 2, 1, 0, $cmeta, $commentMeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnAutoIncrement + * + * @return void + */ + public function testGetHtmlForColumnAutoIncrement() + { + $cmeta = array( + 'Extra' => 'auto_increment' + ); + + $result = PMA_getHtmlForColumnAutoIncrement( + 2, 1, 0, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnIndexes + * + * @return void + */ + public function testGetHtmlForColumnIndexes() + { + $cmeta = array( + 'Extra' => 'auto_increment', + 'Field' => 'fieldname' + ); + + $result = PMA_getHtmlForColumnIndexes( + 2, 1, 0, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '---' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'PRIMARY') + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'UNIQUE') + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'INDEX') + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForIndexTypeOption + * + * @return void + */ + public function testGetHtmlForIndexTypeOption() + { + $cmeta = array( + 'Key' => 'PRI' + ); + + $result = PMA_getHtmlForIndexTypeOption( + 2, $cmeta, 'INT', 'PRI' + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'INT') + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnNull + * + * @return void + */ + public function testGetHtmlForColumnNull() + { + $cmeta = array( + 'Null' => 'YES' + ); + + $result = PMA_getHtmlForColumnNull( + 2, 3, 1, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnAttribute + * + * @return void + */ + public function testGetHtmlForColumnAttribute() + { + $cmeta = array( + 'Null' => 'YES', + 'Extra' => 'on update CURRENT_TIMESTAMP', + 'Field' => 'f' + ); + + $colspec = array('attribute' => 'attr'); + + $analyzed_sql[0]['create_table_fields'] = array( + 'f' => array( + 'default_current_timestamp' => true, + ) + ); + + $types = $this->getMockBuilder('PMA_Types') + ->disableOriginalConstructor() + ->setMethods(array('getAttributes')) + ->getMock(); + + $types->expects($this->once()) + ->method('getAttributes') + ->will( + $this->returnValue( + array('on update CURRENT_TIMESTAMP') + ) + ); + + $GLOBALS['PMA_Types'] = $types; + $result = PMA_getHtmlForColumnAttribute( + 2, 3, 1, $colspec, $cmeta, true, $analyzed_sql, true + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'on update CURRENT_TIMESTAMP') + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnCollation + * + * @return void + */ + public function testGetHtmlForColumnCollation() + { + $cmeta = array( + 'Collation' => 'utf8_general_ci' + ); + + $result = PMA_getHtmlForColumnCollation( + 2, 3, 1, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'utf8_bin') + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnLength + * + * @return void + */ + public function testGetHtmlForColumnLength() + { + $result = PMA_getHtmlForColumnLength( + 2, 3, 1, 10, 8 + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnDefault + * + * @return void + */ + public function testGetHtmlForColumnDefault() + { + $cmeta = array( + 'Default' => 'YES', + 'DefaultType' => 'NONE', + 'DefaultValue' => '2222' + ); + + $result = PMA_getHtmlForColumnDefault( + 2, 3, 1, 'TIMESTAMP', true, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'None') + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getFormParamsForOldColumn + * + * @return void + */ + public function testGetFormParamsForOldColumn() + { + // Function needs correction + } +} +?> \ No newline at end of file
' + ), + $result + ); + } + + /** + * Test for PMA_getHtmlForColumnDefault + * + * @return void + */ + public function testGetHtmlForColumnDefault() + { + $cmeta = array( + 'Default' => 'YES', + 'DefaultType' => 'NONE', + 'DefaultValue' => '2222' + ); + + $result = PMA_getHtmlForColumnDefault( + 2, 3, 1, 'TIMESTAMP', true, $cmeta + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '', + array('content' => 'None') + ), + $result + ); + + $this->assertTag( + PMA_getTagArray( + '' + ), + $result + ); + } + + /** + * Test for PMA_getFormParamsForOldColumn + * + * @return void + */ + public function testGetFormParamsForOldColumn() + { + // Function needs correction + } +} +?> \ No newline at end of file