Skip to content

Commit cc8d834

Browse files
committed
N°8632 - Check existence of parameter file within iTop
1 parent d2f67dc commit cc8d834

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

application/utils.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class utils
181181

182182
protected static function LoadParamFile($sParamFile)
183183
{
184+
$sParamFile = self::AbsolutePath($sParamFile);
184185
if (!file_exists($sParamFile)) {
185186
throw new Exception("Could not find the parameter file: '".utils::HtmlEntities($sParamFile)."'");
186187
}

tests/php-unit-tests/unitary-tests/application/utilsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,4 +996,31 @@ public function VSprintfProvider()
996996
],
997997
];
998998
}
999+
1000+
public function testLoadParamFile()
1001+
{
1002+
$sTmpFileOutsideItop = tempnam(sys_get_temp_dir(), 'utils');
1003+
$sParamName = 'param_test_p1';
1004+
$sParamValue = 'My own value';
1005+
$sParams = <<<INI
1006+
# comment
1007+
$sParamName = $sParamValue
1008+
INI;
1009+
1010+
file_put_contents($sTmpFileOutsideItop, $sParams);
1011+
1012+
self::assertNull(utils::ReadParam($sParamName, null));
1013+
self::expectException(\Exception::class);
1014+
self::expectExceptionMessage('Could not find the parameter file: \'\'');
1015+
self::InvokeNonPublicStaticMethod(utils::class, 'LoadParamFile', [$sTmpFileOutsideItop]);
1016+
1017+
self::assertNotEquals($sParamValue, utils::ReadParam($sParamName, null), "utils::LoadParamFile() has loaded the file: $sTmpFileOutsideItop");
1018+
1019+
unlink($sTmpFileOutsideItop);
1020+
1021+
$sTmpFileInsideItop = tempnam(utils::GetCachePath(), 'utils-test');
1022+
file_put_contents($sTmpFileInsideItop, $sParams);
1023+
self::InvokeNonPublicStaticMethod(utils::class, 'LoadParamFile', [$sTmpFileInsideItop]);
1024+
self::assertEquals($sParamValue, utils::ReadParam($sParamName, null), "utils::LoadParamFile() has not loaded the file: $sTmpFileOutsideItop");
1025+
}
9991026
}

0 commit comments

Comments
 (0)