createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertStringContainsString(
'style="width:12ex" name="criteriaSort[1]"',
$this->callFunction($object, Qbe::class, 'getSortSelectCell', [1]),
);
$this->assertStringNotContainsString(
'selected="selected"',
$this->callFunction($object, Qbe::class, 'getSortSelectCell', [1]),
);
$this->assertStringContainsString(
'value="ASC" selected="selected">',
$this->callFunction($object, Qbe::class, 'getSortSelectCell', [1, 'ASC']),
);
}
public function testGetSortRow(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertStringContainsString(
'name="criteriaSort[0]"',
$this->callFunction($object, Qbe::class, 'getSortRow', []),
);
$this->assertStringContainsString(
'name="criteriaSort[1]"',
$this->callFunction($object, Qbe::class, 'getSortRow', []),
);
$this->assertStringContainsString(
'name="criteriaSort[2]"',
$this->callFunction($object, Qbe::class, 'getSortRow', []),
);
}
public function testGetShowRow(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
'
| '
. ' | '
. ' | ',
$this->callFunction($object, Qbe::class, 'getShowRow', []),
);
}
public function testGetCriteriaInputboxRow(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
''
. ''
. ' | '
. ''
. ' | '
. ''
. ' | ',
$this->callFunction($object, Qbe::class, 'getCriteriaInputboxRow', []),
);
}
public function testGetAndOrColCell(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
'Or: And:'
. ' Ins Del | ',
$this->callFunction($object, Qbe::class, 'getAndOrColCell', [1]),
);
}
public function testGetModifyColumnsRow(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
''
. 'Or: And: Ins'
. ' '
. 'Del | Or: And:'
. ' Ins Del | Ins'
. ' '
. 'Del | ',
$this->callFunction($object, Qbe::class, 'getModifyColumnsRow', []),
);
}
public function testGetInputboxRow(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
' | '
. ' | | ',
$this->callFunction($object, Qbe::class, 'getInputboxRow', [2]),
);
}
public function testGetInsDelAndOrCriteriaRows(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$actual = $this->callFunction($object, Qbe::class, 'getInsDelAndOrCriteriaRows', [2, 3]);
$this->assertStringContainsString('', $actual);
$this->assertStringContainsString(
' | | |
',
$actual,
);
}
public function testGetSelectClause(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals('', $this->callFunction($object, Qbe::class, 'getSelectClause', []));
}
public function testGetWhereClause(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals('', $this->callFunction($object, Qbe::class, 'getWhereClause', []));
}
public function testGetOrderByClause(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals('', $this->callFunction($object, Qbe::class, 'getOrderByClause', []));
}
public function testGetIndexes(): void
{
$dbiDummy = $this->createDbiDummy();
$dbiDummy->addResult('SHOW INDEXES FROM `pma_test`.```table1```', []);
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
['unique' => [], 'index' => []],
$this->callFunction(
$object,
Qbe::class,
'getIndexes',
[['`table1`', 'table2'], ['column1', 'column2', 'column3'], ['column2']],
),
);
}
public function testGetLeftJoinColumnCandidates(): void
{
$dbiDummy = $this->createDbiDummy();
$dbiDummy->addSelectDb('pma_test');
$dbiDummy->addResult('SHOW INDEXES FROM `pma_test`.```table1```', []);
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
[0 => 'column2'],
$this->callFunction(
$object,
Qbe::class,
'getLeftJoinColumnCandidates',
[['`table1`', 'table2'], ['column1', 'column2', 'column3'], ['column2']],
),
);
}
public function testGetMasterTable(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
0,
$this->callFunction(
$object,
Qbe::class,
'getMasterTable',
[['table1', 'table2'], ['column1', 'column2', 'column3'], ['column2'], ['qbe_test']],
),
);
}
public function testGetWhereClauseTablesAndColumns(): void
{
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$_POST['criteriaColumn'] = ['table1.id', 'table1.value', 'table1.name', 'table1.deleted'];
$this->assertEquals(
['where_clause_tables' => [], 'where_clause_columns' => []],
$this->callFunction($object, Qbe::class, 'getWhereClauseTablesAndColumns', []),
);
}
public function testGetFromClause(): void
{
$GLOBALS['db'] = 'pma_test';
$dbiDummy = $this->createDbiDummy();
$createTableStatement = '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';
$dbiDummy->addResult('SHOW CREATE TABLE `pma_test`.`table1`', [[$createTableStatement]]);
$dbiDummy->addSelectDb('pma_test');
$dbiDummy->addResult('SHOW CREATE TABLE `pma_test`.`table1`', [[$createTableStatement]]);
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$_POST['criteriaColumn'] = ['table1.id', 'table1.value', 'table1.name', 'table1.deleted'];
$this->assertEquals('`table1`', $this->callFunction($object, Qbe::class, 'getFromClause', [['`table1`.`id`']]));
}
public function testGetSQLQuery(): void
{
$GLOBALS['db'] = 'pma_test';
$dbiDummy = $this->createDbiDummy();
$createTableStatement = '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';
$dbiDummy->addResult('SHOW CREATE TABLE `pma_test`.`table1`', [[$createTableStatement]]);
$dbiDummy->addSelectDb('pma_test');
$dbiDummy->addResult('SHOW CREATE TABLE `pma_test`.`table1`', [[$createTableStatement]]);
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
$object = new Qbe(new Relation($GLOBALS['dbi']), new Template(), $GLOBALS['dbi'], 'pma_test');
$_POST['criteriaColumn'] = ['table1.id', 'table1.value', 'table1.name', 'table1.deleted'];
$this->assertEquals(
'FROM `table1`' . "\n",
$this->callFunction($object, Qbe::class, 'getSQLQuery', [['`table1`.`id`']]),
);
}
}