getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
$dbi->types = new Types($dbi);
$GLOBALS['dbi'] = $dbi;
// set expectations
$dbi->expects($this->any())
->method('selectDb')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('getColumns')
->will(
$this->returnValue(
[
'id' => ['Type' => 'integer'],
'col1' => ['Type' => 'varchar(100)'],
'col2' => ['Type' => 'DATETIME'],
]
)
);
$dbi->expects($this->any())
->method('getColumnNames')
->will($this->returnValue(['id', 'col1', 'col2']));
$map = [
[
'PMA_db',
'PMA_table1',
DatabaseInterface::CONNECT_USER,
[],
],
[
'PMA_db',
'PMA_table',
DatabaseInterface::CONNECT_USER,
[
[
'Key_name' => 'PRIMARY',
'Column_name' => 'id',
],
],
],
[
'PMA_db',
'PMA_table2',
DatabaseInterface::CONNECT_USER,
[
[
'Key_name' => 'PRIMARY',
'Column_name' => 'id',
],
[
'Key_name' => 'PRIMARY',
'Column_name' => 'col1',
],
],
],
];
$dbi->expects($this->any())
->method('getTableIndexes')
->will($this->returnValueMap($map));
$dbi->expects($this->any())
->method('tryQuery')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('fetchResult')
->will($this->returnValue([0]));
$template = new Template();
$this->normalization = new Normalization($dbi, new Relation($dbi, $template), new Transformations(), $template);
}
/**
* Test for getHtmlForColumnsList
*/
public function testGetHtmlForColumnsList(): void
{
$db = 'PMA_db';
$table = 'PMA_table';
$this->assertStringContainsString(
'',
$this->normalization->getHtmlForColumnsList($table, $db)
);
$this->assertEquals(
'col1 [ varchar(100) ]
',
$this->normalization->getHtmlForColumnsList($table, $db, 'String', 'checkbox')
);
}
/**
* Test for getHtmlForCreateNewColumn
*/
public function testGetHtmlForCreateNewColumn(): void
{
$GLOBALS['cfg']['BrowseMIME'] = true;
$GLOBALS['cfg']['MaxRows'] = 25;
$GLOBALS['col_priv'] = false;
$db = 'PMA_db';
$table = 'PMA_table';
$numFields = 1;
$result = $this->normalization->getHtmlForCreateNewColumn($numFields, $db, $table);
$this->assertStringContainsString(
'