From 92285b55b6eccf74161f3326bbfdf02207dfd1ed Mon Sep 17 00:00:00 2001 From: odain Date: Mon, 28 Oct 2019 15:50:53 +0100 Subject: [PATCH] add few tests on OQL group by --- test/core/DBSearchTest.php | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/core/DBSearchTest.php b/test/core/DBSearchTest.php index 29f2c181d..f73ee4a75 100644 --- a/test/core/DBSearchTest.php +++ b/test/core/DBSearchTest.php @@ -593,4 +593,67 @@ class DBSearchTest extends ItopDataTestCase ), ); } + + /** + * @throws Exception + */ + public function testSanity_GroupFunction_In_WherePart() + { + $sExceptionClass = ''; + $oSearch = DBSearch::FromOQL("SELECT FiberChannelInterface AS FCI"); + self::assertNotNull($oSearch); + + try + { + $oExpr1 = Expression::FromOQL('AVC(FCI.name)'); + //$aGroupBy = array('group1' => $oExpr1); + //$oSearch->MakeGroupByQuery(array(), $aGroupBy, false, array(), array()); + } + catch (Exception $e) + { + $sExceptionClass = get_class($e); + } + + static::assertEquals('OQLParserException', $sExceptionClass); + } + + public function testSanity_GroupFunction_In_GroupByPart() + { + $sExceptionClass = ''; + try + { + $oSearch = DBSearch::FromOQL("SELECT FiberChannelInterface AS FCI WHERE COUNT(FCI.name) = AVC(FCI.name)"); + //$oSearch->MakeGroupByQuery(array(), array(), false, array(), array()); + } + catch (Exception $e) + { + $sExceptionClass = get_class($e); + } + + static::assertEquals('OQLParserException', $sExceptionClass); + } + + public function testSanity_UnknownGroupFunction_In_SelectPart() + { + $sExceptionClass = ''; + try + { + $oTimeExpr = Expression::FromOQL('FCI.speed'); + $oWrongExpr = new FunctionExpression('GABUZOMEU', array($oTimeExpr)); + // Alias => Expression + $aFunctions = array( + '_itop_wrong_' => $oWrongExpr, + ); + $oSearch = DBSearch::FromOQL("SELECT FiberChannelInterface AS FCI"); + $oSearch->MakeGroupByQuery(array(), array(), false, $aFunctions, array()); + } + catch (Exception $e) + { + $sExceptionClass = get_class($e); + } + + //later on it should raise an exception... + static::assertEquals('', $sExceptionClass); + } + }