mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 04:28:44 +02:00
N°8981: prepare hub connector test cover
sdk test enhancement : add call itop api fix ci ci: fix broken tests ci: cover hub setup on compile and launch steps code style ci: fix ModuleDiscoveryTest redundant class + add logs to investigate ci setup issues ci: fix log during setup tests
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\HubConnector;
|
||||
|
||||
use Combodo\iTop\HubConnector\Controller\HubController;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use DOMFormatException;
|
||||
use JsonPage;
|
||||
use MFCompiler;
|
||||
use SetupLog;
|
||||
use SetupUtils;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runClassInSeparateProcess
|
||||
*/
|
||||
class HubControllerTest extends ItopDataTestCase
|
||||
{
|
||||
public const USE_TRANSACTION = false;
|
||||
public const AUTHENTICATION_TOKEN = '14b5da9d092f84044187421419a0347e7317bc8cd2b486fdda631be06b959269';
|
||||
public const AUTHENTICATION_PASSWORD = "tagada-Secret,007";
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->SkipIfModuleNotPresent('itop-hub-connector');
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('env-production/itop-hub-connector/src/Controller/HubController.php');
|
||||
}
|
||||
|
||||
public function testLaunchCompile(): void
|
||||
{
|
||||
$this->PrepareCompileAuthent();
|
||||
|
||||
$this->CopyProductionModulesIntoHubExtensionDir();
|
||||
|
||||
touch(MFCompiler::USE_SYMBOLIC_LINKS_FILE_PATH);
|
||||
HubController::GetInstance()->SetOutputHeaders(false);
|
||||
|
||||
try {
|
||||
HubController::GetInstance()->LaunchCompile();
|
||||
} catch (DOMFormatException $e) {
|
||||
SetupLog::Error(__METHOD__, null, [ 'production.delta.xml' => @file_get_contents(APPROOT.'data/production.delta.xml')]);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->CheckReport('{"code":0,"message":"Ok","fields":[]}');
|
||||
}
|
||||
|
||||
public function testLaunchDeploy(): void
|
||||
{
|
||||
$this->PrepareCompileAuthent();
|
||||
HubController::GetInstance()->LaunchDeploy();
|
||||
$this->CheckReport('{"code":0,"message":"Compilation successful.","fields":[]}');
|
||||
}
|
||||
|
||||
private function CheckReport($sExpected)
|
||||
{
|
||||
$oJsonPage = HubController::GetInstance()->GetLastJsonPage();
|
||||
$this->assertEquals($sExpected, $this->InvokeNonPublicMethod(JsonPage::class, 'ComputeContent', $oJsonPage, []));
|
||||
|
||||
//keep line below to avoid: Test code or tested code did not (only) close its own output buffers
|
||||
$this->InvokeNonPublicMethod(JsonPage::class, 'RenderContent', $oJsonPage, []);
|
||||
}
|
||||
|
||||
private function PrepareCompileAuthent()
|
||||
{
|
||||
$sUUID = 'hub_'.uniqid();
|
||||
$_REQUEST['authent'] = $sUUID;
|
||||
$sPath = utils::GetDataPath().'hub/compile_authent';
|
||||
file_put_contents($sPath, $sUUID);
|
||||
$this->aFileToClean[] = $sPath;
|
||||
}
|
||||
|
||||
private function CopyProductionModulesIntoHubExtensionDir()
|
||||
{
|
||||
$sProdModules = APPROOT.'/data/production-modules';
|
||||
$sExtensionDir = APPROOT.'/data/downloaded-extensions/';
|
||||
$this->aFileToClean[] = $sExtensionDir;
|
||||
|
||||
SetupUtils::rrmdir($sExtensionDir);
|
||||
SetupUtils::copydir($sExtensionDir, $sProdModules);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user