Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
accognet committed Jan 31, 2025
1 parent 311a0d9 commit 701ba0a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,10 @@ protected function GivenObject(string $sClass, array $aParams): DBObject
* @param string $sClass
* @param array $aValues
*
* @return string created object key
* @return int
* @throws Exception
*/
protected function GivenObjectInDB($sClass, $aValues)
protected function GivenObjectInDB($sClass, $aValues):int
{
// Check and complete the values
foreach ($aValues as $sAttCode => $oValue) {
Expand Down
60 changes: 60 additions & 0 deletions tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,64 @@ public function OnFormCancelInvalidTempIdProvider()
],
];
}

public function testSetDefaultOrgIdWhenLoggedInWithContact()
{
$iContactOrgId = $this->GivenObjectInDB('Organization', ['name' => 'TestOrg']);
$this->GivenUserLoggedInWithContact($iContactOrgId);

$oInlineImage = \MetaModel::NewObject('InlineImage',['item_class' => 'UserRequest']);
$oInlineImage->SetDefaultOrgId();
$this->assertEquals($iContactOrgId, $oInlineImage->Get('item_org_id'),'The org_id should be the one of the contact');

$oInlineImage = \MetaModel::NewObject('InlineImage',['item_class' => 'TriggerOnObjectCreation']);
$oInlineImage->SetDefaultOrgId();
$this->assertEquals(0, $oInlineImage->Get('item_org_id'),'The org_id should be left undefined');
}


public function testSetDefaultOrgIdWhenLoggedInWithoutContact()
{
$this->GivenUserLoggedInWithoutContact();

$oInlineImage = \MetaModel::NewObject('InlineImage',['item_class' => 'UserRequest']);
$oInlineImage->SetDefaultOrgId();
$this->assertEquals(0, $oInlineImage->Get('item_org_id'),'The org_id should be left undefined');

$oInlineImage = \MetaModel::NewObject('InlineImage',['item_class' => 'TriggerOnObjectCreation']);
$oInlineImage->SetDefaultOrgId();
$this->assertEquals(0, $oInlineImage->Get('item_org_id'),'The org_id should be left undefined');
}

private function GivenUserLoggedInWithContact(int $iContactOrgId)
{
$iContactId = $this->GivenObjectInDB('Person', [
'first_name' => 'TestContact',
'name' => 'TestContact',
'org_id' => $iContactOrgId]);
$sLogin = 'demo_test_'.uniqid(__CLASS__, true);
$iUser = $this->GivenObjectInDB('UserLocal', [
'login' => $sLogin,
'password' => 'tagada-Secret,007',
'language' => 'EN US',
'contactid' => $iContactId,
'profile_list' => [
'profileid:'.self::$aURP_Profiles['Configuration Manager']
]
]);
\UserRights::Login($sLogin);
}
private function GivenUserLoggedInWithoutContact()
{
$sLogin = 'demo_test_'.uniqid(__CLASS__, true);
$iUser = $this->GivenObjectInDB('UserLocal', [
'login' => $sLogin,
'password' => 'tagada-Secret,007',
'language' => 'EN US',
'profile_list' => [
'profileid:'.self::$aURP_Profiles['Configuration Manager']
]
]);
\UserRights::Login($sLogin);
}
}

0 comments on commit 701ba0a

Please sign in to comment.