Files
iTop/test/status/StatusTest.php
Pierre Goiffon 8578d18e7f Merge remote-tracking branch 'origin/support/2.7' into support/3.0
# Conflicts:
#	core/cmdbsource.class.inc.php
#	core/config.class.inc.php
#	core/displayablegraph.class.inc.php
#	core/log.class.inc.php
#	datamodels/2.x/itop-config-mgmt/dictionaries/tr.dict.itop-config-mgmt.php
#	datamodels/2.x/itop-knownerror-mgmt/dictionaries/tr.dict.itop-knownerror-mgmt.php
#	datamodels/2.x/itop-service-mgmt/dictionaries/tr.dict.itop-service-mgmt.php
#	datamodels/2.x/itop-tickets/tr.dict.itop-tickets.php
#	datamodels/2.x/itop-welcome-itil/tr.dict.itop-welcome-itil.php
#	dictionaries/tr.dictionary.itop.core.php
#	dictionaries/tr.dictionary.itop.ui.php
#	pages/UI.php
#	setup/itopdesignformat.class.inc.php
#	test/core/LogAPITest.php
#	test/integration/iTopModulesPhpVersionChecklistTest.php
#	test/postbuild_integration/SetupCssIntegrityChecklistTest.php
#	test/postbuild_integration/iTopModuleXmlInstallationChecklistTest.php
#	test/status/StatusTest.php
2022-01-10 16:15:00 +01:00

69 lines
2.5 KiB
PHP

<?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()
{
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);
//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);
}
}