N°4756 - Fix unit tests

This commit is contained in:
Eric Espie
2022-09-19 16:09:02 +02:00
parent aa31da34e5
commit 88f0013330
3 changed files with 16 additions and 15 deletions

View File

@@ -453,9 +453,9 @@ class ItopDataTestCase extends ItopTestCase
$oUserProfile = new URP_UserProfile();
$oUserProfile->Set('profileid', $iProfileId);
$oUserProfile->Set('reason', 'UNIT Tests');
/** @var DBObjectSet $oSet */
/** @var \ormLinkSet $oSet */
$oSet = $oUser->Get('profile_list');
$oSet->AddObject($oUserProfile);
$oSet->AddItem($oUserProfile);
$oUser = $this->updateObject('UserLocal', $oUser->GetKey(), array(
'profile_list' => $oSet,
));

View File

@@ -254,7 +254,7 @@ class DBObjectTest extends ItopDataTestCase
static::assertDBQueryCount(0, function() use (&$oObject){
$oObject = \MetaModel::NewObject('Person', ['name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2]);
});
static::assertDBQueryCount(28, function() use (&$oObject) {
static::assertDBQueryCount(26, function() use (&$oObject) {
$oObject->DBInsertNoReload();
});
$sClass = get_class($oObject);
@@ -304,7 +304,7 @@ class DBObjectTest extends ItopDataTestCase
static::assertDBQueryCount(0, function() use (&$oPerson){
$oPerson = MetaModel::NewObject('Person', ['name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2]);
});
static::assertDBQueryCount(28, function() use (&$oPerson) {
static::assertDBQueryCount(26, function() use (&$oPerson) {
$oPerson->DBInsertNoReload();
});
$sPersonClass = get_class($oPerson);
@@ -326,7 +326,7 @@ class DBObjectTest extends ItopDataTestCase
// $fItopStarted = microtime(true);
// ExecutionKPI::EnableDuration(2);
// $oKPI = new ExecutionKPI();
static::assertDBQueryCount(92, function() use (&$oTeam) {
static::assertDBQueryCount(89, function() use (&$oTeam) {
$oTeam->DBInsertNoReload();
});
// $oKPI->ComputeAndReport('Team DBInsertNoReload');

View File

@@ -22,11 +22,11 @@ class RestTest extends ItopDataTestCase
const MODE = [ 'JSONDATA_AS_STRING' => 0, 'JSONDATA_AS_FILE' => 1 , 'NO_JSONDATA' => 2 ];
private $sTmpFile = "";
/** @var int $iJsonDataMode */
private $sJsonDataMode;
private $sUrl;
private $sLogin;
private $sPassword = "Iuytrez9876543ç_è-(";
/** @var int $iJsonDataMode */
private int $iJsonDataMode;
/**
* @throws Exception
@@ -67,26 +67,27 @@ class RestTest extends ItopDataTestCase
//create ticket
$description = date('dmY H:i:s');
$sOuputJson = $this->CreateTicketViaApi($description);
$aJson = json_decode($sOuputJson, true);
$sOutputJson = $this->CreateTicketViaApi($description);
$this->debug("Output: '$sOutputJson'");
$aJson = json_decode($sOutputJson, true);
if ($this->iJsonDataMode === self::MODE['NO_JSONDATA']){
$this->assertContains("3", "".$aJson['code'], $sOuputJson);
$this->assertContains("Error: Missing parameter 'json_data'", "".$aJson['message'], $sOuputJson);
$this->assertContains("3", "".$aJson['code'], $sOutputJson);
$this->assertContains("Error: Missing parameter 'json_data'", "".$aJson['message'], $sOutputJson);
return;
}
$this->assertContains("0", "".$aJson['code'], $sOuputJson);
$this->assertContains("0", "".$aJson['code'], $sOutputJson);
$sUserRequestKey = $this->array_key_first($aJson['objects']);
$this->assertContains('UserRequest::', $sUserRequestKey);
$iId = $aJson['objects'][$sUserRequestKey]['key'];
$sExpectedJsonOuput=<<<JSON
{"objects":{"UserRequest::$iId":{"code":0,"message":"created","class":"UserRequest","key":"$iId","fields":{"id":"$iId"}}},"code":0,"message":null}
{"objects":{"UserRequest::$iId":{"code":0,"message":"created","class":"UserRequest","key":$iId,"fields":{"id":$iId}}},"code":0,"message":null}
JSON;
$this->assertEquals($sExpectedJsonOuput, $sOuputJson);
$this->assertEquals($sExpectedJsonOuput, $sOutputJson);
$sExpectedJsonOuput=<<<JSON
{"objects":{"UserRequest::$iId":{"code":0,"message":"","class":"UserRequest","key":"$iId","fields":{"id":"$iId","description":"<p>$description<\/p>"}}},"code":0,"message":"Found: 1"}
{"objects":{"UserRequest::$iId":{"code":0,"message":"","class":"UserRequest","key":$iId,"fields":{"id":$iId,"description":"<p>$description<\/p>"}}},"code":0,"message":"Found: 1"}
JSON;
$this->assertEquals($sExpectedJsonOuput, $this->GetTicketViaRest($iId));