mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
ci: rename CallItopUrl by CallUrl + cleanup
This commit is contained in:
@@ -8,14 +8,12 @@
|
|||||||
namespace Combodo\iTop\Test\UnitTest;
|
namespace Combodo\iTop\Test\UnitTest;
|
||||||
|
|
||||||
use CMDBSource;
|
use CMDBSource;
|
||||||
use DateTime;
|
|
||||||
use DeprecatedCallsLog;
|
use DeprecatedCallsLog;
|
||||||
use MySQLTransactionNotClosedException;
|
use MySQLTransactionNotClosedException;
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
use SetupUtils;
|
use SetupUtils;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
|
||||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -649,7 +647,7 @@ abstract class ItopTestCase extends KernelTestCase
|
|||||||
* @param $bXDebugEnabled
|
* @param $bXDebugEnabled
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function CallItopUrl($sUrl, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string
|
protected function CallUrl($sUrl, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string
|
||||||
{
|
{
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
if ($bXDebugEnabled) {
|
if ($bXDebugEnabled) {
|
||||||
@@ -687,6 +685,7 @@ abstract class ItopTestCase extends KernelTestCase
|
|||||||
protected function CallItopUri(string $sUri, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string
|
protected function CallItopUri(string $sUri, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string
|
||||||
{
|
{
|
||||||
$sUrl = \MetaModel::GetConfig()->Get('app_root_url')."/$sUri";
|
$sUrl = \MetaModel::GetConfig()->Get('app_root_url')."/$sUri";
|
||||||
return $this->CallItopUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled);
|
|
||||||
|
return $this->CallUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Test\UnitTest\Application;
|
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
|
||||||
use MetaModel;
|
|
||||||
|
|
||||||
class LoginTest extends ItopDataTestCase
|
|
||||||
{
|
|
||||||
protected $sConfigPath;
|
|
||||||
protected $sLoginMode;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
clearstatcache();
|
|
||||||
|
|
||||||
// The test consists in requesting UI.php from outside iTop with a specific configuration
|
|
||||||
// Hence the configuration file must be tweaked on disk (and restored)
|
|
||||||
$this->sConfigPath = MetaModel::GetConfig()->GetLoadedFile();
|
|
||||||
$this->sConfigTmpBackupFile = tempnam(sys_get_temp_dir(), "config_");
|
|
||||||
file_put_contents($this->sConfigTmpBackupFile, file_get_contents($this->sConfigPath));
|
|
||||||
|
|
||||||
$oConfig = new \Config($this->sConfigPath);
|
|
||||||
$this->sLoginMode = "unimplemented_loginmode";
|
|
||||||
$oConfig->AddAllowedLoginTypes($this->sLoginMode);
|
|
||||||
|
|
||||||
@chmod($this->sConfigPath, 0770);
|
|
||||||
$oConfig->WriteToFile();
|
|
||||||
@chmod($this->sConfigPath, 0444);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown(): void
|
|
||||||
{
|
|
||||||
if (! is_null($this->sConfigTmpBackupFile) && is_file($this->sConfigTmpBackupFile)) {
|
|
||||||
//put config back
|
|
||||||
@chmod($this->sConfigPath, 0770);
|
|
||||||
file_put_contents($this->sConfigPath, file_get_contents($this->sConfigTmpBackupFile));
|
|
||||||
@chmod($this->sConfigPath, 0444);
|
|
||||||
@unlink($this->sConfigTmpBackupFile);
|
|
||||||
}
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function CallItopUrlByCurl($sUri, ?array $aPostFields = [])
|
|
||||||
{
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
$sUrl = MetaModel::GetConfig()->Get('app_root_url')."/$sUri";
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $sUrl);
|
|
||||||
if (0 !== sizeof($aPostFields)) {
|
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);// set post data to true
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $aPostFields);
|
|
||||||
}
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
$sOutput = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
return $sOutput;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -147,7 +147,8 @@ class QueryTest extends ItopDataTestCase
|
|||||||
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
||||||
CURLOPT_USERPWD => self::USER.':'.self::PASSWORD,
|
CURLOPT_USERPWD => self::USER.':'.self::PASSWORD,
|
||||||
];
|
];
|
||||||
return $this->CallItopUrl($url, [], $aCurlOptions);
|
|
||||||
|
return $this->CallUrl($url, [], $aCurlOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
|
|||||||
Reference in New Issue
Block a user