mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 11:38:44 +02:00
N°6182 - Fix crash with UNION OQL queries when classes / aliases are different
This commit is contained in:
@@ -15,6 +15,52 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
class DBUnionSearchTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @dataProvider UnionSearchProvider
|
||||
*
|
||||
* @param $sOQL
|
||||
*
|
||||
* @return void
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function testUnionSearch($sOQL)
|
||||
{
|
||||
$oSearch = DBSearch::FromOQL($sOQL);
|
||||
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
if ($oSet->Count() > 0) {
|
||||
$aSelectedAliases = array_keys($oSearch->GetSelectedClasses());
|
||||
$aFirstRow = $oSet->FetchAssoc();
|
||||
$aAliases = array_keys($aFirstRow);
|
||||
$this->assertEquals($aSelectedAliases, $aAliases);
|
||||
}
|
||||
|
||||
$aSelectedClasses = $oSearch->GetSelectedClasses();
|
||||
foreach ($aSelectedClasses as $sSelectedAlias => $sSelectedClass) {
|
||||
$oSearchTest = $oSearch->DeepClone();
|
||||
$oSearchTest->SetSelectedClasses([$sSelectedAlias]);
|
||||
$oSet = new DBObjectSet($oSearchTest);
|
||||
if ($oSet->Count() > 0) {
|
||||
$aSelectedAliases = array_keys($oSearchTest->GetSelectedClasses());
|
||||
$aFirstRow = $oSet->FetchAssoc();
|
||||
$aAliases = array_keys($aFirstRow);
|
||||
$this->assertEquals($aSelectedAliases, $aAliases);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function UnionSearchProvider()
|
||||
{
|
||||
return [
|
||||
'Same class' => ["SELECT Server UNION SELECT Server"],
|
||||
'different class same alias' => ['SELECT Server AS fci UNION SELECT VirtualMachine AS fci'],
|
||||
'different class no alias' => ['SELECT Server UNION SELECT VirtualMachine'],
|
||||
'multiple classes same alias' => ['SELECT `L`, `P` FROM Location AS `L` JOIN Person AS `P` ON `P`.location_id = `L`.id WHERE (`L`.`org_id` = 3) UNION SELECT `L`, `P` FROM Location AS `L` JOIN Person AS `P` ON `P`.location_id = `L`.id WHERE (`L`.`org_id` = 2)'],
|
||||
'multiple classes' => ['SELECT `L`, `P` FROM Location AS `L` JOIN Person AS `P` ON `P`.location_id = `L`.id WHERE (`L`.`org_id` = 3) UNION SELECT `L1`, `P1` FROM Person AS `P1` JOIN Location AS `L1` ON `P1`.location_id = `L1`.id WHERE (`P1`.`org_id` = 2)'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testFilterOnFirstSelectedClass()
|
||||
{
|
||||
$sSourceOQL = 'SELECT `Person`, `Location` FROM Person AS `Person` JOIN Location AS `Location` ON `Person`.location_id = `Location`.id WHERE (`Location`.`id` = 1)';
|
||||
|
||||
Reference in New Issue
Block a user