N°5608 - Rename unit tests dirs "sources/application" to match counter-part dirs name

This commit is contained in:
Molkobain
2023-01-18 16:06:21 +01:00
parent 34688c2bf6
commit 9be167cf5e
15 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,89 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Status;
use Combodo\iTop\Application\Status\Status;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
use Exception;
use MySQLException;
use function Combodo\iTop\Application\Status\StatusCheckConfigFile;
use function Combodo\iTop\Application\Status\StatusGetAppRoot;
use function Combodo\iTop\Application\Status\StatusStartup;
if (!defined('DEBUG_UNIT_TEST')) {
define('DEBUG_UNIT_TEST', true);
}
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
class StatusIncTest extends ItopTestCase {
/**
* @var string
*/
protected $sAppRoot = '';
protected function setUp(): void
{
parent::setUp();
$this->RequireOnceItopFile('sources/Application/Status/Status.php');
}
public function testStatusGetAppRootWrongPath() {
$this->expectException(Exception::class);
$sAppRootFilenamewrong = 'approot.inc.php_wrong';
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusGetAppRoot", $oStatus, [$sAppRootFilenamewrong]);
}
/**
*
*/
public function testStatusGetAppRootGood() {
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusGetAppRoot", $oStatus, []);
$this->assertNotEmpty(APPROOT);
}
public function testStatusCheckConfigFileWrongPath() {
$this->expectException(Exception::class);
$sConfigFilenamewrong = 'config-itop.php_wrong';
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusCheckConfigFile", $oStatus, [$sConfigFilenamewrong]);
}
public function testStatusCheckConfigFileGood() {
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusCheckConfigFile", $oStatus, []);
$this->assertTrue(true);
}
public function testStatusStartupWrongDbPwd()
{
$this->RequireOnceItopFile('core/cmdbobject.class.inc.php');
$this->RequireOnceItopFile('application/utils.inc.php');
$this->RequireOnceItopFile('core/contexttag.class.inc.php');
$oConfigWrong = new Config(ITOP_DEFAULT_CONFIG_FILE);
$oConfigWrong->Set('db_pwd', $oConfigWrong->Get('db_pwd').'_unittest');
$this->expectException(MySQLException::class);
new Status($oConfigWrong);
}
public function testStatusStartupGood() {
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusStartup", $oStatus, []);
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* User: Guy Couronné (guy.couronne@gmail.com)
* Date: 25/01/2019
*/
namespace Combodo\iTop\Test\UnitTest\Status;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
class StatusTest extends ItopTestCase
{
public function setUp(): void
{
parent::setUp();
require_once APPROOT.'core/config.class.inc.php'; // for constants
}
public function testStatusWrongUrl() {
$sPath = APPROOT.'/status_wrong.php';
exec("php $sPath", $aOutput, $iRet);
$this->assertNotEquals(0, $iRet, "Problem executing status page: $sPath, $iRet, aOutput:\n" . var_export($aOutput, true));
}
public function testStatusGood() {
$sPath = APPROOT.'/webservices/status.php';
exec("php $sPath", $aOutput, $iRet);
$this->assertEquals(0, $iRet, "Problem executing status page: $sPath, $iRet, aOutput:\n".var_export($aOutput, true));
}
/**
*
*/
public function testStatusGoodWithJson()
{
$sPath = APPROOT.'/webservices/status.php';
exec("php $sPath", $aOutput, $iRet);
$sAdditionalInfo = "aOutput:\n".var_export($aOutput, true).'.';
//Check response
$this->assertNotEmpty($aOutput[0], 'Empty response. '.$sAdditionalInfo);
$this->assertJson($aOutput[0], 'Not a JSON. '.$sAdditionalInfo);
$aResponseDecoded = json_decode($aOutput[0], true);
//Check status
$this->assertArrayHasKey('status', $aResponseDecoded, 'JSON does not have a \'status\' field. '.$sAdditionalInfo);
$this->assertEquals('RUNNING', $aResponseDecoded['status'], 'Status is not \'RUNNING\'. '.$sAdditionalInfo);
//Check code
$this->assertArrayHasKey('code', $aResponseDecoded, 'JSON does not have a \'code\' field. '.$sAdditionalInfo);
$this->assertEquals(0, $aResponseDecoded['code'], 'Code is not 0. '.$sAdditionalInfo);
//Check message
$this->assertArrayHasKey('message', $aResponseDecoded, 'JSON does not have a \'message\' field. '.$sAdditionalInfo);
$this->assertEmpty($aResponseDecoded['message'], 'Message is not empty. '.$sAdditionalInfo);
}
}

View File

@@ -0,0 +1,27 @@
<?php
// Include status functions
// Important: We can't use the APPROOT constant here as the current script will be executed via the PHP exec() function which won't have it loaded yet.
require_once __DIR__.'/../../../../../../sources/application/status/Status.php';
// Do check Status
try
{
\Combodo\iTop\Application\Status\StatusStartup();
$aResult = array('status' => STATUS_RUNNING, 'code' => \RestResult::OK, 'message' => '');
}
catch (\Exception $e)
{
$iCode = (defined('\RestResult::INTERNAL_ERROR')) ? \RestResult::INTERNAL_ERROR : 100;
$aResult = array('status' => STATUS_ERROR, 'code' => $iCode, 'message' => $e->getMessage());
http_response_code(500);
}
//Set headers, based on webservices/rest.php
$sContentType = 'application/json';
header('Content-type: ' . $sContentType);
header('Access-Control-Allow-Origin: *');
//Output result
$sResponse = json_encode($aResult);
echo $sResponse;