mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 18:18:46 +02:00
Merge branch 'develop' into feature/uninstallation
This commit is contained in:
@@ -128,7 +128,7 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\IssueLog::Error($this->getName());
|
||||
\IssueLog::Info("Running phpunit test: ".$this->getName());
|
||||
|
||||
$this->PrepareEnvironment();
|
||||
|
||||
@@ -1529,9 +1529,6 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
{
|
||||
$sConfigPath = MetaModel::GetConfig()->GetLoadedFile();
|
||||
clearstatcache();
|
||||
echo sprintf("rights via ls on %s:\n %s \n", $sConfigPath, exec("ls -al $sConfigPath"));
|
||||
$sFilePermOutput = substr(sprintf('%o', fileperms('/etc/passwd')), -4);
|
||||
echo sprintf("rights via fileperms on %s:\n %s \n", $sConfigPath, $sFilePermOutput);
|
||||
|
||||
$this->sConfigTmpBackupFile = tempnam(sys_get_temp_dir(), "config_");
|
||||
MetaModel::GetConfig()->WriteToFile($this->sConfigTmpBackupFile);
|
||||
|
||||
@@ -9,11 +9,15 @@ namespace Combodo\iTop\Test\UnitTest;
|
||||
|
||||
use CMDBSource;
|
||||
use DeprecatedCallsLog;
|
||||
use DOMDocument;
|
||||
use MySQLTransactionNotClosedException;
|
||||
use ParseError;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use ReflectionMethod;
|
||||
use SetupUtils;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\ErrorHandler\Error\FatalError;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
|
||||
/**
|
||||
@@ -149,6 +153,17 @@ abstract class ItopTestCase extends KernelTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Check globals
|
||||
global $fItopStarted;
|
||||
if (is_null($fItopStarted)) {
|
||||
$fItopStarted = microtime(true);
|
||||
}
|
||||
|
||||
global $iItopInitialMemory;
|
||||
if (is_null($iItopInitialMemory)) {
|
||||
$iItopInitialMemory = memory_get_usage(true);
|
||||
}
|
||||
|
||||
// Hack - Required the first time the Portal kernel is booted on a newly installed iTop
|
||||
$_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_PATH'] = __DIR__.'/../../../../../env-production/itop-portal-base/portal/public/';
|
||||
|
||||
@@ -582,6 +597,23 @@ abstract class ItopTestCase extends KernelTestCase
|
||||
self::assertLessThan(2, $iTimeInterval, $sMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.3.0
|
||||
*/
|
||||
protected static function AssertPHPCodeIsValid(string $sPHPCode, $sMessage = ''): void
|
||||
{
|
||||
try {
|
||||
eval($sPHPCode);
|
||||
} catch (ParseError $e) {
|
||||
$aLines = explode("\n", $sPHPCode);
|
||||
foreach ($aLines as $iLine => $sLine) {
|
||||
echo sprintf("%02d: %s\n", $iLine + 1, $sLine);
|
||||
}
|
||||
echo 'Parse Error: '.$e->getMessage().' at line: '.$e->getLine()."\n";
|
||||
self::fail($sMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control which Kernel will be loaded when invoking the bootKernel method
|
||||
*
|
||||
@@ -661,7 +693,11 @@ abstract class ItopTestCase extends KernelTestCase
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt_array($ch, $aCurlOptions);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aPostFields));
|
||||
if ($this->IsArrayOfArray($aPostFields)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aPostFields));
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $aPostFields);
|
||||
}
|
||||
|
||||
$sOutput = curl_exec($ch);
|
||||
|
||||
@@ -676,10 +712,51 @@ abstract class ItopTestCase extends KernelTestCase
|
||||
return $sOutput;
|
||||
}
|
||||
|
||||
private function IsArrayOfArray(array $aStruct): bool
|
||||
{
|
||||
foreach ($aStruct as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function CallItopUri(string $sUri, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string
|
||||
{
|
||||
$sUrl = \MetaModel::GetConfig()->Get('app_root_url')."/$sUri";
|
||||
|
||||
return $this->CallUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sXML
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
protected function CanonicalizeXML($sXML)
|
||||
{
|
||||
// Canonicalize the expected XML (to cope with indentation)
|
||||
$oExpectedDocument = new DOMDocument();
|
||||
$oExpectedDocument->preserveWhiteSpace = false;
|
||||
$oExpectedDocument->formatOutput = true;
|
||||
$oExpectedDocument->loadXML($sXML);
|
||||
|
||||
$sSavedXML = $oExpectedDocument->SaveXML();
|
||||
|
||||
return str_replace(' encoding="UTF-8"', '', $sSavedXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sExpected
|
||||
* @param $sActual
|
||||
* @param string $sMessage
|
||||
*/
|
||||
protected function AssertEqualiTopXML($sExpected, $sActual, string $sMessage = '')
|
||||
{
|
||||
// Note: assertEquals reports the differences in a diff which is easier to interpret (in PHPStorm)
|
||||
// as compared to the report given by assertEqualXMLStructure
|
||||
static::assertEquals($this->CanonicalizeXML($sExpected), $this->CanonicalizeXML($sActual), $sMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user