N°3176 - OQL: Fix malformed UNION queries in portal scopes

Fix regression in Unit tests
This commit is contained in:
Eric
2020-07-22 17:30:38 +02:00
parent 1f66d53ab4
commit 8122270476
4 changed files with 64 additions and 65 deletions

View File

@@ -455,52 +455,4 @@ class DBSearchIntersectTest extends ItopTestCase
return $aQueries;
}
/**
* Bug #2970
* @throws \CoreException
* @throws \CoreWarning
* @throws \OQLException
*/
public function testFilterOnJoin()
{
$sReq1 = "SELECT `L-1` FROM Organization AS `L-1` WHERE (`L-1`.`id` = :current_contact->org_id)";
$sReq2 = "SELECT `L-1-1` FROM CustomerContract AS `L-1-1` JOIN Organization AS `O` ON `L-1-1`.org_id = `O`.id WHERE (((`L-1-1`.`status` = 'active') OR (`L-1-1`.`status` = 'standby')) AND (`O`.`id` = :current_contact->org_id))";
$oFilter1 = DBSearch::FromOQL($sReq1);
$oFilter2 = DBSearch::FromOQL($sReq2);
$aRealiasingMap = array();
$oFilter1 = $oFilter1->Join($oFilter2,
DBSearch::JOIN_REFERENCED_BY,
'org_id',
TREE_OPERATOR_EQUALS, $aRealiasingMap);
$sRes1 = $oFilter1->ToOQL();
$this->debug($sRes1);
foreach($oFilter1->GetCriteria_ReferencedBy() as $sForeignClass => $aReferences)
{
foreach ($aReferences as $sForeignExtKeyAttCode => $aFiltersByOperator)
{
foreach ($aFiltersByOperator as $iOperatorCode => $aFilters)
{
foreach ($aFilters as $index => $oForeignFilter)
{
$this->debug($oForeignFilter->ToOQL());
}
}
}
}
$this->assertFalse(strpos($sRes1, '`O`.'));
$sReq3 = "SELECT `CustomerContract` FROM CustomerContract AS `CustomerContract` WHERE (`CustomerContract`.`org_id` IN ('2'))";
$oFilter3 = DBSearch::FromOQL($sReq3);
$oFilter1 = $oFilter1->Filter('L-1-1', $oFilter3);
$sRes1 = $oFilter1->ToOQL();
$this->debug($sRes1);
$this->assertFalse(strpos($sRes1, '`O`.'));
}
}

View File

@@ -15,7 +15,9 @@ use DBSearch;
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
class DBSearchAddCondition_ReferencedByTest extends ItopDataTestCase {
class DBSearchJoinTest extends ItopDataTestCase {
const USE_TRANSACTION = false;
protected function setUp()
{
@@ -24,7 +26,7 @@ class DBSearchAddCondition_ReferencedByTest extends ItopDataTestCase {
}
/**
* @dataProvider AddCondition_ReferencedByProvider
* @dataProvider JoinProvider
*
* @param $sLeftSelect
* @param $sRightSelect
@@ -37,7 +39,7 @@ class DBSearchAddCondition_ReferencedByTest extends ItopDataTestCase {
* @throws \MySQLException
* @throws \OQLException
*/
public function testAddCondition_ReferencedBy($sLeftSelect, $sRightSelect, $sParentAtt, $sResult)
public function testJoin($sLeftSelect, $sRightSelect, $sParentAtt, $sResult)
{
$oLeftSearch = DBSearch::FromOQL($sLeftSelect);
$oRightSearch = DBSearch::FromOQL($sRightSelect);
@@ -50,7 +52,7 @@ class DBSearchAddCondition_ReferencedByTest extends ItopDataTestCase {
$this->assertEquals($sResult, $oResultSearch->ToOQL());
}
public function AddCondition_ReferencedByProvider()
public function JoinProvider()
{
// Breakpoint in BrowseBrickController::DisplayAction()
// $aLevelsProperties[$aLevelsPropertiesKeys[$i]]['search'] = $aLevelsProperties[$aLevelsPropertiesKeys[$i]]['search']->Join($aLevelsProperties[$aLevelsPropertiesKeys[$i + 1]]['search'],
@@ -77,4 +79,53 @@ class DBSearchAddCondition_ReferencedByTest extends ItopDataTestCase {
// ],
];
}
/**
* Bug #2970
* @throws \CoreException
* @throws \CoreWarning
* @throws \OQLException
*/
public function testFilterOnJoin()
{
$sReq1 = "SELECT `L-1` FROM Organization AS `L-1` WHERE (`L-1`.`id` = 2)";
$sReq2 = "SELECT `L-1-1` FROM CustomerContract AS `L-1-1` JOIN Organization AS `O` ON `L-1-1`.org_id = `O`.id WHERE (((`L-1-1`.`status` = 'active') OR (`L-1-1`.`status` = 'standby')) AND (`O`.`id` = 2))";
$oFilter1 = DBSearch::FromOQL($sReq1);
$oFilter2 = DBSearch::FromOQL($sReq2);
$aRealiasingMap = array();
$oFilter1 = $oFilter1->Join($oFilter2,
DBSearch::JOIN_REFERENCED_BY,
'org_id',
TREE_OPERATOR_EQUALS, $aRealiasingMap);
$sRes1 = $oFilter1->ToOQL();
$this->debug($sRes1);
foreach($oFilter1->GetCriteria_ReferencedBy() as $sForeignClass => $aReferences)
{
foreach ($aReferences as $sForeignExtKeyAttCode => $aFiltersByOperator)
{
foreach ($aFiltersByOperator as $iOperatorCode => $aFilters)
{
foreach ($aFilters as $index => $oForeignFilter)
{
$this->debug($oForeignFilter->ToOQL());
}
}
}
}
$this->assertFalse(strpos($sRes1, '`O`.'));
$sReq3 = "SELECT `CustomerContract` FROM CustomerContract AS `CustomerContract` WHERE (`CustomerContract`.`org_id` IN ('2'))";
$oFilter3 = DBSearch::FromOQL($sReq3);
$oFilter1 = $oFilter1->Filter('L-1-1', $oFilter3);
$sRes1 = $oFilter1->ToOQL();
$this->debug($sRes1);
$this->assertFalse(strpos($sRes1, '`O`.'));
}
}