mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°4369 - Return product and version in status rest ws
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
<?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() {
|
||||
//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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,57 +14,68 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class StatusTest extends ItopTestCase {
|
||||
class StatusTest extends ItopTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once APPROOT.'core/config.class.inc.php'; // for constants
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testStatusWrongUrl() {
|
||||
$sPath = APPROOT . '/status_wrong.php';
|
||||
*
|
||||
*/
|
||||
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));
|
||||
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';
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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));
|
||||
}
|
||||
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';
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testStatusGoodWithJson()
|
||||
{
|
||||
$sPath = APPROOT.'/webservices/status.php';
|
||||
|
||||
exec("php $sPath", $aOutput, $iRet);
|
||||
$sAdditionnalInfo = "aOutput:\n" . var_export($aOutput, true) . '.';
|
||||
exec("php $sPath", $aOutput, $iRet);
|
||||
$sAdditionalInfo = "aOutput:\n".var_export($aOutput, true).'.';
|
||||
|
||||
//Check response
|
||||
$this->assertNotEmpty($aOutput[0], 'Empty response. ' . $sAdditionnalInfo);
|
||||
$this->assertJson($aOutput[0], 'Not a JSON. ' . $sAdditionnalInfo);
|
||||
//Check response
|
||||
$this->assertNotEmpty($aOutput[0], 'Empty response. '.$sAdditionalInfo);
|
||||
$this->assertJson($aOutput[0], 'Not a JSON. '.$sAdditionalInfo);
|
||||
|
||||
$aResponseDecoded = json_decode($aOutput[0], true);
|
||||
$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);
|
||||
}
|
||||
//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);
|
||||
//Check product
|
||||
$this->assertArrayHasKey('product', $aResponseDecoded, 'JSON does not have a product\' field. '.$sAdditionalInfo);
|
||||
$this->assertEquals(ITOP_APPLICATION, $aResponseDecoded['product'], 'Bad product (should be: '.ITOP_APPLICATION.') '.$sAdditionalInfo);
|
||||
//Check version
|
||||
$this->assertArrayHasKey('version', $aResponseDecoded, 'JSON does not have a version\' field. '.$sAdditionalInfo);
|
||||
$this->assertEquals(ITOP_VERSION, $aResponseDecoded['version'], 'Bad version (should be: '.ITOP_VERSION.') '.$sAdditionalInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user