N°5608 - Move/rename "status" unit tests to match their counterpart location/name

This commit is contained in:
Molkobain
2022-10-15 21:10:41 +02:00
parent 6136eadd31
commit bb674fb873
3 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,116 @@
<?php
/**
* User: Guy Couronné (guy.couronne@gmail.com)
* Date: 25/01/2019
*/
namespace Combodo\iTop\Test\UnitTest\Status;
/**
* User: Guy Couronné (guy.couronne@gmail.com)
* Date: 25/01/2019
*/
use Config;
use PHPUnit\Framework\TestCase;
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 TestCase {
/**
* @var string
*/
protected $sAppRoot = '';
protected function setUp(): void
{
//AppRoot is the directory containing the directory
//Assume getcwd() is runned inside APPROOT/test
$this->sAppRoot = __DIR__.'/../../../../../../sources/application/status';
}
/**
* @expectedException \Exception
*/
public function testStatusGetAppRootWrongPath() {
include_once($this->sAppRoot . '/status.inc.php');
$sAppRootFilenamewrong = 'approot.inc.php_wrong';
StatusGetAppRoot($sAppRootFilenamewrong);
}
/**
*
*/
public function testStatusGetAppRootGood() {
include_once($this->sAppRoot . '/status.inc.php');
StatusGetAppRoot();
$this->assertNotEmpty(APPROOT);
}
/**
* @expectedException \Exception
*/
public function testStatusCheckConfigFileWrongPath() {
include_once($this->sAppRoot . '/status.inc.php');
$sConfigFilenamewrong = 'config-itop.php_wrong';
StatusCheckConfigFile($sConfigFilenamewrong);
}
/**
*
*/
public function testStatusCheckConfigFileGood() {
include_once($this->sAppRoot . '/status.inc.php');
StatusCheckConfigFile();
$this->assertTrue(true);
}
/**
* @expectedException \MySQLException
*/
public function testStatusStartupWrongDbPwd() {
include_once($this->sAppRoot . '/status.inc.php');
StatusCheckConfigFile();
require_once(APPROOT . '/core/cmdbobject.class.inc.php');
require_once(APPROOT . '/application/utils.inc.php');
require_once(APPROOT . '/core/contexttag.class.inc.php');
$oConfigWrong = new Config(ITOP_DEFAULT_CONFIG_FILE);
$oConfigWrong->Set('db_pwd', $oConfigWrong->Get('db_pwd') . '_unittest');
StatusStartup($oConfigWrong);
}
/**
*
*/
public function testStatusStartupGood() {
include_once($this->sAppRoot . '/status.inc.php');
StatusStartup();
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,50 @@
<?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 testStatusWrongUrl() {
$sPath = __DIR__ . '/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 = __DIR__ . '/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 = __DIR__ . '/status.php';
exec("php $sPath", $aOutput, $iRet);
$sAdditionnalInfo = "aOutput:\n" . var_export($aOutput, true);
//Check response
$this->assertNotEmpty($aOutput[0], 'Empty response. ' . $sAdditionnalInfo);
$this->assertJson($aOutput[0], 'Not a JSON. ' . $sAdditionnalInfo);
$aResponseDecoded = json_decode($aOutput[0], true);
//Check status
$this->assertArrayHasKey('status', $aResponseDecoded, 'JSON does not have a status\' field. ' . $sAdditionnalInfo);
$this->assertEquals('RUNNING', $aResponseDecoded['status'], 'Status is not \'RUNNING\'. ' . $sAdditionnalInfo);
//Check code
$this->assertArrayHasKey('code', $aResponseDecoded, 'JSON does not have a code\' field. ' . $sAdditionnalInfo);
$this->assertEquals(0, $aResponseDecoded['code'], 'Code is not 0. ' . $sAdditionnalInfo);
//Check message
$this->assertArrayHasKey('message', $aResponseDecoded, 'JSON does not have a message\' field. ' . $sAdditionnalInfo);
$this->assertEmpty($aResponseDecoded['message'], 'Message is not empty. ' . $sAdditionnalInfo);
}
}

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.inc.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;