N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 20:39:38 +01:00
parent 7681c157ec
commit b0a792afab
369 changed files with 22041 additions and 26866 deletions

View File

@@ -1,4 +1,5 @@
<?php
// Copyright (c) 2010-2024 Combodo SAS
//
// This file is part of iTop.
@@ -31,21 +32,21 @@ use MissingQueryArgument;
use MySQLException;
use MySQLHasGoneAwayException;
class ActionNewsroomTest extends ItopDataTestCase
{
const CREATE_TEST_ORG = true;
public const CREATE_TEST_ORG = true;
private int $iTrigger;
private int $iRecipientId;
protected function setUp(): void
{
parent::setUp();
$this->iTrigger = $this->GivenObjectInDB('TriggerOnObjectCreate',
array(
$this->iTrigger = $this->GivenObjectInDB(
'TriggerOnObjectCreate',
[
'description' => '[TEST] TriggerOnObjectCreate',
'target_class' => 'UserRequest',
)
]
);
$this->iRecipientId = $this->GivenPersonInDB(1);
}
@@ -54,7 +55,7 @@ class ActionNewsroomTest extends ItopDataTestCase
{
return [
'With Sync ActionNewsroom' => ['bIsAsynchronous' => false],
'With Async ActionNewsroom' => ['bIsAsynchronous' => true]
'With Async ActionNewsroom' => ['bIsAsynchronous' => true],
];
}
@@ -71,7 +72,8 @@ class ActionNewsroomTest extends ItopDataTestCase
{
$iActionNewsroomId = $this->GivenActionNewsroomInDB(false, 'Body of the notification');
$this->CreateUserRequest(1,
$this->CreateUserRequest(
1,
[
'title' => '[TEST] ActionNewsroom',
'org_id' => $this->getTestOrgId(),
@@ -85,7 +87,7 @@ class ActionNewsroomTest extends ItopDataTestCase
[
'action_id' => $iActionNewsroomId,
'message' => 'Body of the notification',
'title' => 'Title'
'title' => 'Title',
]
);
}
@@ -99,13 +101,14 @@ class ActionNewsroomTest extends ItopDataTestCase
{
$iActionNewsroomId = $this->GivenActionNewsroomInDB($bIsAsynchronous, '$this->service_name$');
$this->CreateUserRequest(1,
$this->CreateUserRequest(
1,
[
'title' => '[TEST] ActionNewsroom',
'org_id' => $this->getTestOrgId(),
'caller_id' => $this->iRecipientId,
'description' => 'PHPUnit Test',
'service_id' => 0
'service_id' => 0,
]
);
@@ -114,7 +117,7 @@ class ActionNewsroomTest extends ItopDataTestCase
[
'action_id' => $iActionNewsroomId,
'title' => 'Notification not sent',
'message' => 'An error occurred while saving the notification'
'message' => 'An error occurred while saving the notification',
]
);
}
@@ -129,7 +132,7 @@ class ActionNewsroomTest extends ItopDataTestCase
'password' => 'admin_123',
'language' => 'EN US',
'profile_list' => ['profileid:'.self::$aURP_Profiles['Administrator']],
'contactid' => $this->iRecipientId
'contactid' => $this->iRecipientId,
]);
return $this->GivenObjectInDB('ActionNewsroom', [
@@ -141,7 +144,7 @@ class ActionNewsroomTest extends ItopDataTestCase
'recipients' => "SELECT Person WHERE id = $this->iRecipientId",
'asynchronous' => $bIsAsynchronous ? 'yes' : 'no',
'trigger_list' => [
"trigger_id:$this->iTrigger"
"trigger_id:$this->iTrigger",
],
]);
}
@@ -151,10 +154,12 @@ class ActionNewsroomTest extends ItopDataTestCase
*/
private function GivenService(string $sName): int
{
return $this->GivenObjectInDB('Service', [
return $this->GivenObjectInDB(
'Service',
[
'name' => $sName,
'org_id' => $this->getTestOrgId()
'org_id' => $this->getTestOrgId(),
]
);
}
}
}

View File

@@ -8,7 +8,7 @@ use MetaModel;
class BulkChangeTest extends ItopDataTestCase
{
const CREATE_TEST_ORG = true;
public const CREATE_TEST_ORG = true;
protected function setUp(): void
{
@@ -18,17 +18,18 @@ class BulkChangeTest extends ItopDataTestCase
}
//bug 2888: csv import / data synchro issue with password validation
public function testPasswordBulkChangeIssue() {
public function testPasswordBulkChangeIssue()
{
/** @var Person $oPerson */
$oPerson = $this->createObject('Person', array(
$oPerson = $this->createObject('Person', [
'first_name' => 'isaac',
'name' => 'asimov',
'email' => 'isaac.asimov@fundation.org',
'org_id' => $this->getTestOrgId(),
));
]);
$aData = array(
array(
$aData = [
[
$oPerson->Get("first_name"),
$oPerson->Get("name"),
$oPerson->Get("email"),
@@ -36,19 +37,19 @@ class BulkChangeTest extends ItopDataTestCase
"iasimov",
"harryseldon",
"profileid->name:Administrator",
),
);
$aAttributes = array("language" => 3, "login" => 4, "password" => 5, "profile_list" => 6);
$aExtKeys = array(
],
];
$aAttributes = ["language" => 3, "login" => 4, "password" => 5, "profile_list" => 6];
$aExtKeys = [
"contactid" =>
array("first_name" => 0, "name" => 1, "email" => 2),
);
["first_name" => 0, "name" => 1, "email" => 2],
];
$oBulk = new BulkChange(
"UserLocal",
$aData,
$aAttributes,
$aExtKeys,
array("login"),
["login"],
null,
null,
"Y-m-d H:i:s", // date format
@@ -61,13 +62,14 @@ class BulkChangeTest extends ItopDataTestCase
foreach ($aRes as $aRow) {
if (array_key_exists('__STATUS__', $aRow)) {
$sStatus = $aRow['__STATUS__'];
$this->assertFalse(strstr($sStatus->GetDescription(), "CoreCannotSaveObjectException"),
"CSVimport/Datasynchro: Password validation failed with: ".$sStatus->GetDescription());
$this->assertFalse(
strstr($sStatus->GetDescription(), "CoreCannotSaveObjectException"),
"CSVimport/Datasynchro: Password validation failed with: ".$sStatus->GetDescription()
);
}
}
}
/**
* test $oBulk->Process with server 1 from demo datas
*
@@ -78,7 +80,8 @@ class BulkChangeTest extends ItopDataTestCase
* @param $aExtKeys
* @param $aReconcilKeys
*/
public function testBulkChangeWithoutInitData($aCSVData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, array $aResultHTML = null) {
public function testBulkChangeWithoutInitData($aCSVData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, array $aResultHTML = null)
{
$this->debug("aReconcilKeys:".$aReconcilKeys[0]);
$oBulk = new BulkChange(
"Server",
@@ -106,9 +109,9 @@ class BulkChangeTest extends ItopDataTestCase
$this->debug("i:".$i);
$this->debug('GetCLIValue:'.$oCell->GetCLIValue());
$this->debug("aResult:".$aResult[$i]);
$this->assertEquals($aResult[$i], $oCell->GetCLIValue(), "Unexpected CLI result for cell " . $i);
$this->assertEquals($aResult[$i], $oCell->GetCLIValue(), "Unexpected CLI result for cell ".$i);
if (null !== $aResultHTML) {
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue(), "Unexpected HTML result for cell " . $i);
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue(), "Unexpected HTML result for cell ".$i);
}
}
}
@@ -116,74 +119,75 @@ class BulkChangeTest extends ItopDataTestCase
}
}
public function bulkChangeWithoutInitDataProvider() {
public function bulkChangeWithoutInitDataProvider()
{
return [
"Case 3, 5 et 8 : unchanged" => [
"csvData" =>
[["Demo", "Server1", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconciliation Keys"=>
"reconciliation Keys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
],
"Case 9 : wrong date format" => [
"csvData" =>
[["Demo", "Server1", "1", "production", "<date"]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconciliation Keys"=>
"reconciliation Keys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ 0 => "Demo", "org_id" => "n/a", 1 => "Server1", 2 => "1", 3 => "production", 4 => "'<date' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[ 0 => "Demo", "org_id" => "n/a", 1 => "Server1", 2 => "1", 3 => "production", 4 => "'&lt;date' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
"Case 1 : no match" => [
"csvData" =>
[["<Bad", "Server1", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconciliation Keys"=>
"reconciliation Keys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[0 => '<Bad', "org_id" => "No match for value '<Bad'",1 => "Server1",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => '&lt;Bad', "org_id" => "No match for value &apos;&lt;Bad&apos;",1 => "Server1",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 10 : Missing mandatory value" => [
"csvData" =>
[["", "Server1", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconciliation Keys"=>
"reconciliation Keys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[0 => null, "org_id" => "Invalid value for attribute", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => null, "org_id" => "Invalid value for attribute", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 6 : Unexpected value" => [
"csvData" =>
[["Demo", "Server1", "1", "<svg onclick\"alert(1)\">", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconciliation Keys"=>
"reconciliation Keys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[
0 => "Demo",
"org_id" => "3",
@@ -193,9 +197,9 @@ class BulkChangeTest extends ItopDataTestCase
4 => "",
"id" => 1,
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling"
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[
0 => "Demo",
"org_id" => "3",
@@ -205,7 +209,7 @@ class BulkChangeTest extends ItopDataTestCase
4 => "",
"id" => 1,
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling"
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling",
],
],
];
@@ -222,21 +226,21 @@ class BulkChangeTest extends ItopDataTestCase
* @param $aExtKeys
* @param $aReconcilKeys
*/
public function testBulkChangeWithExistingData($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, $aResultHTML= null ) {
public function testBulkChangeWithExistingData($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, $aResultHTML = null)
{
//change value during the test
$db_core_transactions_enabled=MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled',false);
$db_core_transactions_enabled = MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled', false);
if (is_array($aInitData) && sizeof($aInitData) != 0) {
/** @var Server $oServer */
$oServer = $this->createObject('Server', array(
$oServer = $this->createObject('Server', [
'name' => $aInitData[1],
'status' => $aInitData[2],
'org_id' => $aInitData[0],
'purchase_date' => $aInitData[3],
));
if(array_key_exists('id', $aAttributes)) {
]);
if (array_key_exists('id', $aAttributes)) {
$iColumnForId = $aAttributes['id'];
$aCsvData[0][$iColumnForId] = $oServer->GetKey();
$aResult[$iColumnForId] = $oServer->GetKey();
@@ -253,7 +257,7 @@ class BulkChangeTest extends ItopDataTestCase
$iNBFields = count($aAttributes);
foreach ($aExtKeys as $aListFields) {
$iNBFields += count($aListFields);
$iNBFields += count($aListFields);
}
$oBulk = new BulkChange(
"Server",
@@ -279,38 +283,39 @@ class BulkChangeTest extends ItopDataTestCase
$this->debug("i:".$i);
$this->debug('GetCLIValue:'.$oCell->GetCLIValue());
$this->debug("aResult:".$aResult[$i]);
$this->assertEquals( $aResult[$i], $oCell->GetCLIValue(), "failure on " . get_class($oCell) . ' cell type for cell number ' . $i );
$this->assertEquals($aResult[$i], $oCell->GetCLIValue(), "failure on ".get_class($oCell).' cell type for cell number '.$i);
if (null !== $aResultHTML && array_key_exists($i, $aResultHTML)) {
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue(), "failure on " . get_class($oCell) . ' cell type for cell number ' . $i);
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue(), "failure on ".get_class($oCell).' cell type for cell number '.$i);
}
} else if ($i === "__ERRORS__") {
} elseif ($i === "__ERRORS__") {
$sErrors = array_key_exists("__ERRORS__", $aResult) ? $aResult["__ERRORS__"] : "";
$this->assertEquals( $sErrors, $oCell->GetDescription());
$this->assertEquals($sErrors, $oCell->GetDescription());
}
}
$this->assertEquals( $aResult[0], $aRow[0]->GetCLIValue());
$this->assertEquals($aResult[0], $aRow[0]->GetCLIValue());
if (null !== $aResultHTML) {
$this->assertEquals($aResultHTML[0], $aRow[0]->GetHTMLValue());
}
}
}
MetaModel::GetConfig()->Set('db_core_transactions_enabled',$db_core_transactions_enabled);
MetaModel::GetConfig()->Set('db_core_transactions_enabled', $db_core_transactions_enabled);
}
public function bulkChangeWithExistingDataProvider() {
public function bulkChangeWithExistingDataProvider()
{
return [
"Ambigous case on reconciliation" => [
"initData"=>
"initData" =>
["1", "Server1", "production", ""],
"csvData" =>
[[">Demo", "Server1"]],
"attributes"=>
"attributes" =>
["name" => 1],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["name"],
"expectedResult"=>
"expectedResult" =>
[
0 => ">Demo",
"org_id" => "n/a",
@@ -320,7 +325,7 @@ class BulkChangeTest extends ItopDataTestCase
"__STATUS__" => "Issue: ambiguous reconciliation",
"__ERRORS__" => "Object not found",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[
0 => "&gt;Demo",
"org_id" => "n/a",
@@ -332,17 +337,17 @@ class BulkChangeTest extends ItopDataTestCase
],
],
"Case 6 - 1 : Unexpected value (update)" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "key - will be automatically overwritten by test", ">BadValue", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
@@ -354,31 +359,31 @@ class BulkChangeTest extends ItopDataTestCase
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
"expectedResultHTML"=>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
"org_id" => "3",
1 => "&gt;ServerTest",
2 => "1",
3 => "'&gt;BadValue' is an invalid value",
4 => "",
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
"expectedResultHTML" =>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
"org_id" => "3",
1 => "&gt;ServerTest",
2 => "1",
3 => "'&gt;BadValue' is an invalid value",
4 => "",
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
],
"Case 6 - 2 : Unexpected value (update)" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "key", "<svg onclick\"alert(1)\">", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
@@ -390,7 +395,7 @@ class BulkChangeTest extends ItopDataTestCase
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
@@ -404,17 +409,17 @@ class BulkChangeTest extends ItopDataTestCase
],
],
"Case 6 - 3 : Unexpected value (creation)" => [
"initData"=>
"initData" =>
[],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "<svg onclick\"alert(1)\">", 1]],
"attributes"=>
["name" => 1, "status" => 2, 'id'=> 3],
"extKeys"=>
"attributes" =>
["name" => 1, "status" => 2, 'id' => 3],
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["name"],
"expectedResult"=>
"expectedResult" =>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
@@ -425,7 +430,7 @@ class BulkChangeTest extends ItopDataTestCase
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[
"id" => "{Id of the server created by the test}",
0 => "Demo",
@@ -438,219 +443,218 @@ class BulkChangeTest extends ItopDataTestCase
],
],
"Case 8 : unchanged name" => [
"initData"=>
"initData" =>
["1", "<svg onclick\"alert(1)\">", "production", ""],
"csvData"=>
"csvData" =>
[["Demo", "<svg onclick\"alert(1)\">", "key", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "3", 1 => '<svg onclick"alert(1)">', 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
"expectedResultHTML"=>
0 => "Demo", "org_id" => "3", 1 => '<svg onclick"alert(1)">', 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "3", 1 => '&lt;svg onclick&quot;alert(1)&quot;&gt;', 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
0 => "Demo", "org_id" => "3", 1 => '&lt;svg onclick&quot;alert(1)&quot;&gt;', 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
],
"Case 3, 5 et 8 : unchanged 2" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "3", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
"expectedResultHTML"=>
0 => "Demo", "org_id" => "3", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "3", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
0 => "Demo", "org_id" => "3", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
],
"Case 9 - 1: wrong date format" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "1", "production", "date>"]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'date>' is an invalid value", "__STATUS__" => "Issue: wrong date format"],
"expectedResultHTML"=>
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'date>' is an invalid value", "__STATUS__" => "Issue: wrong date format"],
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "n/a", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => "'date&gt;' is an invalid value", "__STATUS__" => "Issue: wrong date format"],
0 => "Demo", "org_id" => "n/a", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => "'date&gt;' is an invalid value", "__STATUS__" => "Issue: wrong date format"],
],
"Case 9 - 2: wrong date format" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "1", "production", "<svg onclick\"alert(1)\">"]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => '\'<svg onclick"alert(1)">\' is an invalid value',"__STATUS__" => "Issue: wrong date format"],
"expectedResultHTML"=>
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => '\'<svg onclick"alert(1)">\' is an invalid value',"__STATUS__" => "Issue: wrong date format"],
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "n/a", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => '\'&lt;svg onclick&quot;alert(1)&quot;&gt;\' is an invalid value',"__STATUS__" => "Issue: wrong date format"],
0 => "Demo", "org_id" => "n/a", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => '\'&lt;svg onclick&quot;alert(1)&quot;&gt;\' is an invalid value',"__STATUS__" => "Issue: wrong date format"],
],
"Case 1 - 1 : no match" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[[">Bad", ">ServerTest", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => ">Bad", "org_id" => "No match for value '>Bad'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
0 => ">Bad", "org_id" => "No match for value '>Bad'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => "&gt;Bad", "org_id" => "No match for value &apos;&gt;Bad&apos;",1 => "&gt;ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
0 => "&gt;Bad", "org_id" => "No match for value &apos;&gt;Bad&apos;",1 => "&gt;ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
],
],
"Case 1 - 2 : no match" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["<svg onclick\"alert(1)\">", ">ServerTest", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => '<svg onclick"alert(1)">', "org_id" => "No match for value '<svg onclick\"alert(1)\">'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
0 => '<svg onclick"alert(1)">', "org_id" => "No match for value '<svg onclick\"alert(1)\">'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => '&lt;svg onclick&quot;alert(1)&quot;&gt;', "org_id" => "No match for value &apos;&lt;svg onclick&quot;alert(1)&quot;&gt;&apos;",1 => "&gt;ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
0 => '&lt;svg onclick&quot;alert(1)&quot;&gt;', "org_id" => "No match for value &apos;&lt;svg onclick&quot;alert(1)&quot;&gt;&apos;",1 => "&gt;ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Object not found",
],
],
"Case 10 : Missing mandatory value" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData" =>
[["", ">ServerTest", "1", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => "", "org_id" => "Invalid value for attribute", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Null not allowed",
0 => "", "org_id" => "Invalid value for attribute", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Null not allowed",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[ "id" => "{Id of the server created by the test}",
0 => "", "org_id" => "Invalid value for attribute", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Null not allowed",
0 => "", "org_id" => "Invalid value for attribute", 1 => "&gt;ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => "Null not allowed",
],
],
"Case 0 : Date format ok but incorrect date" => [
"initData"=>
"initData" =>
["1", ">ServerTest", "production", "2020-02-01"],
"csvData"=>
"csvData" =>
[["Demo", ">ServerTest", "1", "production", "2020-20-03"]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'2020-20-03' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'2020-20-03' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
"Case 11 : Missing AttributeDateTime cell should issue an error" => [
"initData"=>
"initData" =>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
"csvData" =>
[["1"]],
"attributes"=>
"attributes" =>
["id" => 0,"purchase_date" => 1],
"extKeys"=>
"extKeys" =>
[],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ 1 => "'' is an invalid value", "id" => 1, "__STATUS__" => 'Issue: Not the expected number of columns (found: 1, expected: 2)'],
],
"Case 12 : Missing AttributeEnum cell should issue an error" => [
"initData"=>
"initData" =>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
"csvData" =>
[[ "1"]], // missing status
"attributes"=>
"attributes" =>
[ "id" => 0, "status" => 1],
"extKeys"=>
"extKeys" =>
[],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ 1 => "'' is an invalid value", "id" => 1, "__STATUS__" => 'Issue: Not the expected number of columns (found: 1, expected: 2)'],
],
"Case 13 : Missing AttributeExternalKey cell should issue an error" => [
"initData"=>
"initData" =>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
"csvData" =>
[[ "1"]], // missing org_id
"attributes"=>
"attributes" =>
[ "id" => 0],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 1]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ 1 => "'' is an invalid value", "id" => 1, "__STATUS__" => 'Issue: Not the expected number of columns (found: 1, expected: 2)'],
],
"Case 14 : Missing 1 of 2 AttributeExternalKey need 2 cells for reconciliation cell should issue an error" => [
"initData"=>
"initData" =>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
"csvData" =>
[[ "1", "Demo"]], // missing org_code
"attributes"=>
"attributes" =>
[ "id" => 0],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 1, "code" => 2]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[ 1 => 'Demo', "id" => 1, "__STATUS__" => 'Issue: Not the expected number of columns (found: 2, expected: 3)'],
],
];
}
/**
* test $oBulk->Process with new server and new organization datas
*
@@ -662,35 +666,36 @@ class BulkChangeTest extends ItopDataTestCase
* @param $aExtKeys
* @param $aReconcilKeys
*/
public function testBulkChangeWithExistingDataAndSpecificOrg($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, $aResultHTML = null) {
public function testBulkChangeWithExistingDataAndSpecificOrg($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, $aResultHTML = null)
{
//change value during the test
$db_core_transactions_enabled=MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled',false);
$db_core_transactions_enabled = MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled', false);
if (is_array($aInitData) && sizeof($aInitData) != 0) {
/** @var Server $oServer */
$oOrganisation = $this->createObject('Organization', array(
'name' => $aInitData["orgName"]
));
if ($aResult["org_id"]==="{org id of the server created by the test}"){
$oOrganisation = $this->createObject('Organization', [
'name' => $aInitData["orgName"],
]);
if ($aResult["org_id"] === "{org id of the server created by the test}") {
$aResult["org_id"] = $oOrganisation->GetKey();
if ($aResultHTML!==null){
$aResultHTML["org_id"]=$oOrganisation->GetKey();
if ($aResultHTML !== null) {
$aResultHTML["org_id"] = $oOrganisation->GetKey();
}
}
$oServer = $this->createObject('Server', array(
$oServer = $this->createObject('Server', [
'name' => $aInitData["serverName"],
'status' => $aInitData["serverStatus"],
'org_id' => $oOrganisation->GetKey(),
'purchase_date' => $aInitData["serverPurchaseDate"],
));
]);
$aCsvData[0][2] = $oServer->GetKey();
$aResult[2]=$oServer->GetKey();
if ($aResult["id"]==="{Id of the server created by the test}") {
$aResult["id"]=$oServer->GetKey();
if ($aResultHTML!==null){
$aResultHTML[2]=$oServer->GetKey();
$aResultHTML["id"]=$oServer->GetKey();
$aResult[2] = $oServer->GetKey();
if ($aResult["id"] === "{Id of the server created by the test}") {
$aResult["id"] = $oServer->GetKey();
if ($aResultHTML !== null) {
$aResultHTML[2] = $oServer->GetKey();
$aResultHTML["id"] = $oServer->GetKey();
}
}
}
@@ -720,9 +725,9 @@ class BulkChangeTest extends ItopDataTestCase
} elseif ($i === "__STATUS__") {
$sStatus = $aRow['__STATUS__'];
$this->assertEquals($aResult["__STATUS__"], $sStatus->GetDescription());
} else if ($i === "__ERRORS__") {
} elseif ($i === "__ERRORS__") {
$sErrors = array_key_exists("__ERRORS__", $aResult) ? $aResult["__ERRORS__"] : "";
$this->assertEquals( $sErrors, $oCell->GetDescription());
$this->assertEquals($sErrors, $oCell->GetDescription());
}
}
$this->assertEquals($aResult[0], $aRow[0]->GetCLIValue());
@@ -730,23 +735,24 @@ class BulkChangeTest extends ItopDataTestCase
$this->assertEquals($aResultHTML[0], $aRow[0]->GetHTMLValue());
}
}
MetaModel::GetConfig()->Set('db_core_transactions_enabled',$db_core_transactions_enabled);
MetaModel::GetConfig()->Set('db_core_transactions_enabled', $db_core_transactions_enabled);
}
public function bulkChangeWithExistingDataAndSpecificOrgProvider() {
public function bulkChangeWithExistingDataAndSpecificOrgProvider()
{
return [
"Ambigous case " => [
"initData"=>
["orgName" => "Demo", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
"initData" =>
["orgName" => "Demo", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" => ""],
"csvData" =>
[["Demo", ">Server1"]],
"attributes"=>
"attributes" =>
["name" => 1,"id" => 2],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["org_id"],
"expectedResult"=>
"expectedResult" =>
[
0 => "Demo",
"org_id" => "Invalid value for attribute",
@@ -755,7 +761,7 @@ class BulkChangeTest extends ItopDataTestCase
"__STATUS__" => "Issue: failed to reconcile",
"__ERRORS__" => "Allowed 'status' value(s): stock,implemfentation,production,obsolete",
],
"expectedResultHTML"=>
"expectedResultHTML" =>
[
0 => "Demo",
"org_id" => "Invalid value for attribute",
@@ -766,67 +772,67 @@ class BulkChangeTest extends ItopDataTestCase
],
],
"Case 3 : unchanged name" => [
"initData"=>
["orgName" => ">dodo", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
"csvData"=>
"initData" =>
["orgName" => ">dodo", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" => ""],
"csvData" =>
[[">dodo", ">ServerYO", "key will be set by the test", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[0 => ">dodo", "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => "&gt;dodo", "org_id" => "{org id of the server created by the test}", 1 => "&gt;ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
],
"Case 3 bis : unchanged name" => [
"initData"=>
["orgName" =>"<svg >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
"csvData"=>
"initData" =>
["orgName" => "<svg >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" => ""],
"csvData" =>
[["<svg >", ">ServerYO", "key", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[0 => "<svg >", "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => "&lt;svg &gt;", "org_id" => "{org id of the server created by the test}", 1 => "&gt;ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
],
"Case 3 ter : unchanged name" => [
"initData"=>
["orgName" => "<svg onclick\"alert(1)\" >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
"csvData"=>
"initData" =>
["orgName" => "<svg onclick\"alert(1)\" >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" => ""],
"csvData" =>
[["<svg onclick\"alert(1)\" >", ">ServerYO", "key", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["id"],
"expectedResult"=>
"expectedResult" =>
[0 => '<svg onclick"alert(1)" >', "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => '&lt;svg onclick&quot;alert(1)&quot; &gt;', "org_id" => "{org id of the server created by the test}", 1 => "&gt;ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
],
"Case reconciliation on external key" => [
"initData"=>
["orgName" => "<svg onclick\"alert(1)\" >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
"csvData"=>
"initData" =>
["orgName" => "<svg onclick\"alert(1)\" >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" => ""],
"csvData" =>
[["<svg onclick\"alert(1)\" >", ">ServerYO", "key", "production", ""]],
"attributes"=>
"attributes" =>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
"extKeys" =>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
"reconcilKeys" =>
["org_id", "name"],
"expectedResult"=>
"expectedResult" =>
[0 => '<svg onclick"alert(1)" >', "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
"expectedResultHTML"=>
"expectedResultHTML" =>
[0 => '&lt;svg onclick&quot;alert(1)&quot; &gt;', "org_id" => "{org id of the server created by the test}", 1 => "&gt;ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
],
];

View File

@@ -1424,7 +1424,7 @@ class DBObjectTest extends ItopDataTestCase
$iUserRequest = $this->GivenObjectInDB('UserRequest', [
'ref' => 'UR1', 'title' => 'UR1', 'description' => 'UR1', 'caller_id' => 3, 'org_id' => 3, 'service_id' => 1,
'functionalcis_list' => [
"functionalci_id:$iServer"
"functionalci_id:$iServer",
],
]);
$oUserRequest = MetaModel::GetObject('UserRequest', $iUserRequest);

View File

@@ -90,8 +90,9 @@ class DBSearchCommitTest extends ItopDataTestCase
/**
* @covers N°8511 - Enhance DBObjectSet to be able to order by id
*/
public function testDbObjectSetFetchMethodWorksWithOptimizeColumnLoadOrderedById(){
$sUID=uniqid();
public function testDbObjectSetFetchMethodWorksWithOptimizeColumnLoadOrderedById()
{
$sUID = uniqid();
$oOrg1 = $this->CreateOrganization($sUID);
$oOrg2 = $this->CreateOrganization($sUID);

View File

@@ -68,7 +68,7 @@ class ExceptionLogTest extends ItopDataTestCase
$sExpectedFile = __FILE__;
// @formatter:off
$oException = new $aExceptions[$i]("Iteration number $i");
$sExpectedLine = __LINE__-1; //Both should remain on the same line
$sExpectedLine = __LINE__ - 1; //Both should remain on the same line
// @formatter:on
$iExpectedWriteNumber = $aExpectedWriteNumber[$i];

View File

@@ -9,7 +9,6 @@
namespace Combodo\iTop\Test\UnitTest\Core;
use CMDBSource;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use DBObjectSearch;
@@ -25,7 +24,6 @@ use utils;
class OQLTest extends ItopDataTestCase
{
/**
* @doesNotPerformAssertions
*
@@ -63,244 +61,236 @@ class OQLTest extends ItopDataTestCase
public function NestedQueryProvider()
{
return array(
array("SELECT User AS U JOIN Person AS P ON U.contactid = P.id WHERE U.status='enabled' AND U.id NOT IN (SELECT User AS U JOIN Person AS P ON U.contactid=P.id JOIN URP_UserOrg AS L ON L.userid = U.id WHERE U.status='enabled' AND L.allowed_org_id = P.org_id UNION SELECT User AS U WHERE U.status='enabled' AND U.id NOT IN ( SELECT User AS U JOIN URP_UserOrg AS L ON L.userid = U.id WHERE U.status='enabled'))"),
array('SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE `UserRequest`.org_id IN (SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = \'3\'))'),
array('SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE `Organization`.`id`=`UserRequest`.`org_id`))'),
array("SELECT UserRequest AS Ur WHERE Ur.id NOT IN (SELECT UserRequest AS Ur JOIN lnkFunctionalCIToTicket AS lnk ON lnk.ticket_id = Ur.id)"),
array("SELECT Ticket AS T WHERE T. finalclass IN ('userrequest' , 'change') AND T.id NOT IN (SELECT UserRequest AS Ur JOIN lnkFunctionalCIToTicket AS lnk ON lnk.ticket_id = Ur.id UNION SELECT Change AS C JOIN lnkFunctionalCIToTicket AS lnk ON lnk.ticket_id = C.id)"),
array("SELECT PhysicalDevice WHERE status='production' AND id NOT IN (SELECT PhysicalDevice AS p JOIN lnkFunctionalCIToProviderContract AS l ON l.functionalci_id=p.id)"),
array("SELECT Team WHERE id NOT IN (SELECT Team AS t JOIN lnkPersonToTeam AS l ON l.team_id=t.id WHERE 1)"),
);
return [
["SELECT User AS U JOIN Person AS P ON U.contactid = P.id WHERE U.status='enabled' AND U.id NOT IN (SELECT User AS U JOIN Person AS P ON U.contactid=P.id JOIN URP_UserOrg AS L ON L.userid = U.id WHERE U.status='enabled' AND L.allowed_org_id = P.org_id UNION SELECT User AS U WHERE U.status='enabled' AND U.id NOT IN ( SELECT User AS U JOIN URP_UserOrg AS L ON L.userid = U.id WHERE U.status='enabled'))"],
['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE `UserRequest`.org_id IN (SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = \'3\'))'],
['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE `Organization`.`id`=`UserRequest`.`org_id`))'],
["SELECT UserRequest AS Ur WHERE Ur.id NOT IN (SELECT UserRequest AS Ur JOIN lnkFunctionalCIToTicket AS lnk ON lnk.ticket_id = Ur.id)"],
["SELECT Ticket AS T WHERE T. finalclass IN ('userrequest' , 'change') AND T.id NOT IN (SELECT UserRequest AS Ur JOIN lnkFunctionalCIToTicket AS lnk ON lnk.ticket_id = Ur.id UNION SELECT Change AS C JOIN lnkFunctionalCIToTicket AS lnk ON lnk.ticket_id = C.id)"],
["SELECT PhysicalDevice WHERE status='production' AND id NOT IN (SELECT PhysicalDevice AS p JOIN lnkFunctionalCIToProviderContract AS l ON l.functionalci_id=p.id)"],
["SELECT Team WHERE id NOT IN (SELECT Team AS t JOIN lnkPersonToTeam AS l ON l.team_id=t.id WHERE 1)"],
];
}
/**
* @dataProvider GoodQueryProvider
* @depends testOQLSetup
*
* @param $sQuery
*
* @throws \OQLException
*/
public function testGoodQueryParser($sQuery)
{
$this->debug($sQuery);
$oOql = new OqlInterpreter($sQuery);
$oQuery = $oOql->ParseQuery();
static::assertInstanceOf('OqlQuery', $oQuery);
}
/**
* @dataProvider GoodQueryProvider
* @depends testOQLSetup
*
* @param $sQuery
*
* @throws \OQLException
*/
public function testGoodQueryParser($sQuery)
{
$this->debug($sQuery);
$oOql = new OqlInterpreter($sQuery);
$oQuery = $oOql->ParseQuery();
static::assertInstanceOf('OqlQuery', $oQuery);
}
public function GoodQueryProvider()
{
return array(
array('SELECT toto'),
array('SELECT toto WHERE toto.a = 1'),
array('SELECT toto WHERE toto.a = -1'),
array('SELECT toto WHERE toto.a = (1-1)'),
array('SELECT toto WHERE toto.a = (-1+3)'),
array('SELECT toto WHERE toto.a = (3+-1)'),
array('SELECT toto WHERE toto.a = (3--1)'),
array('SELECT toto WHERE toto.a = 0xC'),
array('SELECT toto WHERE toto.a = \'AXDVFS0xCZ32\''),
array('SELECT toto WHERE toto.a = :myparameter'),
array('SELECT toto WHERE toto.a IN (:param1)'),
array('SELECT toto WHERE toto.a IN (:param1, :param2)'),
array('SELECT toto WHERE toto.a=1'),
array('SELECT toto WHERE toto.a = "1"'),
array('SELECT toto WHERE toto.a & 1'),
array('SELECT toto WHERE toto.a | 1'),
array('SELECT toto WHERE toto.a ^ 1'),
array('SELECT toto WHERE toto.a << 1'),
array('SELECT toto WHERE toto.a >> 1'),
array('SELECT toto WHERE toto.a NOT LIKE "That\'s it"'),
array('SELECT toto WHERE toto.a NOT LIKE "That\'s \\"it\\""'),
array('SELECT toto WHERE toto.a NOT LIKE \'That"s it\''),
array('SELECT toto WHERE toto.a NOT LIKE \'That\\\'s it\''),
array('SELECT toto WHERE toto.a NOT LIKE "blah \\\\ truc"'),
array('SELECT toto WHERE toto.a NOT LIKE \'blah \\\\ truc\''),
array('SELECT toto WHERE toto.a NOT LIKE "\\\\"'),
array('SELECT toto WHERE toto.a NOT LIKE "\\""'),
array('SELECT toto WHERE toto.a NOT LIKE "\\"\\\\"'),
array('SELECT toto WHERE toto.a NOT LIKE "\\\\\\""'),
array('SELECT toto WHERE toto.a NOT LIKE ""'),
array('SELECT toto WHERE toto.a NOT LIKE "blah" AND toto.b LIKE "foo"'),
array('SELECT toto WHERE toto.a = 1 AND toto.b LIKE "x" AND toto.f >= 12345'),
array('SELECT Device JOIN Site ON Device.site = Site.id'),
array('SELECT Device JOIN Site ON Device.site = Site.id JOIN Country ON Site.location = Country.id'),
array('SELECT UserRightsMatrixClassGrant WHERE UserRightsMatrixClassGrant.class = \'lnkContactRealObject\' AND UserRightsMatrixClassGrant.action = \'modify\' AND UserRightsMatrixClassGrant.login = \'Denis\''),
array('SELECT A WHERE A.col1 = \'lit1\' AND A.col2 = \'lit2\' AND A.col3 = \'lit3\''),
array('SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 = 123 AND B.col1 = \'aa\') OR (A.col3 = \'zzz\' AND B.col4 > 100)'),
array('SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 = B.col2 AND B.col1 = A.col2) OR (A.col3 = \'\' AND B.col4 > 100)'),
array('SELECT A JOIN B ON A.myB = B.id WHERE A.col1 + B.col2 * B.col1 = A.col2'),
array('SELECT A JOIN B ON A.myB = B.id WHERE A.col1 + (B.col2 * B.col1) = A.col2'),
array('SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 + B.col2) * B.col1 = A.col2'),
array('SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 & B.col2) = A.col2'),
array('SELECT Device AS D_ JOIN Site AS S_ ON D_.site = S_.id WHERE S_.country = "Francia"'),
array('SELECT A FROM A'),
array('SELECT A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT A FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT B FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT A,B FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT A, B FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT B,A FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT A, B,C FROM A JOIN B ON A.myB = B.id'),
array('SELECT C FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'),
array('SELECT A JOIN B ON A.myB BELOW B.id WHERE A.col1 = 2'),
array('SELECT A JOIN B ON B.myA BELOW A.id WHERE A.col1 = 2'),
array('SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id BELOW B.id WHERE A.col1 = 2 AND B.id = 3'),
array('SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id BELOW STRICT B.id WHERE A.col1 = 2 AND B.id = 3'),
array('SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id NOT BELOW B.id WHERE A.col1 = 2 AND B.id = 3'),
array('SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id NOT BELOW STRICT B.id WHERE A.col1 = 2 AND B.id = 3'),
array('SELECT A UNION SELECT B'),
array('SELECT A WHERE A.b = "sdf" UNION SELECT B WHERE B.a = "sfde"'),
array('SELECT A UNION SELECT B UNION SELECT C'),
array('SELECT A UNION SELECT B UNION SELECT C UNION SELECT D'),
array('SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id NOT BELOW B.id WHERE A.col1 = 2 AND B.id = 3 UNION SELECT Device JOIN Site ON Device.site = Site.id JOIN Country ON Site.location = Country.id'),
array('SELECT Person AS B WHERE B.name LIKE \'%A%\''),
array('SELECT Server WHERE name REGEXP \'dbserver[0-9]+\''),
array('SELECT Server WHERE name REGEXP \'^dbserver[0-9]+\\\\..+\\\\.[a-z]{2,3}$\''),
array('SELECT Change AS ch WHERE ch.start_date >= \'2009-12-31\' AND ch.end_date <= \'2010-01-01\''),
array('SELECT DatacenterDevice AS dev WHERE INET_ATON(dev.managementip) > INET_ATON(\'10.22.32.224\') AND INET_ATON(dev.managementip) < INET_ATON(\'10.22.32.255\')'),
array('SELECT Person AS P JOIN Organization AS Node ON P.org_id = Node.id JOIN Organization AS Root ON Node.parent_id BELOW Root.id WHERE Root.id=1'),
array('SELECT PhysicalInterface AS if JOIN DatacenterDevice AS dev ON if.connectableci_id = dev.id WHERE dev.status = \'production\' AND dev.organization_name = \'Demo\''),
array('SELECT Ticket AS t WHERE t.agent_id = :current_contact_id'),
array('SELECT Person AS p JOIN UserRequest AS u ON u.agent_id = p.id WHERE u.status != \'closed\''),
array('SELECT Contract AS c WHERE c.end_date > NOW() AND c.end_date < DATE_ADD(NOW(), INTERVAL 30 DAY)'),
array('SELECT UserRequest AS u WHERE u.start_date < DATE_SUB(NOW(), INTERVAL 60 MINUTE) AND u.status = \'new\''),
array('SELECT UserRequest AS u WHERE u.close_date > DATE_ADD(u.start_date, INTERVAL 8 HOUR)'),
array('SELECT Ticket WHERE tagfield MATCHES \'salad\''),
);
}
public function GoodQueryProvider()
{
return [
['SELECT toto'],
['SELECT toto WHERE toto.a = 1'],
['SELECT toto WHERE toto.a = -1'],
['SELECT toto WHERE toto.a = (1-1)'],
['SELECT toto WHERE toto.a = (-1+3)'],
['SELECT toto WHERE toto.a = (3+-1)'],
['SELECT toto WHERE toto.a = (3--1)'],
['SELECT toto WHERE toto.a = 0xC'],
['SELECT toto WHERE toto.a = \'AXDVFS0xCZ32\''],
['SELECT toto WHERE toto.a = :myparameter'],
['SELECT toto WHERE toto.a IN (:param1)'],
['SELECT toto WHERE toto.a IN (:param1, :param2)'],
['SELECT toto WHERE toto.a=1'],
['SELECT toto WHERE toto.a = "1"'],
['SELECT toto WHERE toto.a & 1'],
['SELECT toto WHERE toto.a | 1'],
['SELECT toto WHERE toto.a ^ 1'],
['SELECT toto WHERE toto.a << 1'],
['SELECT toto WHERE toto.a >> 1'],
['SELECT toto WHERE toto.a NOT LIKE "That\'s it"'],
['SELECT toto WHERE toto.a NOT LIKE "That\'s \\"it\\""'],
['SELECT toto WHERE toto.a NOT LIKE \'That"s it\''],
['SELECT toto WHERE toto.a NOT LIKE \'That\\\'s it\''],
['SELECT toto WHERE toto.a NOT LIKE "blah \\\\ truc"'],
['SELECT toto WHERE toto.a NOT LIKE \'blah \\\\ truc\''],
['SELECT toto WHERE toto.a NOT LIKE "\\\\"'],
['SELECT toto WHERE toto.a NOT LIKE "\\""'],
['SELECT toto WHERE toto.a NOT LIKE "\\"\\\\"'],
['SELECT toto WHERE toto.a NOT LIKE "\\\\\\""'],
['SELECT toto WHERE toto.a NOT LIKE ""'],
['SELECT toto WHERE toto.a NOT LIKE "blah" AND toto.b LIKE "foo"'],
['SELECT toto WHERE toto.a = 1 AND toto.b LIKE "x" AND toto.f >= 12345'],
['SELECT Device JOIN Site ON Device.site = Site.id'],
['SELECT Device JOIN Site ON Device.site = Site.id JOIN Country ON Site.location = Country.id'],
['SELECT UserRightsMatrixClassGrant WHERE UserRightsMatrixClassGrant.class = \'lnkContactRealObject\' AND UserRightsMatrixClassGrant.action = \'modify\' AND UserRightsMatrixClassGrant.login = \'Denis\''],
['SELECT A WHERE A.col1 = \'lit1\' AND A.col2 = \'lit2\' AND A.col3 = \'lit3\''],
['SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 = 123 AND B.col1 = \'aa\') OR (A.col3 = \'zzz\' AND B.col4 > 100)'],
['SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 = B.col2 AND B.col1 = A.col2) OR (A.col3 = \'\' AND B.col4 > 100)'],
['SELECT A JOIN B ON A.myB = B.id WHERE A.col1 + B.col2 * B.col1 = A.col2'],
['SELECT A JOIN B ON A.myB = B.id WHERE A.col1 + (B.col2 * B.col1) = A.col2'],
['SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 + B.col2) * B.col1 = A.col2'],
['SELECT A JOIN B ON A.myB = B.id WHERE (A.col1 & B.col2) = A.col2'],
['SELECT Device AS D_ JOIN Site AS S_ ON D_.site = S_.id WHERE S_.country = "Francia"'],
['SELECT A FROM A'],
['SELECT A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT A FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT B FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT A,B FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT A, B FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT B,A FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT A, B,C FROM A JOIN B ON A.myB = B.id'],
['SELECT C FROM A JOIN B ON A.myB = B.id WHERE A.col1 = 2'],
['SELECT A JOIN B ON A.myB BELOW B.id WHERE A.col1 = 2'],
['SELECT A JOIN B ON B.myA BELOW A.id WHERE A.col1 = 2'],
['SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id BELOW B.id WHERE A.col1 = 2 AND B.id = 3'],
['SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id BELOW STRICT B.id WHERE A.col1 = 2 AND B.id = 3'],
['SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id NOT BELOW B.id WHERE A.col1 = 2 AND B.id = 3'],
['SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id NOT BELOW STRICT B.id WHERE A.col1 = 2 AND B.id = 3'],
['SELECT A UNION SELECT B'],
['SELECT A WHERE A.b = "sdf" UNION SELECT B WHERE B.a = "sfde"'],
['SELECT A UNION SELECT B UNION SELECT C'],
['SELECT A UNION SELECT B UNION SELECT C UNION SELECT D'],
['SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id NOT BELOW B.id WHERE A.col1 = 2 AND B.id = 3 UNION SELECT Device JOIN Site ON Device.site = Site.id JOIN Country ON Site.location = Country.id'],
['SELECT Person AS B WHERE B.name LIKE \'%A%\''],
['SELECT Server WHERE name REGEXP \'dbserver[0-9]+\''],
['SELECT Server WHERE name REGEXP \'^dbserver[0-9]+\\\\..+\\\\.[a-z]{2,3}$\''],
['SELECT Change AS ch WHERE ch.start_date >= \'2009-12-31\' AND ch.end_date <= \'2010-01-01\''],
['SELECT DatacenterDevice AS dev WHERE INET_ATON(dev.managementip) > INET_ATON(\'10.22.32.224\') AND INET_ATON(dev.managementip) < INET_ATON(\'10.22.32.255\')'],
['SELECT Person AS P JOIN Organization AS Node ON P.org_id = Node.id JOIN Organization AS Root ON Node.parent_id BELOW Root.id WHERE Root.id=1'],
['SELECT PhysicalInterface AS if JOIN DatacenterDevice AS dev ON if.connectableci_id = dev.id WHERE dev.status = \'production\' AND dev.organization_name = \'Demo\''],
['SELECT Ticket AS t WHERE t.agent_id = :current_contact_id'],
['SELECT Person AS p JOIN UserRequest AS u ON u.agent_id = p.id WHERE u.status != \'closed\''],
['SELECT Contract AS c WHERE c.end_date > NOW() AND c.end_date < DATE_ADD(NOW(), INTERVAL 30 DAY)'],
['SELECT UserRequest AS u WHERE u.start_date < DATE_SUB(NOW(), INTERVAL 60 MINUTE) AND u.status = \'new\''],
['SELECT UserRequest AS u WHERE u.close_date > DATE_ADD(u.start_date, INTERVAL 8 HOUR)'],
['SELECT Ticket WHERE tagfield MATCHES \'salad\''],
];
}
/**
* @dataProvider BadQueryProvider
* @depends testOQLSetup
*
* @param $sQuery
* @param $sExpectedExceptionClass
*
*/
public function testBadQueryParser($sQuery, $sExpectedExceptionClass)
{
$this->debug($sQuery);
$oOql = new OqlInterpreter($sQuery);
$sExceptionClass = '';
try
{
$oOql->ParseQuery();
}
catch (Exception $e)
{
$sExceptionClass = get_class($e);
}
/**
* @dataProvider BadQueryProvider
* @depends testOQLSetup
*
* @param $sQuery
* @param $sExpectedExceptionClass
*
*/
public function testBadQueryParser($sQuery, $sExpectedExceptionClass)
{
$this->debug($sQuery);
$oOql = new OqlInterpreter($sQuery);
$sExceptionClass = '';
try {
$oOql->ParseQuery();
} catch (Exception $e) {
$sExceptionClass = get_class($e);
}
static::assertEquals($sExpectedExceptionClass, $sExceptionClass);
}
static::assertEquals($sExpectedExceptionClass, $sExceptionClass);
}
public function BadQueryProvider()
{
return array(
array('SELECT toto WHERE toto.a = (3++1)', 'OQLParserSyntaxErrorException'),
array('SELECT toto WHHHERE toto.a = "1"', 'OQLParserSyntaxErrorException'),
array('SELECT toto WHERE toto.a == "1"', 'OQLParserSyntaxErrorException'),
array('SELECT toto WHERE toto.a % 1', 'Exception'),
array('SELECT toto WHERE toto.a like \'arg\'', 'OQLParserSyntaxErrorException'),
array('SELECT toto WHERE toto.a NOT LIKE "That\'s "it""', 'OQLParserSyntaxErrorException'),
array('SELECT toto WHERE toto.a NOT LIKE \'That\'s it\'', 'OQLParserSyntaxErrorException'),
array('SELECT toto WHERE toto.a NOT LIKE "blah \\ truc"', 'Exception'),
array('SELECT toto WHERE toto.a NOT LIKE \'blah \\ truc\'', 'Exception'),
array('SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id = B.id WHERE A.col1 BELOW 2 AND B.id = 3', 'OQLParserSyntaxErrorException'),
);
}
public function BadQueryProvider()
{
return [
['SELECT toto WHERE toto.a = (3++1)', 'OQLParserSyntaxErrorException'],
['SELECT toto WHHHERE toto.a = "1"', 'OQLParserSyntaxErrorException'],
['SELECT toto WHERE toto.a == "1"', 'OQLParserSyntaxErrorException'],
['SELECT toto WHERE toto.a % 1', 'Exception'],
['SELECT toto WHERE toto.a like \'arg\'', 'OQLParserSyntaxErrorException'],
['SELECT toto WHERE toto.a NOT LIKE "That\'s "it""', 'OQLParserSyntaxErrorException'],
['SELECT toto WHERE toto.a NOT LIKE \'That\'s it\'', 'OQLParserSyntaxErrorException'],
['SELECT toto WHERE toto.a NOT LIKE "blah \\ truc"', 'Exception'],
['SELECT toto WHERE toto.a NOT LIKE \'blah \\ truc\'', 'Exception'],
['SELECT A JOIN B ON A.myB = B.id JOIN C ON C.parent_id = B.id WHERE A.col1 BELOW 2 AND B.id = 3', 'OQLParserSyntaxErrorException'],
];
}
/**
* Needs actual datamodel
* @depends testOQLSetup
*
* @dataProvider QueryNormalizationProvider
*
* @param $sQuery
* @param $sExpectedExceptionClass
*
*/
public function testQueryNormalization($sQuery, $sExpectedExceptionClass)
{
$this->debug($sQuery);
$sExceptionClass = '';
try
{
$oSearch = DBObjectSearch::FromOQL($sQuery);
static::assertInstanceOf('DBObjectSearch', $oSearch);
}
catch (Exception $e)
{
$sExceptionClass = get_class($e);
}
/**
* Needs actual datamodel
* @depends testOQLSetup
*
* @dataProvider QueryNormalizationProvider
*
* @param $sQuery
* @param $sExpectedExceptionClass
*
*/
public function testQueryNormalization($sQuery, $sExpectedExceptionClass)
{
$this->debug($sQuery);
$sExceptionClass = '';
try {
$oSearch = DBObjectSearch::FromOQL($sQuery);
static::assertInstanceOf('DBObjectSearch', $oSearch);
} catch (Exception $e) {
$sExceptionClass = get_class($e);
}
static::assertEquals($sExpectedExceptionClass, $sExceptionClass);
}
static::assertEquals($sExpectedExceptionClass, $sExceptionClass);
}
public function QueryNormalizationProvider()
{
return [
['SELECT Contact', ''],
['SELECT Contact WHERE nom_de_famille = "foo"', 'OqlNormalizeException'],
['SELECT Contact AS c WHERE name = "foo"', ''],
['SELECT Contact AS c WHERE nom_de_famille = "foo"', 'OqlNormalizeException'],
['SELECT Contact AS c WHERE c.name = "foo"', ''],
['SELECT Contact AS c WHERE Contact.name = "foo"', 'OqlNormalizeException'],
['SELECT Contact AS c WHERE x.name = "foo"', 'OqlNormalizeException'],
public function QueryNormalizationProvider()
{
return array(
array('SELECT Contact', ''),
array('SELECT Contact WHERE nom_de_famille = "foo"', 'OqlNormalizeException'),
array('SELECT Contact AS c WHERE name = "foo"', ''),
array('SELECT Contact AS c WHERE nom_de_famille = "foo"', 'OqlNormalizeException'),
array('SELECT Contact AS c WHERE c.name = "foo"', ''),
array('SELECT Contact AS c WHERE Contact.name = "foo"', 'OqlNormalizeException'),
array('SELECT Contact AS c WHERE x.name = "foo"', 'OqlNormalizeException'),
['SELECT Organization AS child JOIN Organization AS root ON child.parent_id BELOW root.id', ''],
['SELECT Organization AS root JOIN Organization AS child ON child.parent_id BELOW root.id', ''],
array('SELECT Organization AS child JOIN Organization AS root ON child.parent_id BELOW root.id', ''),
array('SELECT Organization AS root JOIN Organization AS child ON child.parent_id BELOW root.id', ''),
['SELECT RelationProfessionnelle', 'UnknownClassOqlException'],
['SELECT RelationProfessionnelle AS c WHERE name = "foo"', 'UnknownClassOqlException'],
array('SELECT RelationProfessionnelle', 'UnknownClassOqlException'),
array('SELECT RelationProfessionnelle AS c WHERE name = "foo"', 'UnknownClassOqlException'),
// The first query is the base query altered only in one place in the subsequent queries
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE p.name LIKE "foo"', ''],
['SELECT Person AS p JOIN lnkXXXXXXXXXXXX AS lnk ON lnk.person_id = p.id WHERE p.name LIKE "foo"', 'UnknownClassOqlException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON p.person_id = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON person_id = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.role = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.team_id = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id BELOW p.id WHERE p.name LIKE "bar"', ''],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.org_id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON p.id = lnk.person_id WHERE p.name LIKE "foo"', 'OqlNormalizeException'], // inverted the JOIN spec
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE name LIKE "foo"', ''],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE x.name LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE p.eman LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE eman LIKE "foo"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE id = 1', 'OqlNormalizeException'],
['SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON p.id = lnk.person_id WHERE p.name LIKE "foo"', 'OqlNormalizeException'],
// The first query is the base query altered only in one place in the subsequent queries
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE p.name LIKE "foo"', ''),
array('SELECT Person AS p JOIN lnkXXXXXXXXXXXX AS lnk ON lnk.person_id = p.id WHERE p.name LIKE "foo"', 'UnknownClassOqlException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON p.person_id = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON person_id = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.role = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.team_id = p.id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id BELOW p.id WHERE p.name LIKE "bar"', ''),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.org_id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON p.id = lnk.person_id WHERE p.name LIKE "foo"', 'OqlNormalizeException'), // inverted the JOIN spec
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE name LIKE "foo"', ''),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE x.name LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE p.eman LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE eman LIKE "foo"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON lnk.person_id = p.id WHERE id = 1', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN lnkPersonToTeam AS lnk ON p.id = lnk.person_id WHERE p.name LIKE "foo"', 'OqlNormalizeException'),
['SELECT Person AS p JOIN Organization AS o ON p.org_id = o.id WHERE p.name LIKE "foo" AND o.name LIKE "land"', ''],
['SELECT Person AS p JOIN Organization AS o ON p.location_id = o.id WHERE p.name LIKE "foo" AND o.name LIKE "land"', 'OqlNormalizeException'],
['SELECT Person AS p JOIN Organization AS o ON p.name = o.id WHERE p.name LIKE "foo" AND o.name LIKE "land"', 'OqlNormalizeException'],
array('SELECT Person AS p JOIN Organization AS o ON p.org_id = o.id WHERE p.name LIKE "foo" AND o.name LIKE "land"', ''),
array('SELECT Person AS p JOIN Organization AS o ON p.location_id = o.id WHERE p.name LIKE "foo" AND o.name LIKE "land"', 'OqlNormalizeException'),
array('SELECT Person AS p JOIN Organization AS o ON p.name = o.id WHERE p.name LIKE "foo" AND o.name LIKE "land"', 'OqlNormalizeException'),
['SELECT Person AS p JOIN Organization AS o ON p.org_id = o.id JOIN Person AS p ON p.org_id = o.id', 'OqlNormalizeException'],
['SELECT Person JOIN Organization AS o ON Person.org_id = o.id JOIN Person ON Person.org_id = o.id', 'OqlNormalizeException'],
array('SELECT Person AS p JOIN Organization AS o ON p.org_id = o.id JOIN Person AS p ON p.org_id = o.id', 'OqlNormalizeException'),
array('SELECT Person JOIN Organization AS o ON Person.org_id = o.id JOIN Person ON Person.org_id = o.id', 'OqlNormalizeException'),
['SELECT Person AS p JOIN Location AS l ON p.location_id = l.id', ''],
['SELECT Person AS p JOIN Location AS l ON p.location_id BELOW l.id', 'OqlNormalizeException'],
array('SELECT Person AS p JOIN Location AS l ON p.location_id = l.id', ''),
array('SELECT Person AS p JOIN Location AS l ON p.location_id BELOW l.id', 'OqlNormalizeException'),
array('SELECT Person FROM Person JOIN Location ON Person.location_id = Location.id', ''),
array('SELECT p FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''),
array('SELECT l FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''),
array('SELECT l, p FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''),
array('SELECT p, l FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''),
array('SELECT foo FROM Person AS p JOIN Location AS l ON p.location_id = l.id', 'OqlNormalizeException'),
array('SELECT p, foo FROM Person AS p JOIN Location AS l ON p.location_id = l.id', 'OqlNormalizeException'),
// Joins based on AttributeObjectKey
//
array('SELECT Attachment AS a JOIN UserRequest AS r ON a.item_id = r.id', ''),
array('SELECT UserRequest AS r JOIN Attachment AS a ON a.item_id = r.id', ''),
);
}
['SELECT Person FROM Person JOIN Location ON Person.location_id = Location.id', ''],
['SELECT p FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''],
['SELECT l FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''],
['SELECT l, p FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''],
['SELECT p, l FROM Person AS p JOIN Location AS l ON p.location_id = l.id', ''],
['SELECT foo FROM Person AS p JOIN Location AS l ON p.location_id = l.id', 'OqlNormalizeException'],
['SELECT p, foo FROM Person AS p JOIN Location AS l ON p.location_id = l.id', 'OqlNormalizeException'],
// Joins based on AttributeObjectKey
//
['SELECT Attachment AS a JOIN UserRequest AS r ON a.item_id = r.id', ''],
['SELECT UserRequest AS r JOIN Attachment AS a ON a.item_id = r.id', ''],
];
}
/**
* @depends testOQLSetup
@@ -331,7 +321,7 @@ class OQLTest extends ItopDataTestCase
public function OQLIntersectProvider()
{
return array(
return [
// Wrong result:
/*
SELECT `SSC`
@@ -349,17 +339,17 @@ class OQLTest extends ItopDataTestCase
// "SELECT ServiceSubcategory AS ssc JOIN Service AS s ON ssc.service_id=s.id JOIN lnkCustomerContractToService AS l1 ON l1.service_id=s.id JOIN CustomerContract AS cc ON l1.customercontract_id=cc.id WHERE cc.org_id = :current_contact->org_id AND ssc.status != 'obsolete'",
// "SELECT `SSC` FROM ServiceSubcategory AS `SSC` JOIN Service AS `S` ON `SSC`.service_id = `S`.id JOIN lnkCustomerContractToService AS `l11` ON `l11`.service_id = `S`.id JOIN CustomerContract AS `cc` ON `l11`.customercontract_id = `cc`.id JOIN lnkGRTypeToServiceSubcategory AS `l1` ON `l1`.servicesubcategory_id = `SSC`.id JOIN GRType AS `GRT` ON `l1`.grtype_id = `GRT`.id WHERE ((`GRT`.`id` = :grtype_id) AND ((`cc`.`org_id` = :current_contact->org_id) AND (`SSC`.`status` != 'obsolete')))"
// ),
'Person' => array(
'Person' => [
"SELECT P FROM Person AS P JOIN lnkPersonToTeam AS l1 ON l1.person_id = P.id JOIN Team AS T ON l1.team_id = T.id WHERE T.id = 3",
"SELECT p FROM Person AS p JOIN Person AS mgr ON p.manager_id = mgr.id JOIN lnkContactToTicket AS l1 ON l1.contact_id = mgr.id JOIN Ticket AS T ON l1.ticket_id = T.id WHERE T.id = 4 AND p.id = 3",
"SELECT `P` FROM Person AS `P` JOIN Person AS `mgr` ON `P`.manager_id = `mgr`.id JOIN lnkContactToTicket AS `l11` ON `l11`.contact_id = `mgr`.id JOIN Ticket AS `T1` ON `l11`.ticket_id = `T1`.id JOIN lnkPersonToTeam AS `l1` ON `l1`.person_id = `P`.id JOIN Team AS `T` ON `l1`.team_id = `T`.id WHERE ((`T`.`id` = 3) AND ((`T1`.`id` = 4) AND (`P`.`id` = 3)))"
),
'Person2' => array(
"SELECT `P` FROM Person AS `P` JOIN Person AS `mgr` ON `P`.manager_id = `mgr`.id JOIN lnkContactToTicket AS `l11` ON `l11`.contact_id = `mgr`.id JOIN Ticket AS `T1` ON `l11`.ticket_id = `T1`.id JOIN lnkPersonToTeam AS `l1` ON `l1`.person_id = `P`.id JOIN Team AS `T` ON `l1`.team_id = `T`.id WHERE ((`T`.`id` = 3) AND ((`T1`.`id` = 4) AND (`P`.`id` = 3)))",
],
'Person2' => [
"SELECT P FROM Person AS P JOIN lnkPersonToTeam AS l1 ON l1.person_id = P.id JOIN Team AS T ON l1.team_id = T.id JOIN Person AS MGR ON P.manager_id = MGR.id WHERE T.id = 3",
"SELECT p FROM Person AS p JOIN Person AS mgr ON p.manager_id = mgr.id JOIN lnkContactToTicket AS l1 ON l1.contact_id = mgr.id JOIN Ticket AS T ON l1.ticket_id = T.id WHERE T.id = 4 AND p.id = 3",
"SELECT `P` FROM Person AS `P` JOIN Person AS `MGR` ON `P`.manager_id = `MGR`.id JOIN lnkContactToTicket AS `l11` ON `l11`.contact_id = `MGR`.id JOIN Ticket AS `T1` ON `l11`.ticket_id = `T1`.id JOIN lnkPersonToTeam AS `l1` ON `l1`.person_id = `P`.id JOIN Team AS `T` ON `l1`.team_id = `T`.id WHERE ((`T`.`id` = 3) AND ((`T1`.`id` = 4) AND (`P`.`id` = 3)))"
),
);
"SELECT `P` FROM Person AS `P` JOIN Person AS `MGR` ON `P`.manager_id = `MGR`.id JOIN lnkContactToTicket AS `l11` ON `l11`.contact_id = `MGR`.id JOIN Ticket AS `T1` ON `l11`.ticket_id = `T1`.id JOIN lnkPersonToTeam AS `l1` ON `l1`.person_id = `P`.id JOIN Team AS `T` ON `l1`.team_id = `T`.id WHERE ((`T`.`id` = 3) AND ((`T1`.`id` = 4) AND (`P`.`id` = 3)))",
],
];
}
/**
@@ -370,13 +360,10 @@ class OQLTest extends ItopDataTestCase
public function testMakeSelectQuery($sOQL, $sExpectedExceptionClass = '')
{
$sExceptionClass = '';
try
{
try {
$oSearch = DBSearch::FromOQL($sOQL);
CMDBSource::TestQuery($oSearch->MakeSelectQuery());
}
catch (Exception $e)
{
} catch (Exception $e) {
$this->debug($e->getMessage());
$sExceptionClass = get_class($e);
}
@@ -386,22 +373,21 @@ class OQLTest extends ItopDataTestCase
public function MakeSelectQueryProvider()
{
return array(
array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id JOIN Organization AS `Organization` ON `P`.org_id = `Organization`.id WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = `Toto`.`org_id`)))", 'OqlNormalizeException'),
array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id JOIN Organization AS `Organization` ON `P`.org_id = `Organization`.id WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = `UserRequest`.`org_id`)))"),
array("SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE ((`U`.`status` = 'enabled') AND (`L`.`allowed_org_id` = `P`.`org_id`)) UNION SELECT `U` FROM User AS `U` WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE (`U`.`status` = 'enabled')))))))"),
array("SELECT `Ur` FROM UserRequest AS `Ur` WHERE (`Ur`.`id` NOT IN (SELECT `Ur` FROM UserRequest AS `Ur` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `Ur`.id WHERE 1))"),
array("SELECT `T` FROM Ticket AS `T` WHERE ((`T`.`finalclass` IN ('userrequest', 'change')) AND (`T`.`id` NOT IN (SELECT `Ur` FROM UserRequest AS `Ur` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `Ur`.id WHERE 1 UNION SELECT `C` FROM Change AS `C` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `C`.id WHERE 1)))"),
array("SELECT `PhysicalDevice` FROM PhysicalDevice AS `PhysicalDevice` WHERE ((`PhysicalDevice`.`status` = 'production') AND (`PhysicalDevice`.`id` NOT IN (SELECT `p` FROM PhysicalDevice AS `p` JOIN lnkFunctionalCIToProviderContract AS `l` ON `l`.functionalci_id = `p`.id WHERE 1)))"),
array("SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE ((`U1`.`status` = 'enabled') AND (`L`.`allowed_org_id` = `P`.`org_id`)) UNION SELECT `U` FROM User AS `U` WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE (`U`.`status` = 'enabled')))))))", "OqlNormalizeException"),
array("SELECT Team WHERE id NOT IN (SELECT Team AS t JOIN lnkPersonToTeam AS l ON l.team_id=t.id WHERE 1)"),
array("SELECT UserRequest WHERE id NOT IN (SELECT UserRequest AS u JOIN lnkFunctionalCIToTicket AS l ON l.ticket_id=u.id JOIN PhysicalDevice AS f ON l.functionalci_id=f.id WHERE f.status='production')"),
array("SELECT UserRequest WHERE id NOT IN (SELECT UserRequest AS u JOIN lnkFunctionalCIToTicket AS l ON l.ticket_id=u.id JOIN PhysicalDevice AS f ON l.functionalci_id=f.id WHERE f.status='production' UNION SELECT UserRequest AS u JOIN lnkFunctionalCIToTicket AS l ON l.ticket_id=u.id JOIN ApplicationSolution AS f ON l.functionalci_id=f.id WHERE f.status='active')"),
array("SELECT Person WHERE status='active' AND id NOT IN (SELECT Person AS p JOIN User AS u ON u.contactid=p.id WHERE u.status='enabled')"),
);
return [
["SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id JOIN Organization AS `Organization` ON `P`.org_id = `Organization`.id WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = `Toto`.`org_id`)))", 'OqlNormalizeException'],
["SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id JOIN Organization AS `Organization` ON `P`.org_id = `Organization`.id WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = `UserRequest`.`org_id`)))"],
["SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE ((`U`.`status` = 'enabled') AND (`L`.`allowed_org_id` = `P`.`org_id`)) UNION SELECT `U` FROM User AS `U` WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE (`U`.`status` = 'enabled')))))))"],
["SELECT `Ur` FROM UserRequest AS `Ur` WHERE (`Ur`.`id` NOT IN (SELECT `Ur` FROM UserRequest AS `Ur` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `Ur`.id WHERE 1))"],
["SELECT `T` FROM Ticket AS `T` WHERE ((`T`.`finalclass` IN ('userrequest', 'change')) AND (`T`.`id` NOT IN (SELECT `Ur` FROM UserRequest AS `Ur` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `Ur`.id WHERE 1 UNION SELECT `C` FROM Change AS `C` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `C`.id WHERE 1)))"],
["SELECT `PhysicalDevice` FROM PhysicalDevice AS `PhysicalDevice` WHERE ((`PhysicalDevice`.`status` = 'production') AND (`PhysicalDevice`.`id` NOT IN (SELECT `p` FROM PhysicalDevice AS `p` JOIN lnkFunctionalCIToProviderContract AS `l` ON `l`.functionalci_id = `p`.id WHERE 1)))"],
["SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE ((`U1`.`status` = 'enabled') AND (`L`.`allowed_org_id` = `P`.`org_id`)) UNION SELECT `U` FROM User AS `U` WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE (`U`.`status` = 'enabled')))))))", "OqlNormalizeException"],
["SELECT Team WHERE id NOT IN (SELECT Team AS t JOIN lnkPersonToTeam AS l ON l.team_id=t.id WHERE 1)"],
["SELECT UserRequest WHERE id NOT IN (SELECT UserRequest AS u JOIN lnkFunctionalCIToTicket AS l ON l.ticket_id=u.id JOIN PhysicalDevice AS f ON l.functionalci_id=f.id WHERE f.status='production')"],
["SELECT UserRequest WHERE id NOT IN (SELECT UserRequest AS u JOIN lnkFunctionalCIToTicket AS l ON l.ticket_id=u.id JOIN PhysicalDevice AS f ON l.functionalci_id=f.id WHERE f.status='production' UNION SELECT UserRequest AS u JOIN lnkFunctionalCIToTicket AS l ON l.ticket_id=u.id JOIN ApplicationSolution AS f ON l.functionalci_id=f.id WHERE f.status='active')"],
["SELECT Person WHERE status='active' AND id NOT IN (SELECT Person AS p JOIN User AS u ON u.contactid=p.id WHERE u.status='enabled')"],
];
}
/**
* @dataProvider GetOQLClassTreeProvider
* @param $sOQL
@@ -410,13 +396,11 @@ class OQLTest extends ItopDataTestCase
public function testGetOQLClassTree($sOQL, $sExpectedOQL)
{
$oFilter = DBSearch::FromOQL($sOQL);
$aCountAttToLoad = array();
$aCountAttToLoad = [];
$sMainClass = null;
foreach ($oFilter->GetSelectedClasses() as $sClassAlias => $sClass)
{
$aCountAttToLoad[$sClassAlias] = array();
if (empty($sMainClass))
{
foreach ($oFilter->GetSelectedClasses() as $sClassAlias => $sClass) {
$aCountAttToLoad[$sClassAlias] = [];
if (empty($sMainClass)) {
$sMainClass = $sClass;
}
}
@@ -462,10 +446,10 @@ class OQLTest extends ItopDataTestCase
{
$oFilter = DBSearch::FromOQL($sOQL);
// Avoid adding all the fields for counts or "group by" requests
$aCountAttToLoad = array();
$aCountAttToLoad = [];
$sMainClass = null;
foreach ($oFilter->GetSelectedClasses() as $sClassAlias => $sClass) {
$aCountAttToLoad[$sClassAlias] = array();
$aCountAttToLoad[$sClassAlias] = [];
if (empty($sMainClass)) {
$sMainClass = $sClass;
}

View File

@@ -140,8 +140,6 @@ class ormDocumentTest extends ItopDataTestCase
];
}
public function testResizeImageToFitShouldResizeImageWhenImageIsTooBig()
{
$sImageData = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAoAAAAICAIAAABPmPnhAAAAe0lEQVQI132OMQoCMRRE3/9Z3M126V0kB9BCvICnziXs7QIWlttqpWMRFQT1VcMbGMb4xPoQ18uWL4eTxxglSaq1Au8OwM1TSi3nnLGnzxKA4fM8N1VKQVyPZ6Br6s4Xhj7st9OwcNy61yUsGEK3Nmu+mUawcbfiN85fHsBoHdXt5HATAAAAAElFTkSuQmCC');
@@ -159,9 +157,9 @@ class ormDocumentTest extends ItopDataTestCase
'height' => $aRealDimensions[1],
];
$this->assertNotSame( $oDoc, $oResult, 'ResizeImageToFit should return a new object when there have been some modifications');
$this->assertIsArray( $aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the new image when there are no issues');
$this->assertEquals( $aDimensions, $aActualDimensions, 'The returned dimensions should match the real dimensions of the image');
$this->assertNotSame($oDoc, $oResult, 'ResizeImageToFit should return a new object when there have been some modifications');
$this->assertIsArray($aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the new image when there are no issues');
$this->assertEquals($aDimensions, $aActualDimensions, 'The returned dimensions should match the real dimensions of the image');
$this->assertLessThanOrEqual($iMawWidth, $aActualDimensions['width'], 'The new width should be less than or equal to max width');
$this->assertLessThanOrEqual($iMaxHeight, $aActualDimensions['height'], 'The new height should be less than or equal to max height');
}
@@ -177,8 +175,8 @@ class ormDocumentTest extends ItopDataTestCase
$oResult = $oDoc->ResizeImageToFit($iMawWidth, $iMaxHeight, $aDimensions);
$this->assertSame( $oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertIsArray( $aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the image when there are no issues');
$this->assertSame($oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertIsArray($aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the image when there are no issues');
}
public function testResizeImageToFitShouldDoNothingWhenItCannotReadTheImage()
@@ -192,8 +190,8 @@ class ormDocumentTest extends ItopDataTestCase
$oResult = $oDoc->ResizeImageToFit($iMawWidth, $iMaxHeight, $aDimensions);
$this->assertSame( $oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertNull( $aDimensions, 'ResizeImageToFit should fill aDimension with null when there are issues');
$this->assertSame($oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertNull($aDimensions, 'ResizeImageToFit should fill aDimension with null when there are issues');
}
public function testResizeImageToFitShouldDoNothingWhenItDoesNotHandleTheMimeType()
@@ -207,8 +205,8 @@ class ormDocumentTest extends ItopDataTestCase
$oResult = $oDoc->ResizeImageToFit($iMawWidth, $iMaxHeight, $aDimensions);
$this->assertSame( $oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertNull( $aDimensions, 'ResizeImageToFit should fill aDimension with null when there are issues');
$this->assertSame($oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertNull($aDimensions, 'ResizeImageToFit should fill aDimension with null when there are issues');
}
public function testResizeImageToFitShouldNotResizeWhenMaximumIs0()
@@ -222,8 +220,8 @@ class ormDocumentTest extends ItopDataTestCase
$oResult = $oDoc->ResizeImageToFit($iMawWidth, $iMaxHeight, $aDimensions);
$this->assertSame( $oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertIsArray( $aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the image when there are no issues');
$this->assertSame($oDoc, $oResult, 'ResizeImageToFit should return the same object when there have been no modifications');
$this->assertIsArray($aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the image when there are no issues');
}
public function testResizeImageToFitShouldIgnoreMaximum0Axis()
@@ -243,9 +241,9 @@ class ormDocumentTest extends ItopDataTestCase
'height' => $aRealDimensions[1],
];
$this->assertNotSame( $oDoc, $oResult, 'ResizeImageToFit should return a new object when there have been some modifications');
$this->assertIsArray( $aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the new image when there are no issues');
$this->assertEquals( $aDimensions, $aActualDimensions, 'The returned dimensions should match the real dimensions of the image');
$this->assertNotSame($oDoc, $oResult, 'ResizeImageToFit should return a new object when there have been some modifications');
$this->assertIsArray($aDimensions, 'ResizeImageToFit should fill aDimension with the dimensions of the new image when there are no issues');
$this->assertEquals($aDimensions, $aActualDimensions, 'The returned dimensions should match the real dimensions of the image');
$this->assertEquals($iMawWidth, $aActualDimensions['width'], 'The new width should be exactly the max width');
$this->assertGreaterThanOrEqual($iMaxHeight, $aActualDimensions['height'], 'The new height should not be 0');
}